diff --git a/CreamInstaller/Components/CustomTreeView.cs b/CreamInstaller/Components/CustomTreeView.cs index 2da011e..36e1ad3 100644 --- a/CreamInstaller/Components/CustomTreeView.cs +++ b/CreamInstaller/Components/CustomTreeView.cs @@ -206,7 +206,7 @@ internal sealed class CustomTreeView : TreeView foreach ((string directory, BinaryType _) in pair.Key.ExecutableDirectories) { string path = directory + @"\" + proxy + ".dll"; - if (!path.FileExists(form: form) || path.IsResourceFile(ResourceIdentifier.Koaloader)) + if (!path.FileExists() || path.IsResourceFile(ResourceIdentifier.Koaloader)) continue; canUse = false; break; diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index 2bb0308..3e7e6aa 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -4,7 +4,7 @@ net7.0-windows True Resources\ini.ico - 4.7.1.2 + 4.7.1.3 2021, pointfeev (https://github.com/pointfeev) CreamInstaller Automatic DLC Unlocker Installer & Configuration Generator @@ -21,6 +21,7 @@ $(DefineConstants) False latest + True $(Company) @@ -29,118 +30,118 @@ $(Company)-debug - False + False - False + False - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CreamInstaller/Forms/InstallForm.cs b/CreamInstaller/Forms/InstallForm.cs index 5eeea56..5107abc 100644 --- a/CreamInstaller/Forms/InstallForm.cs +++ b/CreamInstaller/Forms/InstallForm.cs @@ -80,9 +80,9 @@ internal sealed partial class InstallForm : CustomForm if (Program.Canceled) throw new CustomMessageException("The operation was canceled."); directory.GetKoaloaderComponents(out string old_config, out string config); - if (directory.GetKoaloaderProxies().Any(proxy => proxy.FileExists(form: this) && proxy.IsResourceFile(ResourceIdentifier.Koaloader)) - || directory != selection.RootDirectory && Koaloader.AutoLoadDLLs.Any(pair => (directory + @"\" + pair.dll).FileExists(form: this)) - || old_config.FileExists(form: this) || config.FileExists(form: this)) + if (directory.GetKoaloaderProxies().Any(proxy => proxy.FileExists() && proxy.IsResourceFile(ResourceIdentifier.Koaloader)) + || directory != selection.RootDirectory && Koaloader.AutoLoadDLLs.Any(pair => (directory + @"\" + pair.dll).FileExists()) + || old_config.FileExists() || config.FileExists()) { UpdateUser("Uninstalling Koaloader from " + selection.Name + $" in incorrect directory \"{directory}\" . . . ", LogTextBox.Operation); await Koaloader.Uninstall(directory, selection.RootDirectory, this); @@ -95,9 +95,8 @@ internal sealed partial class InstallForm : CustomForm if (Program.Canceled) throw new CustomMessageException("The operation was canceled."); directory.GetKoaloaderComponents(out string old_config, out string config); - if (directory.GetKoaloaderProxies().Any(proxy => proxy.FileExists(form: this) && proxy.IsResourceFile(ResourceIdentifier.Koaloader)) - || Koaloader.AutoLoadDLLs.Any(pair => (directory + @"\" + pair.dll).FileExists(form: this)) || old_config.FileExists(form: this) - || config.FileExists(form: this)) + if (directory.GetKoaloaderProxies().Any(proxy => proxy.FileExists() && proxy.IsResourceFile(ResourceIdentifier.Koaloader)) + || Koaloader.AutoLoadDLLs.Any(pair => (directory + @"\" + pair.dll).FileExists()) || old_config.FileExists() || config.FileExists()) { UpdateUser("Uninstalling Koaloader from " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation); await Koaloader.Uninstall(directory, selection.RootDirectory, this); @@ -115,9 +114,9 @@ internal sealed partial class InstallForm : CustomForm directory.GetSmokeApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string old_config, out string config, out string old_log, out string log, out string cache); if (uninstallProxy - ? api32_o.FileExists(form: this) || api64_o.FileExists(form: this) || old_config.FileExists(form: this) || config.FileExists(form: this) - || old_log.FileExists(form: this) || log.FileExists(form: this) || cache.FileExists(form: this) - : api32.FileExists(form: this) || api64.FileExists(form: this)) + ? api32_o.FileExists() || api64_o.FileExists() || old_config.FileExists() || config.FileExists() || old_log.FileExists() + || log.FileExists() || cache.FileExists() + : api32.FileExists() || api64.FileExists()) { UpdateUser( $"{(uninstallProxy ? "Uninstalling" : "Installing")} SmokeAPI" + $" {(uninstallProxy ? "from" : "for")} " + selection.Name @@ -132,8 +131,8 @@ internal sealed partial class InstallForm : CustomForm { directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log); if (uninstallProxy - ? api32_o.FileExists(form: this) || api64_o.FileExists(form: this) || config.FileExists(form: this) || log.FileExists(form: this) - : api32.FileExists(form: this) || api64.FileExists(form: this)) + ? api32_o.FileExists() || api64_o.FileExists() || config.FileExists() || log.FileExists() + : api32.FileExists() || api64.FileExists()) { UpdateUser( $"{(uninstallProxy ? "Uninstalling" : "Installing")} ScreamAPI" + $" {(uninstallProxy ? "from" : "for")} " + selection.Name @@ -148,8 +147,8 @@ internal sealed partial class InstallForm : CustomForm { directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log); if (uninstallProxy - ? api32_o.FileExists(form: this) || api64_o.FileExists(form: this) || config.FileExists(form: this) || log.FileExists(form: this) - : api32.FileExists(form: this) || api64.FileExists(form: this)) + ? api32_o.FileExists() || api64_o.FileExists() || config.FileExists() || log.FileExists() + : api32.FileExists() || api64.FileExists()) { UpdateUser( $"{(uninstallProxy ? "Uninstalling" : "Installing")} Uplay R1 Unlocker" + $" {(uninstallProxy ? "from" : "for")} " + selection.Name @@ -161,8 +160,8 @@ internal sealed partial class InstallForm : CustomForm } directory.GetUplayR2Components(out string old_api32, out string old_api64, out api32, out api32_o, out api64, out api64_o, out config, out log); if (uninstallProxy - ? api32_o.FileExists(form: this) || api64_o.FileExists(form: this) || config.FileExists(form: this) || log.FileExists(form: this) - : old_api32.FileExists(form: this) || old_api64.FileExists(form: this) || api32.FileExists(form: this) || api64.FileExists(form: this)) + ? api32_o.FileExists() || api64_o.FileExists() || config.FileExists() || log.FileExists() + : old_api32.FileExists() || old_api64.FileExists() || api32.FileExists() || api64.FileExists()) { UpdateUser( $"{(uninstallProxy ? "Uninstalling" : "Installing")} Uplay R2 Unlocker" + $" {(uninstallProxy ? "from" : "for")} " + selection.Name diff --git a/CreamInstaller/Forms/SelectForm.cs b/CreamInstaller/Forms/SelectForm.cs index e13ebb4..73dfc7e 100644 --- a/CreamInstaller/Forms/SelectForm.cs +++ b/CreamInstaller/Forms/SelectForm.cs @@ -126,7 +126,7 @@ internal sealed partial class SelectForm : CustomForm if (uninstallAll || programsToScan.Any(c => c.platform is Platform.Paradox)) { AddToRemainingGames("Paradox Launcher"); - List dllDirectories = await ParadoxLauncher.InstallPath.GetDllDirectoriesFromGameDirectory(Platform.Paradox, this); + List dllDirectories = await ParadoxLauncher.InstallPath.GetDllDirectoriesFromGameDirectory(Platform.Paradox); if (dllDirectories is not null) { if (uninstallAll) @@ -183,7 +183,7 @@ internal sealed partial class SelectForm : CustomForm { if (Program.Canceled) return; - List dllDirectories = await gameDirectory.GetDllDirectoriesFromGameDirectory(Platform.Steam, this); + List dllDirectories = await gameDirectory.GetDllDirectoriesFromGameDirectory(Platform.Steam); if (dllDirectories is null) { Interlocked.Decrement(ref steamGamesToCheck); @@ -386,7 +386,7 @@ internal sealed partial class SelectForm : CustomForm { if (Program.Canceled) return; - List dllDirectories = await directory.GetDllDirectoriesFromGameDirectory(Platform.Epic, this); + List dllDirectories = await directory.GetDllDirectoriesFromGameDirectory(Platform.Epic); if (dllDirectories is null) { RemoveFromRemainingGames(name); @@ -520,7 +520,7 @@ internal sealed partial class SelectForm : CustomForm { if (Program.Canceled) return; - List dllDirectories = await gameDirectory.GetDllDirectoriesFromGameDirectory(Platform.Ubisoft, this); + List dllDirectories = await gameDirectory.GetDllDirectoriesFromGameDirectory(Platform.Ubisoft); if (dllDirectories is null) { RemoveFromRemainingGames(name); @@ -858,10 +858,10 @@ internal sealed partial class SelectForm : CustomForm string appInfoVDF = $@"{SteamCMD.AppInfoPath}\{id}.vdf"; string appInfoJSON = $@"{SteamCMD.AppInfoPath}\{id}.json"; string cooldown = $@"{ProgramData.CooldownPath}\{id}.txt"; - if (appInfoVDF.FileExists(form: this) || appInfoJSON.FileExists(form: this)) + if (appInfoVDF.FileExists() || appInfoJSON.FileExists()) { List queries = new(); - if (appInfoJSON.FileExists(form: this)) + if (appInfoJSON.FileExists()) { string platformString = selection is null || selection.Platform is Platform.Steam ? "Steam Store " @@ -870,7 +870,7 @@ internal sealed partial class SelectForm : CustomForm : ""; queries.Add(new($"Open {platformString}Query", "Notepad", (_, _) => Diagnostics.OpenFileInNotepad(appInfoJSON))); } - if (appInfoVDF.FileExists(form: this)) + if (appInfoVDF.FileExists()) queries.Add(new("Open SteamCMD Query", "Notepad", (_, _) => Diagnostics.OpenFileInNotepad(appInfoVDF))); if (queries.Any()) { @@ -908,9 +908,8 @@ internal sealed partial class SelectForm : CustomForm { directory.GetSmokeApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string old_config, out string config, out string old_log, out string log, out string cache); - if (api32.FileExists(form: this) || api32_o.FileExists(form: this) || api64.FileExists(form: this) || api64_o.FileExists(form: this) - || old_config.FileExists(form: this) || config.FileExists(form: this) || old_log.FileExists(form: this) || log.FileExists(form: this) - || cache.FileExists(form: this)) + if (api32.FileExists() || api32_o.FileExists() || api64.FileExists() || api64_o.FileExists() || old_config.FileExists() + || config.FileExists() || old_log.FileExists() || log.FileExists() || cache.FileExists()) items.Add(new ContextMenuItem($"Open Steamworks Directory #{++steam}", "File Explorer", (_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); } @@ -919,8 +918,7 @@ internal sealed partial class SelectForm : CustomForm { directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log); - if (api32.FileExists(form: this) || api32_o.FileExists(form: this) || api64.FileExists(form: this) || api64_o.FileExists(form: this) - || config.FileExists(form: this) || log.FileExists(form: this)) + if (api32.FileExists() || api32_o.FileExists() || api64.FileExists() || api64_o.FileExists() || config.FileExists() || log.FileExists()) items.Add(new ContextMenuItem($"Open EOS Directory #{++epic}", "File Explorer", (_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); } @@ -929,15 +927,13 @@ internal sealed partial class SelectForm : CustomForm { directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log); - if (api32.FileExists(form: this) || api32_o.FileExists(form: this) || api64.FileExists(form: this) || api64_o.FileExists(form: this) - || config.FileExists(form: this) || log.FileExists(form: this)) + if (api32.FileExists() || api32_o.FileExists() || api64.FileExists() || api64_o.FileExists() || config.FileExists() || log.FileExists()) items.Add(new ContextMenuItem($"Open Uplay R1 Directory #{++r1}", "File Explorer", (_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); directory.GetUplayR2Components(out string old_api32, out string old_api64, out api32, out api32_o, out api64, out api64_o, out config, out log); - if (old_api32.FileExists(form: this) || old_api64.FileExists(form: this) || api32.FileExists(form: this) - || api32_o.FileExists(form: this) || api64.FileExists(form: this) || api64_o.FileExists(form: this) || config.FileExists(form: this) - || log.FileExists(form: this)) + if (old_api32.FileExists() || old_api64.FileExists() || api32.FileExists() || api32_o.FileExists() || api64.FileExists() + || api64_o.FileExists() || config.FileExists() || log.FileExists()) items.Add(new ContextMenuItem($"Open Uplay R2 Directory #{++r2}", "File Explorer", (_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); } diff --git a/CreamInstaller/Platforms/Paradox/ParadoxLauncher.cs b/CreamInstaller/Platforms/Paradox/ParadoxLauncher.cs index 5953443..327cf16 100644 --- a/CreamInstaller/Platforms/Paradox/ParadoxLauncher.cs +++ b/CreamInstaller/Platforms/Paradox/ParadoxLauncher.cs @@ -80,7 +80,9 @@ internal static class ParadoxLauncher { InstallForm installForm = form as InstallForm; if (!Program.AreDllsLockedDialog(form, selection)) - return form is InstallForm ? throw new CustomMessageException("Repair failed! One or more DLLs crucial to unlocker installation are locked!") : RepairResult.ProgramRunning; + return form is InstallForm + ? throw new CustomMessageException("Repair failed! One or more DLLs crucial to unlocker installation are locked!") + : RepairResult.ProgramRunning; bool smokeInstalled = false; byte[] steamOriginalSdk32 = null; byte[] steamOriginalSdk64 = null; @@ -90,27 +92,27 @@ internal static class ParadoxLauncher foreach (string directory in selection.DllDirectories) { bool koaloaderInstalled = Koaloader.AutoLoadDLLs.Select(pair => (pair.unlocker, path: directory + @"\" + pair.dll)) - .Any(pair => pair.path.FileExists(form: form) && pair.path.IsResourceFile()); + .Any(pair => pair.path.FileExists() && pair.path.IsResourceFile()); directory.GetSmokeApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string old_config, out string config, out _, out _, out _); - smokeInstalled = smokeInstalled || api32_o.FileExists(form: form) || api64_o.FileExists(form: form) - || (old_config.FileExists(form: form) || config.FileExists(form: form)) && !koaloaderInstalled - || api32.FileExists(form: form) && api32.IsResourceFile(ResourceIdentifier.Steamworks32) - || api64.FileExists(form: form) && api64.IsResourceFile(ResourceIdentifier.Steamworks64); + smokeInstalled = smokeInstalled || api32_o.FileExists() || api64_o.FileExists() + || (old_config.FileExists() || config.FileExists()) && !koaloaderInstalled + || api32.FileExists() && api32.IsResourceFile(ResourceIdentifier.Steamworks32) + || api64.FileExists() && api64.IsResourceFile(ResourceIdentifier.Steamworks64); await SmokeAPI.Uninstall(directory, deleteOthers: false); - if (steamOriginalSdk32 is null && api32.FileExists(form: form) && !api32.IsResourceFile(ResourceIdentifier.Steamworks32)) + if (steamOriginalSdk32 is null && api32.FileExists() && !api32.IsResourceFile(ResourceIdentifier.Steamworks32)) steamOriginalSdk32 = api32.ReadFileBytes(true); - if (steamOriginalSdk64 is null && api64.FileExists(form: form) && !api64.IsResourceFile(ResourceIdentifier.Steamworks64)) + if (steamOriginalSdk64 is null && api64.FileExists() && !api64.IsResourceFile(ResourceIdentifier.Steamworks64)) steamOriginalSdk64 = api64.ReadFileBytes(true); directory.GetScreamApiComponents(out api32, out api32_o, out api64, out api64_o, out config, out string log); - screamInstalled = screamInstalled || api32_o.FileExists(form: form) || api64_o.FileExists(form: form) - || (config.FileExists(form: form) || log.FileExists(form: form)) && !koaloaderInstalled - || api32.FileExists(form: form) && api32.IsResourceFile(ResourceIdentifier.EpicOnlineServices32) - || api64.FileExists(form: form) && api64.IsResourceFile(ResourceIdentifier.EpicOnlineServices64); + screamInstalled = screamInstalled || api32_o.FileExists() || api64_o.FileExists() + || (config.FileExists() || log.FileExists()) && !koaloaderInstalled + || api32.FileExists() && api32.IsResourceFile(ResourceIdentifier.EpicOnlineServices32) + || api64.FileExists() && api64.IsResourceFile(ResourceIdentifier.EpicOnlineServices64); await ScreamAPI.Uninstall(directory, deleteOthers: false); - if (epicOriginalSdk32 is null && api32.FileExists(form: form) && !api32.IsResourceFile(ResourceIdentifier.EpicOnlineServices32)) + if (epicOriginalSdk32 is null && api32.FileExists() && !api32.IsResourceFile(ResourceIdentifier.EpicOnlineServices32)) epicOriginalSdk32 = api32.ReadFileBytes(true); - if (epicOriginalSdk64 is null && api64.FileExists(form: form) && !api64.IsResourceFile(ResourceIdentifier.EpicOnlineServices64)) + if (epicOriginalSdk64 is null && api64.FileExists() && !api64.IsResourceFile(ResourceIdentifier.EpicOnlineServices64)) epicOriginalSdk64 = api64.ReadFileBytes(true); } using DialogForm dialogForm = new(form); diff --git a/CreamInstaller/Resources/Koaloader.cs b/CreamInstaller/Resources/Koaloader.cs index 5752cb7..650a17f 100644 --- a/CreamInstaller/Resources/Koaloader.cs +++ b/CreamInstaller/Resources/Koaloader.cs @@ -60,9 +60,9 @@ internal static class Koaloader private static void CheckConfig(string directory, InstallForm installForm = null) { directory.GetKoaloaderComponents(out string old_config, out string config); - if (old_config.FileExists(form: installForm)) + if (old_config.FileExists()) { - if (!config.FileExists(form: installForm)) + if (!config.FileExists()) { old_config.MoveFile(config!); installForm?.UpdateUser($"Converted old configuration: {Path.GetFileName(old_config)} -> {Path.GetFileName(config)}", LogTextBox.Action, false); @@ -85,7 +85,7 @@ internal static class Koaloader writer.Flush(); writer.Close(); } - else if (config.FileExists(form: installForm)) + else if (config.FileExists()) { config.DeleteFile(); installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); @@ -137,23 +137,23 @@ internal static class Koaloader { directory.GetKoaloaderComponents(out string old_config, out string config); foreach (string proxyPath in directory.GetKoaloaderProxies().Where(proxyPath - => proxyPath.FileExists(form: installForm) && proxyPath.IsResourceFile(ResourceIdentifier.Koaloader))) + => proxyPath.FileExists() && proxyPath.IsResourceFile(ResourceIdentifier.Koaloader))) { proxyPath.DeleteFile(); installForm?.UpdateUser($"Deleted Koaloader: {Path.GetFileName(proxyPath)}", LogTextBox.Action, false); } foreach ((string unlocker, string path) in AutoLoadDLLs.Select(pair => (pair.unlocker, path: directory + @"\" + pair.dll)) - .Where(pair => pair.path.FileExists(form: installForm) && pair.path.IsResourceFile())) + .Where(pair => pair.path.FileExists() && pair.path.IsResourceFile())) { path.DeleteFile(); installForm?.UpdateUser($"Deleted {unlocker}: {Path.GetFileName(path)}", LogTextBox.Action, false); } - if (deleteConfig && old_config.FileExists(form: installForm)) + if (deleteConfig && old_config.FileExists()) { old_config.DeleteFile(); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(old_config)}", LogTextBox.Action, false); } - if (deleteConfig && config.FileExists(form: installForm)) + if (deleteConfig && config.FileExists()) { config.DeleteFile(); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); @@ -172,13 +172,12 @@ internal static class Koaloader { string proxy = selection.KoaloaderProxy ?? ProgramSelection.DefaultKoaloaderProxy; string path = directory + @"\" + proxy + ".dll"; - foreach (string _path in directory.GetKoaloaderProxies() - .Where(p => p != path && p.FileExists(form: installForm) && p.IsResourceFile(ResourceIdentifier.Koaloader))) + foreach (string _path in directory.GetKoaloaderProxies().Where(p => p != path && p.FileExists() && p.IsResourceFile(ResourceIdentifier.Koaloader))) { _path.DeleteFile(); installForm?.UpdateUser($"Deleted Koaloader: {Path.GetFileName(_path)}", LogTextBox.Action, false); } - if (path.FileExists(form: installForm) && !path.IsResourceFile(ResourceIdentifier.Koaloader)) + if (path.FileExists() && !path.IsResourceFile(ResourceIdentifier.Koaloader)) throw new CustomMessageException("A non-Koaloader DLL named " + proxy + ".dll already exists in this directory!"); path.WriteProxy(proxy, binaryType); installForm?.UpdateUser($"Wrote {(binaryType == BinaryType.BIT32 ? "32-bit" : "64-bit")} Koaloader: {Path.GetFileName(path)}", LogTextBox.Action, @@ -206,7 +205,7 @@ internal static class Koaloader path = directory + @"\SmokeAPI32.dll"; if (rootDirectory is not null && directory != rootDirectory) { - if (path.FileExists(form: installForm)) + if (path.FileExists()) { path.DeleteFile(); installForm?.UpdateUser($"Deleted SmokeAPI from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, false); @@ -223,7 +222,7 @@ internal static class Koaloader path = directory + @"\SmokeAPI64.dll"; if (rootDirectory is not null && directory != rootDirectory) { - if (path.FileExists(form: installForm)) + if (path.FileExists()) { path.DeleteFile(); installForm?.UpdateUser($"Deleted SmokeAPI from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, false); @@ -246,7 +245,7 @@ internal static class Koaloader path = directory + @"\ScreamAPI32.dll"; if (rootDirectory is not null && directory != rootDirectory) { - if (path.FileExists(form: installForm)) + if (path.FileExists()) { path.DeleteFile(); installForm?.UpdateUser($"Deleted ScreamAPI from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, false); @@ -263,7 +262,7 @@ internal static class Koaloader path = directory + @"\ScreamAPI64.dll"; if (rootDirectory is not null && directory != rootDirectory) { - if (path.FileExists(form: installForm)) + if (path.FileExists()) { path.DeleteFile(); installForm?.UpdateUser($"Deleted ScreamAPI from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, false); @@ -285,7 +284,7 @@ internal static class Koaloader path = directory + @"\UplayR1Unlocker32.dll"; if (rootDirectory is not null && directory != rootDirectory) { - if (path.FileExists(form: installForm)) + if (path.FileExists()) { path.DeleteFile(); installForm?.UpdateUser($"Deleted Uplay R1 Unlocker from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, @@ -303,7 +302,7 @@ internal static class Koaloader path = directory + @"\UplayR1Unlocker64.dll"; if (rootDirectory is not null && directory != rootDirectory) { - if (path.FileExists(form: installForm)) + if (path.FileExists()) { path.DeleteFile(); installForm?.UpdateUser($"Deleted Uplay R1 Unlocker from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, @@ -322,7 +321,7 @@ internal static class Koaloader path = directory + @"\UplayR2Unlocker32.dll"; if (rootDirectory is not null && directory != rootDirectory) { - if (path.FileExists(form: installForm)) + if (path.FileExists()) { path.DeleteFile(); installForm?.UpdateUser($"Deleted Uplay R2 Unlocker from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, @@ -340,7 +339,7 @@ internal static class Koaloader path = directory + @"\UplayR2Unlocker64.dll"; if (rootDirectory is not null && directory != rootDirectory) { - if (path.FileExists(form: installForm)) + if (path.FileExists()) { path.DeleteFile(); installForm?.UpdateUser($"Deleted Uplay R2 Unlocker from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, diff --git a/CreamInstaller/Resources/Resources.cs b/CreamInstaller/Resources/Resources.cs index 95b4c8a..0bbb4a7 100644 --- a/CreamInstaller/Resources/Resources.cs +++ b/CreamInstaller/Resources/Resources.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; -using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; @@ -480,10 +479,7 @@ internal static class Resources } } - [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), DefaultDllImportSearchPaths(DllImportSearchPath.System32)] - private static extern bool GetBinaryType(string lpApplicationName, out BinaryType lpBinaryType); - - internal static bool TryGetFileBinaryType(this string path, out BinaryType binaryType) => GetBinaryType(path, out binaryType); + internal static bool TryGetFileBinaryType(this string path, out BinaryType binaryType) => NativeImports.GetBinaryType(path, out binaryType); internal static async Task> GetExecutableDirectories(this string rootDirectory, bool filterCommon = false, Func validFunc = null) @@ -535,7 +531,7 @@ internal static class Resources || subPath.Contains("ANTICHEAT"); } - internal static async Task> GetDllDirectoriesFromGameDirectory(this string gameDirectory, Platform platform, Form form = null) + internal static async Task> GetDllDirectoriesFromGameDirectory(this string gameDirectory, Platform platform) => await Task.Run(() => { List dllDirectories = new(); @@ -549,36 +545,35 @@ internal static class Resources if (dllDirectories.Contains(subDirectory)) continue; bool koaloaderInstalled = Koaloader.AutoLoadDLLs.Select(pair => (pair.unlocker, path: directory + @"\" + pair.dll)) - .Any(pair => pair.path.FileExists(form: form) && pair.path.IsResourceFile()); + .Any(pair => pair.path.FileExists() && pair.path.IsResourceFile()); if (platform is Platform.Steam or Platform.Paradox) { subDirectory.GetSmokeApiComponents(out string api, out string api_o, out string api64, out string api64_o, out string old_config, out string config, out string old_log, out string log, out string cache); - if (api.FileExists(form: form) || api_o.FileExists(form: form) || api64.FileExists(form: form) || api64_o.FileExists(form: form) - || (old_config.FileExists(form: form) || config.FileExists(form: form) || old_log.FileExists(form: form) || log.FileExists(form: form) - || cache.FileExists(form: form)) && !koaloaderInstalled) + if (api.FileExists() || api_o.FileExists() || api64.FileExists() || api64_o.FileExists() + || (old_config.FileExists() || config.FileExists() || old_log.FileExists() || log.FileExists() || cache.FileExists()) + && !koaloaderInstalled) dllDirectories.Add(subDirectory); } if (platform is Platform.Epic or Platform.Paradox) { subDirectory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log); - if (api32.FileExists(form: form) || api32_o.FileExists(form: form) || api64.FileExists(form: form) || api64_o.FileExists(form: form) - || (config.FileExists(form: form) || log.FileExists(form: form)) && !koaloaderInstalled) + if (api32.FileExists() || api32_o.FileExists() || api64.FileExists() || api64_o.FileExists() + || (config.FileExists() || log.FileExists()) && !koaloaderInstalled) dllDirectories.Add(subDirectory); } if (platform is Platform.Ubisoft) { subDirectory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log); - if (api32.FileExists(form: form) || api32_o.FileExists(form: form) || api64.FileExists(form: form) || api64_o.FileExists(form: form) - || (config.FileExists(form: form) || log.FileExists(form: form)) && !koaloaderInstalled) + if (api32.FileExists() || api32_o.FileExists() || api64.FileExists() || api64_o.FileExists() + || (config.FileExists() || log.FileExists()) && !koaloaderInstalled) dllDirectories.Add(subDirectory); subDirectory.GetUplayR2Components(out string old_api32, out string old_api64, out api32, out api32_o, out api64, out api64_o, out config, out log); - if (old_api32.FileExists(form: form) || old_api64.FileExists(form: form) || api32.FileExists(form: form) || api32_o.FileExists(form: form) - || api64.FileExists(form: form) || api64_o.FileExists(form: form) - || (config.FileExists(form: form) || log.FileExists(form: form)) && !koaloaderInstalled) + if (old_api32.FileExists() || old_api64.FileExists() || api32.FileExists() || api32_o.FileExists() || api64.FileExists() + || api64_o.FileExists() || (config.FileExists() || log.FileExists()) && !koaloaderInstalled) dllDirectories.Add(subDirectory); } } @@ -597,7 +592,7 @@ internal static class Resources #pragma warning disable CA5351 private static string ComputeMD5(this string filePath) - => filePath.FileExists() && filePath.ReadFileBytes() is { } bytes + => filePath.FileExists() && filePath.ReadFileBytes(true) is { } bytes ? BitConverter.ToString(MD5.HashData(bytes)).Replace("-", "").ToUpperInvariant() : null; #pragma warning restore CA5351 diff --git a/CreamInstaller/Resources/ScreamAPI.cs b/CreamInstaller/Resources/ScreamAPI.cs index 6be7eb7..95fd015 100644 --- a/CreamInstaller/Resources/ScreamAPI.cs +++ b/CreamInstaller/Resources/ScreamAPI.cs @@ -46,7 +46,7 @@ internal static class ScreamAPI writer.Flush(); writer.Close(); } - else if (config.FileExists(form: installForm)) + else if (config.FileExists()) { config.DeleteFile(); installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); @@ -105,9 +105,9 @@ internal static class ScreamAPI => await Task.Run(() => { directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log); - if (api32_o.FileExists(form: installForm)) + if (api32_o.FileExists()) { - if (api32.FileExists(form: installForm)) + if (api32.FileExists()) { api32.DeleteFile(); installForm?.UpdateUser($"Deleted ScreamAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false); @@ -115,9 +115,9 @@ internal static class ScreamAPI api32_o.MoveFile(api32!); installForm?.UpdateUser($"Restored EOS: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false); } - if (api64_o.FileExists(form: installForm)) + if (api64_o.FileExists()) { - if (api64.FileExists(form: installForm)) + if (api64.FileExists()) { api64.DeleteFile(); installForm?.UpdateUser($"Deleted ScreamAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false); @@ -127,12 +127,12 @@ internal static class ScreamAPI } if (!deleteOthers) return; - if (config.FileExists(form: installForm)) + if (config.FileExists()) { config.DeleteFile(); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); } - if (log.FileExists(form: installForm)) + if (log.FileExists()) { log.DeleteFile(); installForm?.UpdateUser($"Deleted log: {Path.GetFileName(log)}", LogTextBox.Action, false); @@ -143,22 +143,22 @@ internal static class ScreamAPI => await Task.Run(() => { directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out _, out _); - if (api32.FileExists(form: installForm) && !api32_o.FileExists(form: installForm)) + if (api32.FileExists() && !api32_o.FileExists()) { api32.MoveFile(api32_o!); installForm?.UpdateUser($"Renamed EOS: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false); } - if (api32_o.FileExists(form: installForm)) + if (api32_o.FileExists()) { "ScreamAPI.EOSSDK-Win32-Shipping.dll".WriteManifestResource(api32); installForm?.UpdateUser($"Wrote ScreamAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false); } - if (api64.FileExists(form: installForm) && !api64_o.FileExists(form: installForm)) + if (api64.FileExists() && !api64_o.FileExists()) { api64.MoveFile(api64_o!); installForm?.UpdateUser($"Renamed EOS: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false); } - if (api64_o.FileExists(form: installForm)) + if (api64_o.FileExists()) { "ScreamAPI.EOSSDK-Win64-Shipping.dll".WriteManifestResource(api64); installForm?.UpdateUser($"Wrote ScreamAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false); diff --git a/CreamInstaller/Resources/SmokeAPI.cs b/CreamInstaller/Resources/SmokeAPI.cs index bc47de9..185a22c 100644 --- a/CreamInstaller/Resources/SmokeAPI.cs +++ b/CreamInstaller/Resources/SmokeAPI.cs @@ -51,7 +51,7 @@ internal static class SmokeAPI extraApps.Add(newExtraPair); } injectDlc = injectDlc.ToList(); - if (old_config.FileExists(form: installForm)) + if (old_config.FileExists()) { old_config.DeleteFile(); installForm?.UpdateUser($"Deleted old configuration: {Path.GetFileName(old_config)}", LogTextBox.Action, false); @@ -68,7 +68,7 @@ internal static class SmokeAPI writer.Flush(); writer.Close(); } - else if (config.FileExists(form: installForm)) + else if (config.FileExists()) { config.DeleteFile(); installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); @@ -155,16 +155,16 @@ internal static class SmokeAPI => await Task.Run(() => { directory.GetCreamApiComponents(out _, out _, out _, out _, out string oldConfig); - if (oldConfig.FileExists(form: installForm)) + if (oldConfig.FileExists()) { oldConfig.DeleteFile(); installForm?.UpdateUser($"Deleted old CreamAPI configuration: {Path.GetFileName(oldConfig)}", LogTextBox.Action, false); } directory.GetSmokeApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string old_config, out string config, out string old_log, out string log, out string cache); - if (api32_o.FileExists(form: installForm)) + if (api32_o.FileExists()) { - if (api32.FileExists(form: installForm)) + if (api32.FileExists()) { api32.DeleteFile(); installForm?.UpdateUser($"Deleted SmokeAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false); @@ -172,9 +172,9 @@ internal static class SmokeAPI api32_o.MoveFile(api32!); installForm?.UpdateUser($"Restored Steamworks: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false); } - if (api64_o.FileExists(form: installForm)) + if (api64_o.FileExists()) { - if (api64.FileExists(form: installForm)) + if (api64.FileExists()) { api64.DeleteFile(); installForm?.UpdateUser($"Deleted SmokeAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false); @@ -184,27 +184,27 @@ internal static class SmokeAPI } if (!deleteOthers) return; - if (old_config.FileExists(form: installForm)) + if (old_config.FileExists()) { old_config.DeleteFile(); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(old_config)}", LogTextBox.Action, false); } - if (config.FileExists(form: installForm)) + if (config.FileExists()) { config.DeleteFile(); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); } - if (cache.FileExists(form: installForm)) + if (cache.FileExists()) { cache.DeleteFile(); installForm?.UpdateUser($"Deleted cache: {Path.GetFileName(cache)}", LogTextBox.Action, false); } - if (old_log.FileExists(form: installForm)) + if (old_log.FileExists()) { old_log.DeleteFile(); installForm?.UpdateUser($"Deleted log: {Path.GetFileName(old_log)}", LogTextBox.Action, false); } - if (log.FileExists(form: installForm)) + if (log.FileExists()) { log.DeleteFile(); installForm?.UpdateUser($"Deleted log: {Path.GetFileName(log)}", LogTextBox.Action, false); @@ -215,28 +215,28 @@ internal static class SmokeAPI => await Task.Run(() => { directory.GetCreamApiComponents(out _, out _, out _, out _, out string oldConfig); - if (oldConfig.FileExists(form: installForm)) + if (oldConfig.FileExists()) { oldConfig.DeleteFile(); installForm?.UpdateUser($"Deleted old CreamAPI configuration: {Path.GetFileName(oldConfig)}", LogTextBox.Action, false); } directory.GetSmokeApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out _, out _, out _, out _, out _); - if (api32.FileExists(form: installForm) && !api32_o.FileExists(form: installForm)) + if (api32.FileExists() && !api32_o.FileExists()) { api32.MoveFile(api32_o!); installForm?.UpdateUser($"Renamed Steamworks: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false); } - if (api32_o.FileExists(form: installForm)) + if (api32_o.FileExists()) { "SmokeAPI.steam_api.dll".WriteManifestResource(api32); installForm?.UpdateUser($"Wrote SmokeAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false); } - if (api64.FileExists(form: installForm) && !api64_o.FileExists(form: installForm)) + if (api64.FileExists() && !api64_o.FileExists()) { api64.MoveFile(api64_o!); installForm?.UpdateUser($"Renamed Steamworks: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false); } - if (api64_o.FileExists(form: installForm)) + if (api64_o.FileExists()) { "SmokeAPI.steam_api64.dll".WriteManifestResource(api64); installForm?.UpdateUser($"Wrote SmokeAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false); diff --git a/CreamInstaller/Resources/UplayR1.cs b/CreamInstaller/Resources/UplayR1.cs index ab867dd..026a571 100644 --- a/CreamInstaller/Resources/UplayR1.cs +++ b/CreamInstaller/Resources/UplayR1.cs @@ -39,7 +39,7 @@ internal static class UplayR1 writer.Flush(); writer.Close(); } - else if (config.FileExists(form: installForm)) + else if (config.FileExists()) { config.DeleteFile(); installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); @@ -75,9 +75,9 @@ internal static class UplayR1 => await Task.Run(() => { directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log); - if (api32_o.FileExists(form: installForm)) + if (api32_o.FileExists()) { - if (api32.FileExists(form: installForm)) + if (api32.FileExists()) { api32.DeleteFile(); installForm?.UpdateUser($"Deleted Uplay R1 Unlocker: {Path.GetFileName(api32)}", LogTextBox.Action, false); @@ -85,9 +85,9 @@ internal static class UplayR1 api32_o.MoveFile(api32!); installForm?.UpdateUser($"Restored Uplay R1: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false); } - if (api64_o.FileExists(form: installForm)) + if (api64_o.FileExists()) { - if (api64.FileExists(form: installForm)) + if (api64.FileExists()) { api64.DeleteFile(); installForm?.UpdateUser($"Deleted Uplay R1 Unlocker: {Path.GetFileName(api64)}", LogTextBox.Action, false); @@ -97,12 +97,12 @@ internal static class UplayR1 } if (!deleteOthers) return; - if (config.FileExists(form: installForm)) + if (config.FileExists()) { config.DeleteFile(); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); } - if (log.FileExists(form: installForm)) + if (log.FileExists()) { log.DeleteFile(); installForm?.UpdateUser($"Deleted log: {Path.GetFileName(log)}", LogTextBox.Action, false); @@ -113,22 +113,22 @@ internal static class UplayR1 => await Task.Run(() => { directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out _, out _); - if (api32.FileExists(form: installForm) && !api32_o.FileExists(form: installForm)) + if (api32.FileExists() && !api32_o.FileExists()) { api32.MoveFile(api32_o!); installForm?.UpdateUser($"Renamed Uplay R1: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false); } - if (api32_o.FileExists(form: installForm)) + if (api32_o.FileExists()) { "UplayR1.uplay_r1_loader.dll".WriteManifestResource(api32); installForm?.UpdateUser($"Wrote Uplay R1 Unlocker: {Path.GetFileName(api32)}", LogTextBox.Action, false); } - if (api64.FileExists(form: installForm) && !api64_o.FileExists(form: installForm)) + if (api64.FileExists() && !api64_o.FileExists()) { api64.MoveFile(api64_o!); installForm?.UpdateUser($"Renamed Uplay R1: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false); } - if (api64_o.FileExists(form: installForm)) + if (api64_o.FileExists()) { "UplayR1.uplay_r1_loader64.dll".WriteManifestResource(api64); installForm?.UpdateUser($"Wrote Uplay R1 Unlocker: {Path.GetFileName(api64)}", LogTextBox.Action, false); diff --git a/CreamInstaller/Resources/UplayR2.cs b/CreamInstaller/Resources/UplayR2.cs index 649da2b..1099fd3 100644 --- a/CreamInstaller/Resources/UplayR2.cs +++ b/CreamInstaller/Resources/UplayR2.cs @@ -41,7 +41,7 @@ internal static class UplayR2 writer.Flush(); writer.Close(); } - else if (config.FileExists(form: installForm)) + else if (config.FileExists()) { config.DeleteFile(); installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); @@ -80,10 +80,10 @@ internal static class UplayR2 { directory.GetUplayR2Components(out string old_api32, out string old_api64, out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log); - if (api32_o.FileExists(form: installForm)) + if (api32_o.FileExists()) { - string api = old_api32.FileExists(form: installForm) ? old_api32 : api32; - if (api.FileExists(form: installForm)) + string api = old_api32.FileExists() ? old_api32 : api32; + if (api.FileExists()) { api.DeleteFile(); installForm?.UpdateUser($"Deleted Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false); @@ -91,10 +91,10 @@ internal static class UplayR2 api32_o.MoveFile(api!); installForm?.UpdateUser($"Restored Uplay R2: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api)}", LogTextBox.Action, false); } - if (api64_o.FileExists(form: installForm)) + if (api64_o.FileExists()) { - string api = old_api64.FileExists(form: installForm) ? old_api64 : api64; - if (api.FileExists(form: installForm)) + string api = old_api64.FileExists() ? old_api64 : api64; + if (api.FileExists()) { api.DeleteFile(); installForm?.UpdateUser($"Deleted Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false); @@ -104,12 +104,12 @@ internal static class UplayR2 } if (!deleteOthers) return; - if (config.FileExists(form: installForm)) + if (config.FileExists()) { config.DeleteFile(); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); } - if (log.FileExists(form: installForm)) + if (log.FileExists()) { log.DeleteFile(); installForm?.UpdateUser($"Deleted log: {Path.GetFileName(log)}", LogTextBox.Action, false); @@ -121,24 +121,24 @@ internal static class UplayR2 { directory.GetUplayR2Components(out string old_api32, out string old_api64, out string api32, out string api32_o, out string api64, out string api64_o, out _, out _); - string api = old_api32.FileExists(form: installForm) ? old_api32 : api32; - if (api.FileExists(form: installForm) && !api32_o.FileExists(form: installForm)) + string api = old_api32.FileExists() ? old_api32 : api32; + if (api.FileExists() && !api32_o.FileExists()) { api.MoveFile(api32_o!); installForm?.UpdateUser($"Renamed Uplay R2: {Path.GetFileName(api)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false); } - if (api32_o.FileExists(form: installForm)) + if (api32_o.FileExists()) { "UplayR2.upc_r2_loader.dll".WriteManifestResource(api); installForm?.UpdateUser($"Wrote Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false); } - api = old_api64.FileExists(form: installForm) ? old_api64 : api64; - if (api.FileExists(form: installForm) && !api64_o.FileExists(form: installForm)) + api = old_api64.FileExists() ? old_api64 : api64; + if (api.FileExists() && !api64_o.FileExists()) { api.MoveFile(api64_o!); installForm?.UpdateUser($"Renamed Uplay R2: {Path.GetFileName(api)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false); } - if (api64_o.FileExists(form: installForm)) + if (api64_o.FileExists()) { "UplayR2.upc_r2_loader64.dll".WriteManifestResource(api); installForm?.UpdateUser($"Wrote Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false); diff --git a/CreamInstaller/Utility/NativeImports.cs b/CreamInstaller/Utility/NativeImports.cs new file mode 100644 index 0000000..168b0b4 --- /dev/null +++ b/CreamInstaller/Utility/NativeImports.cs @@ -0,0 +1,11 @@ +using System.Runtime.InteropServices; +using static CreamInstaller.Resources.Resources; + +namespace CreamInstaller.Utility; + +internal static partial class NativeImports +{ + [LibraryImport("kernel32.dll", SetLastError = true), DefaultDllImportSearchPaths(DllImportSearchPath.System32)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static partial bool GetBinaryType([MarshalAs(UnmanagedType.LPStr)] string lpApplicationName, out BinaryType lpBinaryType); +} \ No newline at end of file diff --git a/CreamInstaller/Utility/ProgramData.cs b/CreamInstaller/Utility/ProgramData.cs index 2578a0b..65f8add 100644 --- a/CreamInstaller/Utility/ProgramData.cs +++ b/CreamInstaller/Utility/ProgramData.cs @@ -35,15 +35,14 @@ internal static class ProgramData DirectoryPathOld.MoveDirectory(DirectoryPath, true, form); } DirectoryPath.CreateDirectory(); - if (!AppInfoVersionPath.FileExists(form: form) || !Version.TryParse(AppInfoVersionPath.ReadFile(), out Version version) - || version < MinimumAppInfoVersion) + if (!AppInfoVersionPath.FileExists() || !Version.TryParse(AppInfoVersionPath.ReadFile(), out Version version) || version < MinimumAppInfoVersion) { AppInfoPath.DeleteDirectory(); AppInfoPath.CreateDirectory(); AppInfoVersionPath.WriteFile(Program.Version); } CooldownPath.CreateDirectory(); - if (OldProgramChoicesPath.FileExists(form: form)) + if (OldProgramChoicesPath.FileExists()) OldProgramChoicesPath.DeleteFile(); }); diff --git a/CreamInstaller/Utility/SafeIO.cs b/CreamInstaller/Utility/SafeIO.cs index 8fa811b..4712866 100644 --- a/CreamInstaller/Utility/SafeIO.cs +++ b/CreamInstaller/Utility/SafeIO.cs @@ -26,16 +26,7 @@ internal static class SafeIO return false; } - internal static bool DirectoryExists(this string directoryPath, bool crucial = false, Form form = null) - { - while (!Program.Canceled) - { - bool exists = Directory.Exists(directoryPath); - if (exists || !crucial || directoryPath.IOWarn("Failed to find a crucial directory", form) is not DialogResult.OK) - return exists; - } - return false; - } + internal static bool DirectoryExists(this string directoryPath) => Directory.Exists(directoryPath); internal static void CreateDirectory(this string directoryPath, bool crucial = false, Form form = null) { @@ -49,13 +40,15 @@ internal static class SafeIO } catch { - if (!crucial || directoryPath.IOWarn("Failed to create a crucial directory", form) is not DialogResult.OK) + if (!crucial || directoryPath.DirectoryExists() || directoryPath.IOWarn("Failed to create a crucial directory", form) is not DialogResult.OK) break; } } internal static void MoveDirectory(this string directoryPath, string newDirectoryPath, bool crucial = false, Form form = null) { + if (!directoryPath.DirectoryExists()) + return; while (!Program.Canceled) try { @@ -64,7 +57,7 @@ internal static class SafeIO } catch { - if (!crucial || directoryPath.IOWarn("Failed to move a crucial directory", form) is not DialogResult.OK) + if (!crucial || !directoryPath.DirectoryExists() || directoryPath.IOWarn("Failed to move a crucial directory", form) is not DialogResult.OK) break; } } @@ -81,7 +74,7 @@ internal static class SafeIO } catch { - if (!crucial || directoryPath.IOWarn("Failed to delete a crucial directory", form) is not DialogResult.OK) + if (!crucial || !directoryPath.DirectoryExists() || directoryPath.IOWarn("Failed to delete a crucial directory", form) is not DialogResult.OK) break; } } @@ -89,6 +82,8 @@ internal static class SafeIO internal static IEnumerable EnumerateDirectory(this string directoryPath, string filePattern, bool subdirectories = false, bool crucial = false, Form form = null) { + if (!directoryPath.DirectoryExists()) + return Enumerable.Empty(); while (!Program.Canceled) try { @@ -98,7 +93,8 @@ internal static class SafeIO } catch { - if (!crucial || directoryPath.IOWarn("Failed to enumerate a crucial directory's files", form) is not DialogResult.OK) + if (!crucial || !directoryPath.DirectoryExists() + || directoryPath.IOWarn("Failed to enumerate a crucial directory's files", form) is not DialogResult.OK) break; } return Enumerable.Empty(); @@ -107,6 +103,8 @@ internal static class SafeIO internal static IEnumerable EnumerateSubdirectories(this string directoryPath, string directoryPattern, bool subdirectories = false, bool crucial = false, Form form = null) { + if (!directoryPath.DirectoryExists()) + return Enumerable.Empty(); while (!Program.Canceled) try { @@ -116,22 +114,14 @@ internal static class SafeIO } catch { - if (!crucial || directoryPath.IOWarn("Failed to enumerate a crucial directory's subdirectories", form) is not DialogResult.OK) + if (!crucial || !directoryPath.DirectoryExists() + || directoryPath.IOWarn("Failed to enumerate a crucial directory's subdirectories", form) is not DialogResult.OK) break; } return Enumerable.Empty(); } - internal static bool FileExists(this string filePath, bool crucial = false, Form form = null) - { - while (!Program.Canceled) - { - bool exists = File.Exists(filePath); - if (exists || !crucial || filePath.IOWarn("Failed to find a crucial file", form) is not DialogResult.OK) - return exists; - } - return false; - } + internal static bool FileExists(this string filePath) => File.Exists(filePath); internal static void CreateFile(this string filePath, bool crucial = false, Form form = null) { @@ -150,6 +140,8 @@ internal static class SafeIO internal static void MoveFile(this string filePath, string newFilePath, bool crucial = false, Form form = null) { + if (!filePath.FileExists()) + return; while (!Program.Canceled) try { @@ -158,14 +150,14 @@ internal static class SafeIO } catch { - if (!crucial || !filePath.FileExists(true) || filePath.IOWarn("Failed to move a crucial file", form) is not DialogResult.OK) + if (!crucial || !filePath.FileExists() || filePath.IOWarn("Failed to move a crucial file", form) is not DialogResult.OK) break; } } internal static void DeleteFile(this string filePath, bool crucial = false, Form form = null) { - if (!filePath.FileExists(form: form)) + if (!filePath.FileExists()) return; while (!Program.Canceled) try @@ -175,13 +167,15 @@ internal static class SafeIO } catch { - if (!crucial || filePath.IOWarn("Failed to delete a crucial file", form) is not DialogResult.OK) + if (!crucial || !filePath.FileExists() || filePath.IOWarn("Failed to delete a crucial file", form) is not DialogResult.OK) break; } } internal static string ReadFile(this string filePath, bool crucial = false, Form form = null) { + if (!filePath.FileExists()) + return null; while (!Program.Canceled) try { @@ -189,7 +183,7 @@ internal static class SafeIO } catch { - if (!crucial || !filePath.FileExists(true) || filePath.IOWarn("Failed to read a crucial file", form) is not DialogResult.OK) + if (!crucial || !filePath.FileExists() || filePath.IOWarn("Failed to read a crucial file", form) is not DialogResult.OK) break; } return null; @@ -197,6 +191,8 @@ internal static class SafeIO internal static byte[] ReadFileBytes(this string filePath, bool crucial = false, Form form = null) { + if (!filePath.FileExists()) + return null; while (!Program.Canceled) try { @@ -204,7 +200,7 @@ internal static class SafeIO } catch { - if (!crucial || !filePath.FileExists(true) || filePath.IOWarn("Failed to read a crucial file", form) is not DialogResult.OK) + if (!crucial || !filePath.FileExists() || filePath.IOWarn("Failed to read a crucial file", form) is not DialogResult.OK) break; } return null; @@ -227,6 +223,8 @@ internal static class SafeIO internal static void ExtractZip(this string archivePath, string destinationPath, bool crucial = false, Form form = null) { + if (!archivePath.FileExists()) + return; while (!Program.Canceled) try { @@ -235,7 +233,7 @@ internal static class SafeIO } catch { - if (!crucial || archivePath.IOWarn("Failed to extract a crucial zip file", form) is not DialogResult.OK) + if (!crucial || !archivePath.FileExists() || archivePath.IOWarn("Failed to extract a crucial zip file", form) is not DialogResult.OK) break; } } diff --git a/preview.png b/preview.png index cd9e9b9..4d45881 100644 Binary files a/preview.png and b/preview.png differ