From 094cd7ea8d8d6ae5d472efd29f445a62eabc5a65 Mon Sep 17 00:00:00 2001 From: pointfeev Date: Wed, 9 Mar 2022 09:50:20 -0500 Subject: [PATCH] minor code cleanup & refactor --- CreamInstaller/CreamInstaller.csproj | 4 +- .../{ => Forms}/DialogForm.Designer.cs | 0 CreamInstaller/{ => Forms}/DialogForm.cs | 0 CreamInstaller/{ => Forms}/DialogForm.resx | 0 .../{ => Forms}/InstallForm.Designer.cs | 0 CreamInstaller/{ => Forms}/InstallForm.cs | 0 CreamInstaller/{ => Forms}/InstallForm.resx | 0 .../{ => Forms}/MainForm.Designer.cs | 0 CreamInstaller/{ => Forms}/MainForm.cs | 0 CreamInstaller/{ => Forms}/MainForm.resx | 0 .../{ => Forms}/SelectForm.Designer.cs | 0 CreamInstaller/{ => Forms}/SelectForm.cs | 79 +----------------- CreamInstaller/{ => Forms}/SelectForm.resx | 0 CreamInstaller/Paradox/ParadoxLauncher.cs | 83 +++++++++++++++++++ 14 files changed, 86 insertions(+), 80 deletions(-) rename CreamInstaller/{ => Forms}/DialogForm.Designer.cs (100%) rename CreamInstaller/{ => Forms}/DialogForm.cs (100%) rename CreamInstaller/{ => Forms}/DialogForm.resx (100%) rename CreamInstaller/{ => Forms}/InstallForm.Designer.cs (100%) rename CreamInstaller/{ => Forms}/InstallForm.cs (100%) rename CreamInstaller/{ => Forms}/InstallForm.resx (100%) rename CreamInstaller/{ => Forms}/MainForm.Designer.cs (100%) rename CreamInstaller/{ => Forms}/MainForm.cs (100%) rename CreamInstaller/{ => Forms}/MainForm.resx (100%) rename CreamInstaller/{ => Forms}/SelectForm.Designer.cs (100%) rename CreamInstaller/{ => Forms}/SelectForm.cs (85%) rename CreamInstaller/{ => Forms}/SelectForm.resx (100%) diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index b7796ba..da9cca2 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -42,8 +42,8 @@ - - + + True True diff --git a/CreamInstaller/DialogForm.Designer.cs b/CreamInstaller/Forms/DialogForm.Designer.cs similarity index 100% rename from CreamInstaller/DialogForm.Designer.cs rename to CreamInstaller/Forms/DialogForm.Designer.cs diff --git a/CreamInstaller/DialogForm.cs b/CreamInstaller/Forms/DialogForm.cs similarity index 100% rename from CreamInstaller/DialogForm.cs rename to CreamInstaller/Forms/DialogForm.cs diff --git a/CreamInstaller/DialogForm.resx b/CreamInstaller/Forms/DialogForm.resx similarity index 100% rename from CreamInstaller/DialogForm.resx rename to CreamInstaller/Forms/DialogForm.resx diff --git a/CreamInstaller/InstallForm.Designer.cs b/CreamInstaller/Forms/InstallForm.Designer.cs similarity index 100% rename from CreamInstaller/InstallForm.Designer.cs rename to CreamInstaller/Forms/InstallForm.Designer.cs diff --git a/CreamInstaller/InstallForm.cs b/CreamInstaller/Forms/InstallForm.cs similarity index 100% rename from CreamInstaller/InstallForm.cs rename to CreamInstaller/Forms/InstallForm.cs diff --git a/CreamInstaller/InstallForm.resx b/CreamInstaller/Forms/InstallForm.resx similarity index 100% rename from CreamInstaller/InstallForm.resx rename to CreamInstaller/Forms/InstallForm.resx diff --git a/CreamInstaller/MainForm.Designer.cs b/CreamInstaller/Forms/MainForm.Designer.cs similarity index 100% rename from CreamInstaller/MainForm.Designer.cs rename to CreamInstaller/Forms/MainForm.Designer.cs diff --git a/CreamInstaller/MainForm.cs b/CreamInstaller/Forms/MainForm.cs similarity index 100% rename from CreamInstaller/MainForm.cs rename to CreamInstaller/Forms/MainForm.cs diff --git a/CreamInstaller/MainForm.resx b/CreamInstaller/Forms/MainForm.resx similarity index 100% rename from CreamInstaller/MainForm.resx rename to CreamInstaller/Forms/MainForm.resx diff --git a/CreamInstaller/SelectForm.Designer.cs b/CreamInstaller/Forms/SelectForm.Designer.cs similarity index 100% rename from CreamInstaller/SelectForm.Designer.cs rename to CreamInstaller/Forms/SelectForm.Designer.cs diff --git a/CreamInstaller/SelectForm.cs b/CreamInstaller/Forms/SelectForm.cs similarity index 85% rename from CreamInstaller/SelectForm.cs rename to CreamInstaller/Forms/SelectForm.cs index 326d332..f06961c 100644 --- a/CreamInstaller/SelectForm.cs +++ b/CreamInstaller/Forms/SelectForm.cs @@ -12,7 +12,6 @@ using System.Windows.Forms; using CreamInstaller.Components; using CreamInstaller.Epic; using CreamInstaller.Paradox; -using CreamInstaller.Resources; using CreamInstaller.Steam; using CreamInstaller.Utility; @@ -608,83 +607,7 @@ internal partial class SelectForm : CustomForm { contextMenuStrip.Items.Add(new ToolStripSeparator()); contextMenuStrip.Items.Add(new ContextMenuItem("Repair", "Command Prompt", - new EventHandler(async (sender, e) => - { - if (!Program.IsProgramRunningDialog(this, selection)) return; - byte[] creamConfig = null; - byte[] steamOriginalSdk32 = null; - byte[] steamOriginalSdk64 = null; - byte[] screamConfig = null; - byte[] epicOriginalSdk32 = null; - byte[] epicOriginalSdk64 = null; - foreach (string directory in selection.DllDirectories) - { - directory.GetCreamApiComponents(out string sdk32, out string _, out string sdk64, out string _, out string config); - if (creamConfig is null && File.Exists(config)) - creamConfig = File.ReadAllBytes(config); - await InstallForm.UninstallCreamAPI(directory); - if (steamOriginalSdk32 is null && File.Exists(sdk32) && !Properties.Resources.Steamworks32.EqualsFile(sdk32)) - steamOriginalSdk32 = File.ReadAllBytes(sdk32); - if (steamOriginalSdk64 is null && File.Exists(sdk64) && !Properties.Resources.Steamworks64.EqualsFile(sdk64)) - steamOriginalSdk64 = File.ReadAllBytes(sdk64); - directory.GetScreamApiComponents(out sdk32, out string _, out sdk64, out string _, out config); - if (screamConfig is null && File.Exists(config)) - screamConfig = File.ReadAllBytes(config); - await InstallForm.UninstallScreamAPI(directory); - if (epicOriginalSdk32 is null && File.Exists(sdk32) && !Properties.Resources.EpicOnlineServices32.EqualsFile(sdk32)) - epicOriginalSdk32 = File.ReadAllBytes(sdk32); - if (epicOriginalSdk64 is null && File.Exists(sdk64) && !Properties.Resources.EpicOnlineServices64.EqualsFile(sdk64)) - epicOriginalSdk64 = File.ReadAllBytes(sdk64); - } - if (steamOriginalSdk32 is not null || steamOriginalSdk64 is not null || epicOriginalSdk32 is not null || epicOriginalSdk64 is not null) - { - bool neededRepair = false; - foreach (string directory in selection.DllDirectories) - { - directory.GetCreamApiComponents(out string sdk32, out string _, out string sdk64, out string _, out string config); - if (steamOriginalSdk32 is not null && Properties.Resources.Steamworks32.EqualsFile(sdk32)) - { - steamOriginalSdk32.Write(sdk32); - neededRepair = true; - } - if (steamOriginalSdk64 is not null && Properties.Resources.Steamworks64.EqualsFile(sdk64)) - { - steamOriginalSdk64.Write(sdk64); - neededRepair = true; - } - if (creamConfig is not null) - { - await InstallForm.InstallCreamAPI(directory, selection); - creamConfig.Write(config); - } - - directory.GetScreamApiComponents(out sdk32, out string _, out sdk64, out string _, out config); - if (epicOriginalSdk32 is not null && Properties.Resources.EpicOnlineServices32.EqualsFile(sdk32)) - { - epicOriginalSdk32.Write(sdk32); - neededRepair = true; - } - if (epicOriginalSdk64 is not null && Properties.Resources.EpicOnlineServices64.EqualsFile(sdk64)) - { - epicOriginalSdk64.Write(sdk64); - neededRepair = true; - } - if (screamConfig is not null) - { - await InstallForm.InstallScreamAPI(directory, selection); - screamConfig.Write(config); - } - } - if (neededRepair) - new DialogForm(this).Show(Icon, "Paradox Launcher successfully repaired!", "OK"); - else - new DialogForm(this).Show(SystemIcons.Information, "Paradox Launcher does not need to be repaired.", "OK"); - } - else - new DialogForm(this).Show(SystemIcons.Error, "Paradox Launcher repair failed!" - + "\n\nAn original Steamworks/Epic Online Services SDK file could not be found." - + "\nYou must reinstall Paradox Launcher to fix this issue.", "OK"); - }))); + new EventHandler(async (sender, e) => await ParadoxLauncher.Repair(this, selection)))); } contextMenuStrip.Items.Add(new ToolStripSeparator()); contextMenuStrip.Items.Add(new ContextMenuItem("Open Root Directory", "File Explorer", diff --git a/CreamInstaller/SelectForm.resx b/CreamInstaller/Forms/SelectForm.resx similarity index 100% rename from CreamInstaller/SelectForm.resx rename to CreamInstaller/Forms/SelectForm.resx diff --git a/CreamInstaller/Paradox/ParadoxLauncher.cs b/CreamInstaller/Paradox/ParadoxLauncher.cs index 1862918..316eecd 100644 --- a/CreamInstaller/Paradox/ParadoxLauncher.cs +++ b/CreamInstaller/Paradox/ParadoxLauncher.cs @@ -1,7 +1,11 @@ using System.Drawing; +using System.IO; using System.Linq; +using System.Threading.Tasks; using System.Windows.Forms; +using CreamInstaller.Resources; + using Microsoft.Win32; namespace CreamInstaller.Paradox; @@ -56,4 +60,83 @@ internal static class ParadoxLauncher } return false; } + + internal static async Task Repair(Form form, ProgramSelection selection) + { + if (!Program.IsProgramRunningDialog(form, selection)) return; + byte[] creamConfig = null; + byte[] steamOriginalSdk32 = null; + byte[] steamOriginalSdk64 = null; + byte[] screamConfig = null; + byte[] epicOriginalSdk32 = null; + byte[] epicOriginalSdk64 = null; + foreach (string directory in selection.DllDirectories) + { + directory.GetCreamApiComponents(out string sdk32, out string _, out string sdk64, out string _, out string config); + if (creamConfig is null && File.Exists(config)) + creamConfig = File.ReadAllBytes(config); + await InstallForm.UninstallCreamAPI(directory); + if (steamOriginalSdk32 is null && File.Exists(sdk32) && !Properties.Resources.Steamworks32.EqualsFile(sdk32)) + steamOriginalSdk32 = File.ReadAllBytes(sdk32); + if (steamOriginalSdk64 is null && File.Exists(sdk64) && !Properties.Resources.Steamworks64.EqualsFile(sdk64)) + steamOriginalSdk64 = File.ReadAllBytes(sdk64); + directory.GetScreamApiComponents(out sdk32, out string _, out sdk64, out string _, out config); + if (screamConfig is null && File.Exists(config)) + screamConfig = File.ReadAllBytes(config); + await InstallForm.UninstallScreamAPI(directory); + if (epicOriginalSdk32 is null && File.Exists(sdk32) && !Properties.Resources.EpicOnlineServices32.EqualsFile(sdk32)) + epicOriginalSdk32 = File.ReadAllBytes(sdk32); + if (epicOriginalSdk64 is null && File.Exists(sdk64) && !Properties.Resources.EpicOnlineServices64.EqualsFile(sdk64)) + epicOriginalSdk64 = File.ReadAllBytes(sdk64); + } + using DialogForm dialogForm = new(form); + if (steamOriginalSdk32 is not null || steamOriginalSdk64 is not null || epicOriginalSdk32 is not null || epicOriginalSdk64 is not null) + { + bool neededRepair = false; + foreach (string directory in selection.DllDirectories) + { + directory.GetCreamApiComponents(out string sdk32, out string _, out string sdk64, out string _, out string config); + if (steamOriginalSdk32 is not null && Properties.Resources.Steamworks32.EqualsFile(sdk32)) + { + steamOriginalSdk32.Write(sdk32); + neededRepair = true; + } + if (steamOriginalSdk64 is not null && Properties.Resources.Steamworks64.EqualsFile(sdk64)) + { + steamOriginalSdk64.Write(sdk64); + neededRepair = true; + } + if (creamConfig is not null) + { + await InstallForm.InstallCreamAPI(directory, selection); + creamConfig.Write(config); + } + + directory.GetScreamApiComponents(out sdk32, out string _, out sdk64, out string _, out config); + if (epicOriginalSdk32 is not null && Properties.Resources.EpicOnlineServices32.EqualsFile(sdk32)) + { + epicOriginalSdk32.Write(sdk32); + neededRepair = true; + } + if (epicOriginalSdk64 is not null && Properties.Resources.EpicOnlineServices64.EqualsFile(sdk64)) + { + epicOriginalSdk64.Write(sdk64); + neededRepair = true; + } + if (screamConfig is not null) + { + await InstallForm.InstallScreamAPI(directory, selection); + screamConfig.Write(config); + } + } + if (neededRepair) + dialogForm.Show(form.Icon, "Paradox Launcher successfully repaired!", "OK"); + else + dialogForm.Show(SystemIcons.Information, "Paradox Launcher does not need to be repaired.", "OK"); + } + else + dialogForm.Show(SystemIcons.Error, "Paradox Launcher repair failed!" + + "\n\nAn original Steamworks/Epic Online Services SDK file could not be found." + + "\nYou must reinstall Paradox Launcher to fix this issue.", "OK"); + } }