Skip to content

Commit 6c05e2c

Browse files
committed
Replace the Custom File Remover with a DirectoryInfo Enumerate
Massively speeds up custom file uninstallation. A large Randomisation with a lot of custom music and voice packs has gone from taking 10 minutes to uninstall down to just 2, probably the best this code can manage really. Should also fix a bug where a custom file being present but not in the INI breaks everything, haven't tested that though >_>
1 parent c38b613 commit 6c05e2c

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

Sonic-06-Mod-Manager/Sonic-06-Mod-Manager.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@
371371
</ItemGroup>
372372
<ItemGroup>
373373
<PackageReference Include="Costura.Fody">
374-
<Version>5.2.0</Version>
374+
<Version>5.7.0</Version>
375375
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
376376
<PrivateAssets>all</PrivateAssets>
377377
</PackageReference>

Sonic-06-Mod-Manager/src/UnifyPatcher.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static void InstallMods(string mod, string name) {
105105
//If the file is not an archive or it shouldn't be merged, just copy it
106106
} else {
107107
// Skip if file doesn't exist in the base game and it's not custom.
108-
if (!File.Exists(vanillaFilePath) && !custom.Contains(Path.GetFileName(file))) return;
108+
if (!File.Exists(vanillaFilePath) && !custom.Contains(Path.GetFileName(file))) continue;
109109

110110
Console.WriteLine($"[{DateTime.Now:hh:mm:ss tt}] [Copy] {file}");
111111
File.Copy(file, vanillaFilePath, true);
@@ -168,19 +168,20 @@ public static void UninstallMods() {
168168
/// </summary>
169169
public static void UninstallCustomFilesystem(ListView.ListViewItemCollection listViewItems) {
170170
if (Paths.CheckFileLegitimacy(Properties.Settings.Default.Path_GameExecutable)) { // If the game directory is empty/doesn't exist, ignore request
171+
DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(Properties.Settings.Default.Path_GameExecutable));
171172
foreach (ListViewItem mod in listViewItems) {
172173
string[] custom = INI.DeserialiseKey("Custom", mod.SubItems[6].Text).Split(','); // Deserialise 'Custom' key
173174

174175
if (custom[0] != string.Empty) { // Speeds things up a bit - ensures it's not checking a default null parameter
175176
foreach (string file in custom) {
176-
// Search for all files with filters from custom
177-
List<string> files = Directory.GetFiles(Path.GetDirectoryName(Properties.Settings.Default.Path_GameExecutable), file, SearchOption.AllDirectories).ToList();
178-
179-
foreach (string customfile in files)
177+
foreach (var fi in di.EnumerateFiles($"*{file}", SearchOption.AllDirectories)) {
180178
try {
181-
Console.WriteLine($"[{DateTime.Now:hh:mm:ss tt}] [Remove] {customfile}");
182-
File.Delete(customfile); // If custom archive is found, erase...
183-
} catch { }
179+
Console.WriteLine($"[{DateTime.Now:hh:mm:ss tt}] [Remove] {fi.Name}");
180+
File.Delete(fi.FullName); // If custom file is found, erase...
181+
}
182+
catch { }
183+
184+
}
184185
}
185186
}
186187
}

Sonic-06-Mod-Manager/src/UnifyProgram.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Unify
4040
{
4141
static class Program
4242
{
43-
public static readonly string GlobalVersionNumber = $"Version 3.41";
43+
public static readonly string GlobalVersionNumber = $"Version 3.42";
4444

4545
#if !DEBUG
4646
public static readonly string VersionNumber = GlobalVersionNumber;

0 commit comments

Comments
 (0)