rough koaloader implementation

This commit is contained in:
pointfeev 2022-08-23 21:57:22 -04:00
parent 325f6ad117
commit d0743d66a0
5 changed files with 41 additions and 44 deletions

View file

@ -65,7 +65,7 @@ internal partial class InstallForm : CustomForm
}
if (selection.Koaloader && !Uninstalling)
{
foreach (string directory in await selection.RootDirectory.GetExecutableDirectories())
foreach (string directory in await selection.GetKoaloaderDirectories())
{
UpdateUser("Installing Koaloader to " + selection.Name + $" in directory \"{directory}\" . . . ", InstallationLog.Operation);
await Koaloader.Install(directory, selection, this);
@ -75,7 +75,7 @@ internal partial class InstallForm : CustomForm
{
if (Uninstalling)
{
foreach (string directory in await selection.RootDirectory.GetExecutableDirectories())
foreach (string directory in await selection.GetKoaloaderDirectories())
{
directory.GetKoaloaderComponents(out List<string> proxies, out string config);
bool proxyExists = false;
@ -85,20 +85,21 @@ internal partial class InstallForm : CustomForm
proxyExists = true;
break;
}
bool dllExists = false;
foreach ((string unlocker, string dll) in Koaloader.AutoLoadDlls)
{
string path = directory + @"\" + dll;
if (File.Exists(path))
bool dllExists = proxyExists || false;
if (!dllExists)
foreach ((string unlocker, string dll) in Koaloader.AutoLoadDlls)
{
dllExists = true;
break;
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);
await Koaloader.Uninstall(directory, selection, this);
await Koaloader.Uninstall(directory, this);
}
}
}

View file

@ -4,6 +4,7 @@ using CreamInstaller.Resources;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
namespace CreamInstaller;
@ -27,6 +28,7 @@ public enum DlcType
internal class ProgramSelection
{
internal bool Enabled;
internal bool Koaloader = true;
internal Platform Platform;
internal string Id = "0";
@ -43,14 +45,15 @@ internal class ProgramSelection
internal string RootDirectory;
internal List<string> DllDirectories;
internal bool Koaloader = true;
internal readonly SortedList<string, (DlcType type, string name, string icon)> AllDlc = new(PlatformIdComparer.String);
internal readonly SortedList<string, (DlcType type, string name, string icon)> SelectedDlc = new(PlatformIdComparer.String);
internal readonly List<(string id, string name, SortedList<string, (DlcType type, string name, string icon)> dlc)> ExtraDlc = new(); // for Paradox Launcher
internal readonly List<(string id, string name, SortedList<string, (DlcType type, string name, string icon)> dlc)> ExtraSelectedDlc = new(); // for Paradox Launcher
private List<string> koaloaderDirectories;
internal async Task<List<string>> GetKoaloaderDirectories() => koaloaderDirectories ??= await RootDirectory.GetKoaloaderDirectories();
internal bool AreDllsLocked
{
get

View file

@ -1,6 +1,4 @@
using ABI.System.Collections.Generic;
using CreamInstaller.Components;
using CreamInstaller.Components;
using CreamInstaller.Utility;
using System.Collections.Generic;
@ -9,9 +7,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Media.Playback;
using Windows.Networking.Connectivity;
namespace CreamInstaller.Resources;
internal static class Koaloader
@ -82,7 +77,28 @@ internal static class Koaloader
writer.WriteLine("}");
}
internal static async Task Uninstall(string directory, ProgramSelection selection, InstallForm installForm = null, bool deleteConfig = true) => await Task.Run(() =>
internal static async Task<List<string>> GetKoaloaderDirectories(this string rootDirectory) => await Task.Run(async () =>
{
List<string> executableDirectories = new();
if (Program.Canceled || !Directory.Exists(rootDirectory)) return null;
if (Directory.GetFiles(rootDirectory, "*.exe").Any())
executableDirectories.Add(rootDirectory);
string[] directories = Directory.GetDirectories(rootDirectory);
foreach (string _directory in directories)
{
if (Program.Canceled) return null;
try
{
List<string> moreExecutableDirectories = await _directory.GetKoaloaderDirectories();
if (moreExecutableDirectories is not null)
executableDirectories.AddRange(moreExecutableDirectories);
}
catch { }
}
return !executableDirectories.Any() ? null : executableDirectories;
});
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)

View file

@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Threading.Tasks;
namespace CreamInstaller.Resources;
@ -419,25 +417,4 @@ internal static class Resources
internal static bool IsResourceFile(this string filePath, ResourceIdentifier identifier) => filePath.ComputeMD5() is string hash && ResourceMD5s[identifier].Contains(hash);
internal static bool IsResourceFile(this string filePath) => filePath.ComputeMD5() is string hash && ResourceMD5s.Values.Any(hashes => hashes.Contains(hash));
internal static async Task<List<string>> GetExecutableDirectories(this string rootDirectory) => await Task.Run(async () =>
{
List<string> executableDirectories = new();
if (Program.Canceled || !Directory.Exists(rootDirectory)) return null;
if (Directory.GetFiles(rootDirectory, "*.exe").Any())
executableDirectories.Add(rootDirectory);
string[] directories = Directory.GetDirectories(rootDirectory);
foreach (string _directory in directories)
{
if (Program.Canceled) return null;
try
{
List<string> moreExecutableDirectories = await _directory.GetExecutableDirectories();
if (moreExecutableDirectories is not null)
executableDirectories.AddRange(moreExecutableDirectories);
}
catch { }
}
return !executableDirectories.Any() ? null : executableDirectories;
});
}

View file

@ -18,7 +18,7 @@ internal static class IconGrabber
internal static string GetDomainFaviconUrl(string domain, int size = 16) => GoogleFaviconsApiUrl + $"?domain={domain}&sz={size}";
internal static Image GetFileIconImage(string path) => File.Exists(path) ? Icon.ExtractAssociatedIcon(path).ToBitmap() : null;
internal static Image GetFileIconImage(this string path) => File.Exists(path) ? Icon.ExtractAssociatedIcon(path)?.ToBitmap() : null;
internal static Image GetNotepadImage() => GetFileIconImage(Diagnostics.GetNotepadPath());