Skip to content

Commit 98a73f9

Browse files
authored
Merge pull request #726 from Xian55/fix/725
Fix/725 - First time installing the addon fails due multiple .toc file definition exists
2 parents f3d24f5 + 6b71572 commit 98a73f9

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

BlazorServer/run.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
start "" "http://localhost:5000"
22
cd /D "%~dp0"
3-
dotnet run --configuration Release --no-build -e:ASPNETCORE_ENVIRONMENT=Production
3+
dotnet run --configuration Release --no-build
44

55
pause

BlazorServer/rundev.bat

Lines changed: 0 additions & 5 deletions
This file was deleted.

Core/Configurator/AddonConfigurator.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,32 @@ private void MakeUnique()
162162
EditModulesLua();
163163
}
164164

165-
private static void BulkRename(string fPath, string match, string fNewName)
165+
private static void BulkRename(string folderPath, string match, string replacement)
166166
{
167-
foreach (FileInfo f in new DirectoryInfo(fPath).GetFiles())
168-
{
169-
string fromName = Path.GetFileNameWithoutExtension(f.Name);
167+
if (string.IsNullOrEmpty(match))
168+
throw new ArgumentException("match must not be empty", nameof(match));
169+
170+
DirectoryInfo dir = new(folderPath);
170171

171-
if (!fromName.Contains(match))
172+
foreach (var file in dir.EnumerateFiles())
173+
{
174+
var baseName = Path.GetFileNameWithoutExtension(file.Name);
175+
if (baseName is null || !baseName.Contains(match, StringComparison.Ordinal))
172176
continue;
173177

174-
string ext = Path.GetExtension(f.Name);
178+
var ext = file.Extension;
179+
180+
var newBaseName = baseName.Replace(match, replacement, StringComparison.Ordinal);
181+
182+
var targetPath = Path.Combine(file.DirectoryName!, newBaseName + ext);
183+
184+
if (string.Equals(file.FullName, targetPath, StringComparison.OrdinalIgnoreCase))
185+
continue;
175186

176-
fromName = Path.Join(fPath, f.Name);
177-
string toName = Path.Join(fPath, fNewName) + ext;
187+
if (File.Exists(targetPath))
188+
throw new IOException($"Target file already exists: {targetPath}");
178189

179-
File.Move(fromName, toName);
190+
file.MoveTo(targetPath);
180191
}
181192
}
182193

0 commit comments

Comments
 (0)