Skip to content

Commit f0b2c68

Browse files
committed
Massive Optimisation of Custom Content
AKA: Past us massively overengineered the uninstall custom content handling and it was slow as all hell (affecting start up times too) Testing with a Sonic '06 Randomiser Suite mod containing 6538 custom files, Version 3.42 would take two minutes to even start up if "Automatically Uninstall Mods" was active. A build with this change takes around 14 seconds to start up instead. As the same check is performed when installing mods with the option enabled, this also optimises the install time when a lot of custom files are present, as it no longer spends forever checking for them to remove first.
1 parent db3109c commit f0b2c68

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,19 +168,18 @@ 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));
171+
string[] gameFiles = Directory.GetFiles(Path.GetDirectoryName(Properties.Settings.Default.Path_GameExecutable), "*.*", SearchOption.AllDirectories); // Get the game files.
172172
foreach (ListViewItem mod in listViewItems) {
173173
string[] custom = INI.DeserialiseKey("Custom", mod.SubItems[6].Text).Split(','); // Deserialise 'Custom' key
174174

175175
if (custom[0] != string.Empty) { // Speeds things up a bit - ensures it's not checking a default null parameter
176176
foreach (string file in custom) {
177-
foreach (var fi in di.EnumerateFiles($"*{file}", SearchOption.AllDirectories)) {
178-
try {
179-
Console.WriteLine($"[{DateTime.Now:hh:mm:ss tt}] [Remove] {fi.FullName}");
180-
File.Delete(fi.FullName); // If custom file is found, erase...
177+
foreach (string gameFile in gameFiles) {
178+
// Check if this file has the name of one of our custom files, if so, delete it.
179+
if (Path.GetFileName(gameFile) == file) {
180+
Console.WriteLine($"[{DateTime.Now:hh:mm:ss tt}] [Remove] {gameFile}");
181+
File.Delete(gameFile);
181182
}
182-
catch { }
183-
184183
}
185184
}
186185
}

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.42";
43+
public static readonly string GlobalVersionNumber = $"Version 3.43";
4444

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

0 commit comments

Comments
 (0)