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())
{
directory.GetKoaloaderComponents(out List<string> 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);

View file

@ -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,25 +100,20 @@ internal static class Koaloader
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);
foreach (string proxy in proxies)
{
if (File.Exists(proxy) && proxy.IsResourceFile(Resources.ResourceIdentifier.Koaloader))
foreach (string proxy in proxies.Where(proxy => 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);
}
}
foreach ((string unlocker, string dll) in AutoLoadDlls)
{
string path = directory + @"\" + dll;
if (File.Exists(path))
foreach ((string unlocker, string path) in AutoLoadDlls
.Select(pair => (pair.unlocker, path: directory + @"\" + pair.dll))
.Where(pair => File.Exists(pair.path)))
{
File.Delete(path);
if (installForm is not null)
installForm.UpdateUser($"Deleted {unlocker}: {Path.GetFileName(path)}", InstallationLog.Action, info: false);
}
}
if (deleteConfig && File.Exists(config))
{
File.Delete(config);