minor code cleanup & refactor

This commit is contained in:
pointfeev 2022-03-09 09:50:20 -05:00
parent e1a5a23e9c
commit 094cd7ea8d
14 changed files with 86 additions and 80 deletions

View file

@ -42,8 +42,8 @@
<PackageReference Include="Onova" Version="2.6.2" />
</ItemGroup>
<ItemGroup>
<Compile Update="MainForm.cs" />
<Compile Update="SelectForm.cs" />
<Compile Update="Forms\MainForm.cs" />
<Compile Update="Forms\SelectForm.cs" />
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>

View file

@ -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",

View file

@ -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");
}
}