From d0743d66a009afaae970cafbcfcc7490059116f1 Mon Sep 17 00:00:00 2001 From: pointfeev Date: Tue, 23 Aug 2022 21:57:22 -0400 Subject: [PATCH] rough koaloader implementation --- CreamInstaller/Forms/InstallForm.cs | 23 ++++++++++---------- CreamInstaller/ProgramSelection.cs | 7 +++++-- CreamInstaller/Resources/Koaloader.cs | 30 ++++++++++++++++++++------- CreamInstaller/Resources/Resources.cs | 23 -------------------- CreamInstaller/Utility/IconGrabber.cs | 2 +- 5 files changed, 41 insertions(+), 44 deletions(-) diff --git a/CreamInstaller/Forms/InstallForm.cs b/CreamInstaller/Forms/InstallForm.cs index 122af58..2d98031 100644 --- a/CreamInstaller/Forms/InstallForm.cs +++ b/CreamInstaller/Forms/InstallForm.cs @@ -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 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); } } } diff --git a/CreamInstaller/ProgramSelection.cs b/CreamInstaller/ProgramSelection.cs index 97d0413..52016e3 100644 --- a/CreamInstaller/ProgramSelection.cs +++ b/CreamInstaller/ProgramSelection.cs @@ -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 DllDirectories; - internal bool Koaloader = true; - internal readonly SortedList AllDlc = new(PlatformIdComparer.String); internal readonly SortedList SelectedDlc = new(PlatformIdComparer.String); internal readonly List<(string id, string name, SortedList dlc)> ExtraDlc = new(); // for Paradox Launcher internal readonly List<(string id, string name, SortedList dlc)> ExtraSelectedDlc = new(); // for Paradox Launcher + private List koaloaderDirectories; + internal async Task> GetKoaloaderDirectories() => koaloaderDirectories ??= await RootDirectory.GetKoaloaderDirectories(); + internal bool AreDllsLocked { get diff --git a/CreamInstaller/Resources/Koaloader.cs b/CreamInstaller/Resources/Koaloader.cs index d427e94..820af46 100644 --- a/CreamInstaller/Resources/Koaloader.cs +++ b/CreamInstaller/Resources/Koaloader.cs @@ -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> GetKoaloaderDirectories(this string rootDirectory) => await Task.Run(async () => + { + List 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 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 proxies, out string config); foreach (string proxy in proxies) diff --git a/CreamInstaller/Resources/Resources.cs b/CreamInstaller/Resources/Resources.cs index 590dcc0..2bfd539 100644 --- a/CreamInstaller/Resources/Resources.cs +++ b/CreamInstaller/Resources/Resources.cs @@ -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> GetExecutableDirectories(this string rootDirectory) => await Task.Run(async () => - { - List 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 moreExecutableDirectories = await _directory.GetExecutableDirectories(); - if (moreExecutableDirectories is not null) - executableDirectories.AddRange(moreExecutableDirectories); - } - catch { } - } - return !executableDirectories.Any() ? null : executableDirectories; - }); } diff --git a/CreamInstaller/Utility/IconGrabber.cs b/CreamInstaller/Utility/IconGrabber.cs index ef3fb7d..b24cd8c 100644 --- a/CreamInstaller/Utility/IconGrabber.cs +++ b/CreamInstaller/Utility/IconGrabber.cs @@ -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());