From 1fa39a3885fef3e572359529c1daac96bfda6838 Mon Sep 17 00:00:00 2001 From: pointfeev Date: Tue, 23 Aug 2022 22:13:11 -0400 Subject: [PATCH] refactoring --- CreamInstaller/Forms/InstallForm.cs | 22 +++-------------- CreamInstaller/Forms/MainForm.cs | 4 ++-- CreamInstaller/Resources/Koaloader.cs | 34 +++++++++++---------------- 3 files changed, 19 insertions(+), 41 deletions(-) diff --git a/CreamInstaller/Forms/InstallForm.cs b/CreamInstaller/Forms/InstallForm.cs index 2d98031..ab69b12 100644 --- a/CreamInstaller/Forms/InstallForm.cs +++ b/CreamInstaller/Forms/InstallForm.cs @@ -78,25 +78,9 @@ internal partial class InstallForm : CustomForm foreach (string directory in await selection.GetKoaloaderDirectories()) { directory.GetKoaloaderComponents(out List proxies, out string config); - bool proxyExists = false; - foreach (string proxy in proxies) - if (File.Exists(proxy) && proxy.IsResourceFile(Resources.Resources.ResourceIdentifier.Koaloader)) - { - proxyExists = true; - break; - } - bool dllExists = proxyExists || false; - if (!dllExists) - foreach ((string unlocker, string dll) in Koaloader.AutoLoadDlls) - { - string path = directory + @"\" + dll; - if (File.Exists(path)) - { - dllExists = true; - break; - } - } - if (proxyExists || dllExists || File.Exists(config)) + if (proxies.Any(proxy => File.Exists(proxy) && proxy.IsResourceFile(Resources.Resources.ResourceIdentifier.Koaloader)) + || Koaloader.AutoLoadDlls.Any(pair => File.Exists(directory + @"\" + pair.dll)) + || File.Exists(config)) { UpdateUser("Uninstalling Koaloader from " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation); await Koaloader.Uninstall(directory, this); diff --git a/CreamInstaller/Forms/MainForm.cs b/CreamInstaller/Forms/MainForm.cs index 405f3dc..94142b2 100644 --- a/CreamInstaller/Forms/MainForm.cs +++ b/CreamInstaller/Forms/MainForm.cs @@ -72,8 +72,8 @@ internal partial class MainForm : CustomForm if (checkForUpdatesResult.CanUpdate) { #endif - latestVersion = checkForUpdatesResult.LastVersion; - versions = checkForUpdatesResult.Versions; + latestVersion = checkForUpdatesResult.LastVersion; + versions = checkForUpdatesResult.Versions; #if !DEBUG } #endif diff --git a/CreamInstaller/Resources/Koaloader.cs b/CreamInstaller/Resources/Koaloader.cs index 820af46..e883901 100644 --- a/CreamInstaller/Resources/Koaloader.cs +++ b/CreamInstaller/Resources/Koaloader.cs @@ -18,12 +18,11 @@ internal static class Koaloader ) { proxies = new(); - foreach (string proxy in Resources.EmbeddedResources) + foreach (string proxy in Resources.EmbeddedResources.Select(proxy => { - string proxyPath = proxy[(proxy.IndexOf('.') + 1)..]; - proxyPath = proxyPath[(proxyPath.IndexOf('.') + 1)..]; - proxies.Add(directory + @"\" + proxyPath); - } + proxy = proxy[(proxy.IndexOf('.') + 1)..]; + return proxy[(proxy.IndexOf('.') + 1)..]; + })) proxies.Add(directory + @"\" + proxy); config = directory + @"\Koaloader.json"; } @@ -101,24 +100,19 @@ internal static class Koaloader internal static async Task Uninstall(string directory, InstallForm installForm = null, bool deleteConfig = true) => await Task.Run(() => { directory.GetKoaloaderComponents(out List proxies, out string config); - foreach (string proxy in proxies) + foreach (string proxy in proxies.Where(proxy => File.Exists(proxy) && proxy.IsResourceFile(Resources.ResourceIdentifier.Koaloader))) { - if (File.Exists(proxy) && proxy.IsResourceFile(Resources.ResourceIdentifier.Koaloader)) - { - File.Delete(proxy); - if (installForm is not null) - installForm.UpdateUser($"Deleted Koaloader: {Path.GetFileName(proxy)}", InstallationLog.Action, info: false); - } + File.Delete(proxy); + if (installForm is not null) + installForm.UpdateUser($"Deleted Koaloader: {Path.GetFileName(proxy)}", InstallationLog.Action, info: false); } - foreach ((string unlocker, string dll) in AutoLoadDlls) + foreach ((string unlocker, string path) in AutoLoadDlls + .Select(pair => (pair.unlocker, path: directory + @"\" + pair.dll)) + .Where(pair => File.Exists(pair.path))) { - string path = directory + @"\" + dll; - if (File.Exists(path)) - { - File.Delete(path); - if (installForm is not null) - installForm.UpdateUser($"Deleted {unlocker}: {Path.GetFileName(path)}", InstallationLog.Action, info: false); - } + File.Delete(path); + if (installForm is not null) + installForm.UpdateUser($"Deleted {unlocker}: {Path.GetFileName(path)}", InstallationLog.Action, info: false); } if (deleteConfig && File.Exists(config)) {