refactoring

This commit is contained in:
pointfeev 2022-08-23 22:13:11 -04:00
parent d0743d66a0
commit 1fa39a3885
3 changed files with 19 additions and 41 deletions

View file

@ -78,25 +78,9 @@ internal partial class InstallForm : CustomForm
foreach (string directory in await selection.GetKoaloaderDirectories()) foreach (string directory in await selection.GetKoaloaderDirectories())
{ {
directory.GetKoaloaderComponents(out List<string> proxies, out string config); directory.GetKoaloaderComponents(out List<string> proxies, out string config);
bool proxyExists = false; if (proxies.Any(proxy => File.Exists(proxy) && proxy.IsResourceFile(Resources.Resources.ResourceIdentifier.Koaloader))
foreach (string proxy in proxies) || Koaloader.AutoLoadDlls.Any(pair => File.Exists(directory + @"\" + pair.dll))
if (File.Exists(proxy) && proxy.IsResourceFile(Resources.Resources.ResourceIdentifier.Koaloader)) || File.Exists(config))
{
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))
{ {
UpdateUser("Uninstalling Koaloader from " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation); UpdateUser("Uninstalling Koaloader from " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation);
await Koaloader.Uninstall(directory, this); await Koaloader.Uninstall(directory, this);

View file

@ -18,12 +18,11 @@ internal static class Koaloader
) )
{ {
proxies = new(); proxies = new();
foreach (string proxy in Resources.EmbeddedResources) foreach (string proxy in Resources.EmbeddedResources.Select(proxy =>
{ {
string proxyPath = proxy[(proxy.IndexOf('.') + 1)..]; proxy = proxy[(proxy.IndexOf('.') + 1)..];
proxyPath = proxyPath[(proxyPath.IndexOf('.') + 1)..]; return proxy[(proxy.IndexOf('.') + 1)..];
proxies.Add(directory + @"\" + proxyPath); })) proxies.Add(directory + @"\" + proxy);
}
config = directory + @"\Koaloader.json"; config = directory + @"\Koaloader.json";
} }
@ -101,25 +100,20 @@ internal static class Koaloader
internal static async Task Uninstall(string directory, InstallForm installForm = null, bool deleteConfig = true) => await Task.Run(() => internal static async Task Uninstall(string directory, InstallForm installForm = null, bool deleteConfig = true) => await Task.Run(() =>
{ {
directory.GetKoaloaderComponents(out List<string> proxies, out string config); directory.GetKoaloaderComponents(out List<string> 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); File.Delete(proxy);
if (installForm is not null) if (installForm is not null)
installForm.UpdateUser($"Deleted Koaloader: {Path.GetFileName(proxy)}", InstallationLog.Action, info: false); installForm.UpdateUser($"Deleted Koaloader: {Path.GetFileName(proxy)}", InstallationLog.Action, info: false);
} }
} foreach ((string unlocker, string path) in AutoLoadDlls
foreach ((string unlocker, string dll) 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); File.Delete(path);
if (installForm is not null) if (installForm is not null)
installForm.UpdateUser($"Deleted {unlocker}: {Path.GetFileName(path)}", InstallationLog.Action, info: false); installForm.UpdateUser($"Deleted {unlocker}: {Path.GetFileName(path)}", InstallationLog.Action, info: false);
} }
}
if (deleteConfig && File.Exists(config)) if (deleteConfig && File.Exists(config))
{ {
File.Delete(config); File.Delete(config);