v4.6.0.0 (not finished)

- Fixed all (or at least almost all) potential IOExceptions
- Added a minimum & maximum height and width, as well as scroll bars, to dialog boxes
This commit is contained in:
pointfeev 2023-01-29 19:53:21 -05:00
parent 7ae160c610
commit 2253cf973a
23 changed files with 430 additions and 334 deletions

View file

@ -86,8 +86,7 @@ internal class CustomForm : Form
private void OnActivation(object sender, EventArgs args) => Activate(); private void OnActivation(object sender, EventArgs args) => Activate();
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode), DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
private static extern void SetWindowPos(nint hWnd, nint hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags); private static extern void SetWindowPos(nint hWnd, nint hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
internal void BringToFrontWithoutActivation() internal void BringToFrontWithoutActivation()

View file

@ -1,12 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.IO;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using System.Windows.Forms.VisualStyles; using System.Windows.Forms.VisualStyles;
using CreamInstaller.Forms; using CreamInstaller.Forms;
using CreamInstaller.Resources; using CreamInstaller.Resources;
using CreamInstaller.Utility;
using static CreamInstaller.Resources.Resources; using static CreamInstaller.Resources.Resources;
namespace CreamInstaller.Components; namespace CreamInstaller.Components;
@ -209,7 +209,7 @@ internal sealed class CustomTreeView : TreeView
foreach ((string directory, BinaryType _) in pair.Key.ExecutableDirectories) foreach ((string directory, BinaryType _) in pair.Key.ExecutableDirectories)
{ {
string path = directory + @"\" + proxy + ".dll"; string path = directory + @"\" + proxy + ".dll";
if (!File.Exists(path) || path.IsResourceFile(ResourceIdentifier.Koaloader)) if (!path.Exists(form: form) || path.IsResourceFile(ResourceIdentifier.Koaloader))
continue; continue;
canUse = false; canUse = false;
break; break;

View file

@ -4,7 +4,7 @@
<TargetFramework>net7.0-windows</TargetFramework> <TargetFramework>net7.0-windows</TargetFramework>
<UseWindowsForms>True</UseWindowsForms> <UseWindowsForms>True</UseWindowsForms>
<ApplicationIcon>Resources\ini.ico</ApplicationIcon> <ApplicationIcon>Resources\ini.ico</ApplicationIcon>
<Version>4.5.0.0</Version> <Version>4.6.0.0</Version>
<Copyright>2021, pointfeev (https://github.com/pointfeev)</Copyright> <Copyright>2021, pointfeev (https://github.com/pointfeev)</Copyright>
<Company>CreamInstaller</Company> <Company>CreamInstaller</Company>
<Product>Automatic DLC Unlocker Installer &amp; Configuration Generator</Product> <Product>Automatic DLC Unlocker Installer &amp; Configuration Generator</Product>

View file

@ -39,7 +39,7 @@ namespace CreamInstaller.Forms
this.cancelButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.cancelButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.FlatStyle = System.Windows.Forms.FlatStyle.System; this.cancelButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.cancelButton.Location = new System.Drawing.Point(32, 9); this.cancelButton.Location = new System.Drawing.Point(132, 9);
this.cancelButton.Name = "cancelButton"; this.cancelButton.Name = "cancelButton";
this.cancelButton.Padding = new System.Windows.Forms.Padding(12, 0, 12, 0); this.cancelButton.Padding = new System.Windows.Forms.Padding(12, 0, 12, 0);
this.cancelButton.Size = new System.Drawing.Size(115, 24); this.cancelButton.Size = new System.Drawing.Size(115, 24);
@ -54,7 +54,7 @@ namespace CreamInstaller.Forms
this.acceptButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.acceptButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.acceptButton.DialogResult = System.Windows.Forms.DialogResult.OK; this.acceptButton.DialogResult = System.Windows.Forms.DialogResult.OK;
this.acceptButton.FlatStyle = System.Windows.Forms.FlatStyle.System; this.acceptButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.acceptButton.Location = new System.Drawing.Point(153, 9); this.acceptButton.Location = new System.Drawing.Point(253, 9);
this.acceptButton.Name = "acceptButton"; this.acceptButton.Name = "acceptButton";
this.acceptButton.Padding = new System.Windows.Forms.Padding(12, 0, 12, 0); this.acceptButton.Padding = new System.Windows.Forms.Padding(12, 0, 12, 0);
this.acceptButton.Size = new System.Drawing.Size(116, 24); this.acceptButton.Size = new System.Drawing.Size(116, 24);
@ -85,16 +85,18 @@ namespace CreamInstaller.Forms
// //
// descriptionPanel // descriptionPanel
// //
this.descriptionPanel.AutoScroll = true;
this.descriptionPanel.AutoSize = true; this.descriptionPanel.AutoSize = true;
this.descriptionPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.descriptionPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.descriptionPanel.Controls.Add(this.icon); this.descriptionPanel.Controls.Add(this.icon);
this.descriptionPanel.Controls.Add(this.descriptionLabel); this.descriptionPanel.Controls.Add(this.descriptionLabel);
this.descriptionPanel.Dock = System.Windows.Forms.DockStyle.Fill; this.descriptionPanel.Dock = System.Windows.Forms.DockStyle.Fill;
this.descriptionPanel.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
this.descriptionPanel.Location = new System.Drawing.Point(0, 0); this.descriptionPanel.Location = new System.Drawing.Point(0, 0);
this.descriptionPanel.Margin = new System.Windows.Forms.Padding(0); this.descriptionPanel.Margin = new System.Windows.Forms.Padding(0);
this.descriptionPanel.Name = "descriptionPanel"; this.descriptionPanel.Name = "descriptionPanel";
this.descriptionPanel.Padding = new System.Windows.Forms.Padding(12, 12, 12, 6); this.descriptionPanel.Padding = new System.Windows.Forms.Padding(12, 12, 12, 6);
this.descriptionPanel.Size = new System.Drawing.Size(284, 73); this.descriptionPanel.Size = new System.Drawing.Size(384, 73);
this.descriptionPanel.TabIndex = 5; this.descriptionPanel.TabIndex = 5;
// //
// buttonPanel // buttonPanel
@ -108,7 +110,7 @@ namespace CreamInstaller.Forms
this.buttonPanel.Location = new System.Drawing.Point(0, 73); this.buttonPanel.Location = new System.Drawing.Point(0, 73);
this.buttonPanel.Name = "buttonPanel"; this.buttonPanel.Name = "buttonPanel";
this.buttonPanel.Padding = new System.Windows.Forms.Padding(12, 6, 0, 12); this.buttonPanel.Padding = new System.Windows.Forms.Padding(12, 6, 0, 12);
this.buttonPanel.Size = new System.Drawing.Size(284, 48); this.buttonPanel.Size = new System.Drawing.Size(384, 48);
this.buttonPanel.TabIndex = 6; this.buttonPanel.TabIndex = 6;
// //
// DialogForm // DialogForm
@ -119,12 +121,14 @@ namespace CreamInstaller.Forms
this.AutoSize = true; this.AutoSize = true;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.CancelButton = this.cancelButton; this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(284, 121); this.ClientSize = new System.Drawing.Size(384, 121);
this.Controls.Add(this.descriptionPanel); this.Controls.Add(this.descriptionPanel);
this.Controls.Add(this.buttonPanel); this.Controls.Add(this.buttonPanel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false; this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(1600, 900);
this.MinimizeBox = false; this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(400, 160);
this.Name = "DialogForm"; this.Name = "DialogForm";
this.ShowInTaskbar = false; this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;

View file

@ -70,8 +70,7 @@ internal sealed partial class InstallForm : CustomForm
$"{(uninstalling ? "Uninstalling" : "Installing")}" + $" {(uninstalling ? "from" : "for")} " + selection.Name $"{(uninstalling ? "Uninstalling" : "Installing")}" + $" {(uninstalling ? "from" : "for")} " + selection.Name
+ $" with root directory \"{selection.RootDirectory}\" . . . ", LogTextBox.Operation); + $" with root directory \"{selection.RootDirectory}\" . . . ", LogTextBox.Operation);
IEnumerable<string> invalidDirectories = (await selection.RootDirectory.GetExecutables()) IEnumerable<string> invalidDirectories = (await selection.RootDirectory.GetExecutables())
?.Where(d => selection.ExecutableDirectories.All(s => s.directory != Path.GetDirectoryName(d.path))) ?.Where(d => selection.ExecutableDirectories.All(s => s.directory != Path.GetDirectoryName(d.path))).Select(d => Path.GetDirectoryName(d.path));
.Select(d => Path.GetDirectoryName(d.path));
if (selection.ExecutableDirectories.All(s => s.directory != selection.RootDirectory)) if (selection.ExecutableDirectories.All(s => s.directory != selection.RootDirectory))
invalidDirectories = invalidDirectories?.Append(selection.RootDirectory); invalidDirectories = invalidDirectories?.Append(selection.RootDirectory);
invalidDirectories = invalidDirectories?.Distinct(); invalidDirectories = invalidDirectories?.Distinct();
@ -81,9 +80,9 @@ internal sealed partial class InstallForm : CustomForm
if (Program.Canceled) if (Program.Canceled)
throw new CustomMessageException("The operation was canceled."); throw new CustomMessageException("The operation was canceled.");
directory.GetKoaloaderComponents(out string old_config, out string config); directory.GetKoaloaderComponents(out string old_config, out string config);
if (directory.GetKoaloaderProxies().Any(proxy => File.Exists(proxy) && proxy.IsResourceFile(ResourceIdentifier.Koaloader)) if (directory.GetKoaloaderProxies().Any(proxy => proxy.Exists(form: this) && proxy.IsResourceFile(ResourceIdentifier.Koaloader))
|| directory != selection.RootDirectory && Koaloader.AutoLoadDLLs.Any(pair => File.Exists(directory + @"\" + pair.dll)) || directory != selection.RootDirectory && Koaloader.AutoLoadDLLs.Any(pair => (directory + @"\" + pair.dll).Exists(form: this))
|| File.Exists(old_config) || File.Exists(config)) || old_config.Exists(form: this) || config.Exists(form: this))
{ {
UpdateUser("Uninstalling Koaloader from " + selection.Name + $" in incorrect directory \"{directory}\" . . . ", LogTextBox.Operation); UpdateUser("Uninstalling Koaloader from " + selection.Name + $" in incorrect directory \"{directory}\" . . . ", LogTextBox.Operation);
await Koaloader.Uninstall(directory, selection.RootDirectory, this); await Koaloader.Uninstall(directory, selection.RootDirectory, this);
@ -96,8 +95,9 @@ internal sealed partial class InstallForm : CustomForm
if (Program.Canceled) if (Program.Canceled)
throw new CustomMessageException("The operation was canceled."); throw new CustomMessageException("The operation was canceled.");
directory.GetKoaloaderComponents(out string old_config, out string config); directory.GetKoaloaderComponents(out string old_config, out string config);
if (directory.GetKoaloaderProxies().Any(proxy => File.Exists(proxy) && proxy.IsResourceFile(ResourceIdentifier.Koaloader)) if (directory.GetKoaloaderProxies().Any(proxy => proxy.Exists(form: this) && proxy.IsResourceFile(ResourceIdentifier.Koaloader))
|| Koaloader.AutoLoadDLLs.Any(pair => File.Exists(directory + @"\" + pair.dll)) || File.Exists(old_config) || File.Exists(config)) || Koaloader.AutoLoadDLLs.Any(pair => (directory + @"\" + pair.dll).Exists(form: this)) || old_config.Exists(form: this)
|| config.Exists(form: this))
{ {
UpdateUser("Uninstalling Koaloader from " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation); UpdateUser("Uninstalling Koaloader from " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation);
await Koaloader.Uninstall(directory, selection.RootDirectory, this); await Koaloader.Uninstall(directory, selection.RootDirectory, this);
@ -115,9 +115,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, 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); out string config, out string old_log, out string log, out string cache);
if (uninstallProxy if (uninstallProxy
? File.Exists(api32_o) || File.Exists(api64_o) || File.Exists(old_config) || File.Exists(config) || File.Exists(old_log) ? api32_o.Exists(form: this) || api64_o.Exists(form: this) || old_config.Exists(form: this) || config.Exists(form: this)
|| File.Exists(log) || File.Exists(cache) || old_log.Exists(form: this) || log.Exists(form: this) || cache.Exists(form: this)
: File.Exists(api32) || File.Exists(api64)) : api32.Exists(form: this) || api64.Exists(form: this))
{ {
UpdateUser( UpdateUser(
$"{(uninstallProxy ? "Uninstalling" : "Installing")} SmokeAPI" + $" {(uninstallProxy ? "from" : "for")} " + selection.Name $"{(uninstallProxy ? "Uninstalling" : "Installing")} SmokeAPI" + $" {(uninstallProxy ? "from" : "for")} " + selection.Name
@ -132,8 +132,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); directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log);
if (uninstallProxy if (uninstallProxy
? File.Exists(api32_o) || File.Exists(api64_o) || File.Exists(config) || File.Exists(log) ? api32_o.Exists(form: this) || api64_o.Exists(form: this) || config.Exists(form: this) || log.Exists(form: this)
: File.Exists(api32) || File.Exists(api64)) : api32.Exists(form: this) || api64.Exists(form: this))
{ {
UpdateUser( UpdateUser(
$"{(uninstallProxy ? "Uninstalling" : "Installing")} ScreamAPI" + $" {(uninstallProxy ? "from" : "for")} " + selection.Name $"{(uninstallProxy ? "Uninstalling" : "Installing")} ScreamAPI" + $" {(uninstallProxy ? "from" : "for")} " + selection.Name
@ -148,8 +148,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); directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log);
if (uninstallProxy if (uninstallProxy
? File.Exists(api32_o) || File.Exists(api64_o) || File.Exists(config) || File.Exists(log) ? api32_o.Exists(form: this) || api64_o.Exists(form: this) || config.Exists(form: this) || log.Exists(form: this)
: File.Exists(api32) || File.Exists(api64)) : api32.Exists(form: this) || api64.Exists(form: this))
{ {
UpdateUser( UpdateUser(
$"{(uninstallProxy ? "Uninstalling" : "Installing")} Uplay R1 Unlocker" + $" {(uninstallProxy ? "from" : "for")} " + selection.Name $"{(uninstallProxy ? "Uninstalling" : "Installing")} Uplay R1 Unlocker" + $" {(uninstallProxy ? "from" : "for")} " + selection.Name
@ -161,8 +161,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); 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 if (uninstallProxy
? File.Exists(api32_o) || File.Exists(api64_o) || File.Exists(config) || File.Exists(log) ? api32_o.Exists(form: this) || api64_o.Exists(form: this) || config.Exists(form: this) || log.Exists(form: this)
: File.Exists(old_api32) || File.Exists(old_api64) || File.Exists(api32) || File.Exists(api64)) : old_api32.Exists(form: this) || old_api64.Exists(form: this) || api32.Exists(form: this) || api64.Exists(form: this))
{ {
UpdateUser( UpdateUser(
$"{(uninstallProxy ? "Uninstalling" : "Installing")} Uplay R2 Unlocker" + $" {(uninstallProxy ? "from" : "for")} " + selection.Name $"{(uninstallProxy ? "Uninstalling" : "Installing")} Uplay R2 Unlocker" + $" {(uninstallProxy ? "from" : "for")} " + selection.Name

View file

@ -126,7 +126,7 @@ internal sealed partial class SelectForm : CustomForm
List<Task> appTasks = new(); List<Task> appTasks = new();
if (programsToScan.Any(c => c.platform is Platform.Paradox)) if (programsToScan.Any(c => c.platform is Platform.Paradox))
{ {
List<string> dllDirectories = await ParadoxLauncher.InstallPath.GetDllDirectoriesFromGameDirectory(Platform.Paradox); List<string> dllDirectories = await ParadoxLauncher.InstallPath.GetDllDirectoriesFromGameDirectory(Platform.Paradox, this);
if (dllDirectories is not null) if (dllDirectories is not null)
{ {
ProgramSelection selection = ProgramSelection.FromPlatformId(Platform.Paradox, "PL"); ProgramSelection selection = ProgramSelection.FromPlatformId(Platform.Paradox, "PL");
@ -169,7 +169,7 @@ internal sealed partial class SelectForm : CustomForm
{ {
if (Program.Canceled) if (Program.Canceled)
return; return;
List<string> dllDirectories = await gameDirectory.GetDllDirectoriesFromGameDirectory(Platform.Steam); List<string> dllDirectories = await gameDirectory.GetDllDirectoriesFromGameDirectory(Platform.Steam, this);
if (dllDirectories is null) if (dllDirectories is null)
{ {
Interlocked.Decrement(ref steamGamesToCheck); Interlocked.Decrement(ref steamGamesToCheck);
@ -325,7 +325,7 @@ internal sealed partial class SelectForm : CustomForm
{ {
if (Program.Canceled) if (Program.Canceled)
return; return;
List<string> dllDirectories = await directory.GetDllDirectoriesFromGameDirectory(Platform.Epic); List<string> dllDirectories = await directory.GetDllDirectoriesFromGameDirectory(Platform.Epic, this);
if (dllDirectories is null) if (dllDirectories is null)
{ {
RemoveFromRemainingGames(name); RemoveFromRemainingGames(name);
@ -447,7 +447,7 @@ internal sealed partial class SelectForm : CustomForm
{ {
if (Program.Canceled) if (Program.Canceled)
return; return;
List<string> dllDirectories = await gameDirectory.GetDllDirectoriesFromGameDirectory(Platform.Ubisoft); List<string> dllDirectories = await gameDirectory.GetDllDirectoriesFromGameDirectory(Platform.Ubisoft, this);
if (dllDirectories is null) if (dllDirectories is null)
{ {
RemoveFromRemainingGames(name); RemoveFromRemainingGames(name);
@ -515,7 +515,7 @@ internal sealed partial class SelectForm : CustomForm
resetKoaloaderButton.Enabled = false; resetKoaloaderButton.Enabled = false;
progressLabel.Text = "Waiting for user to select which programs/games to scan . . ."; progressLabel.Text = "Waiting for user to select which programs/games to scan . . .";
ShowProgressBar(); ShowProgressBar();
await ProgramData.Setup(); await ProgramData.Setup(this);
bool scan = forceScan; bool scan = forceScan;
if (!scan && (programsToScan is null || !programsToScan.Any() || forceProvideChoices)) if (!scan && (programsToScan is null || !programsToScan.Any() || forceProvideChoices))
{ {
@ -748,10 +748,10 @@ internal sealed partial class SelectForm : CustomForm
string appInfoVDF = $@"{SteamCMD.AppInfoPath}\{id}.vdf"; string appInfoVDF = $@"{SteamCMD.AppInfoPath}\{id}.vdf";
string appInfoJSON = $@"{SteamCMD.AppInfoPath}\{id}.json"; string appInfoJSON = $@"{SteamCMD.AppInfoPath}\{id}.json";
string cooldown = $@"{ProgramData.CooldownPath}\{id}.txt"; string cooldown = $@"{ProgramData.CooldownPath}\{id}.txt";
if (File.Exists(appInfoVDF) || File.Exists(appInfoJSON)) if (appInfoVDF.Exists(form: this) || appInfoJSON.Exists(form: this))
{ {
List<ContextMenuItem> queries = new(); List<ContextMenuItem> queries = new();
if (File.Exists(appInfoJSON)) if (appInfoJSON.Exists(form: this))
{ {
string platformString = selection is null || selection.Platform is Platform.Steam string platformString = selection is null || selection.Platform is Platform.Steam
? "Steam Store " ? "Steam Store "
@ -760,7 +760,7 @@ internal sealed partial class SelectForm : CustomForm
: ""; : "";
queries.Add(new($"Open {platformString}Query", "Notepad", (_, _) => Diagnostics.OpenFileInNotepad(appInfoJSON))); queries.Add(new($"Open {platformString}Query", "Notepad", (_, _) => Diagnostics.OpenFileInNotepad(appInfoJSON)));
} }
if (File.Exists(appInfoVDF)) if (appInfoVDF.Exists(form: this))
queries.Add(new("Open SteamCMD Query", "Notepad", (_, _) => Diagnostics.OpenFileInNotepad(appInfoVDF))); queries.Add(new("Open SteamCMD Query", "Notepad", (_, _) => Diagnostics.OpenFileInNotepad(appInfoVDF)));
if (queries.Any()) if (queries.Any())
{ {
@ -771,7 +771,7 @@ internal sealed partial class SelectForm : CustomForm
{ {
try try
{ {
File.Delete(appInfoVDF); appInfoVDF.Delete();
} }
catch catch
{ {
@ -779,7 +779,7 @@ internal sealed partial class SelectForm : CustomForm
} }
try try
{ {
File.Delete(appInfoJSON); appInfoJSON.Delete();
} }
catch catch
{ {
@ -787,7 +787,7 @@ internal sealed partial class SelectForm : CustomForm
} }
try try
{ {
File.Delete(cooldown); cooldown.Delete();
} }
catch catch
{ {
@ -819,8 +819,9 @@ 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, 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); out string config, out string old_log, out string log, out string cache);
if (File.Exists(api32) || File.Exists(api32_o) || File.Exists(api64) || File.Exists(api64_o) || File.Exists(old_config) if (api32.Exists(form: this) || api32_o.Exists(form: this) || api64.Exists(form: this) || api64_o.Exists(form: this)
|| File.Exists(config) || File.Exists(old_log) || File.Exists(log) || File.Exists(cache)) || old_config.Exists(form: this) || config.Exists(form: this) || old_log.Exists(form: this) || log.Exists(form: this)
|| cache.Exists(form: this))
items.Add(new ContextMenuItem($"Open Steamworks Directory #{++steam}", "File Explorer", items.Add(new ContextMenuItem($"Open Steamworks Directory #{++steam}", "File Explorer",
(_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); (_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory)));
} }
@ -829,7 +830,8 @@ 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, directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config,
out string log); out string log);
if (File.Exists(api32) || File.Exists(api32_o) || File.Exists(api64) || File.Exists(api64_o) || File.Exists(config) || File.Exists(log)) if (api32.Exists(form: this) || api32_o.Exists(form: this) || api64.Exists(form: this) || api64_o.Exists(form: this)
|| config.Exists(form: this) || log.Exists(form: this))
items.Add(new ContextMenuItem($"Open EOS Directory #{++epic}", "File Explorer", items.Add(new ContextMenuItem($"Open EOS Directory #{++epic}", "File Explorer",
(_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); (_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory)));
} }
@ -838,13 +840,14 @@ 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, directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config,
out string log); out string log);
if (File.Exists(api32) || File.Exists(api32_o) || File.Exists(api64) || File.Exists(api64_o) || File.Exists(config) || File.Exists(log)) if (api32.Exists(form: this) || api32_o.Exists(form: this) || api64.Exists(form: this) || api64_o.Exists(form: this)
|| config.Exists(form: this) || log.Exists(form: this))
items.Add(new ContextMenuItem($"Open Uplay R1 Directory #{++r1}", "File Explorer", items.Add(new ContextMenuItem($"Open Uplay R1 Directory #{++r1}", "File Explorer",
(_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); (_, _) => 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, directory.GetUplayR2Components(out string old_api32, out string old_api64, out api32, out api32_o, out api64, out api64_o, out config,
out log); out log);
if (File.Exists(old_api32) || File.Exists(old_api64) || File.Exists(api32) || File.Exists(api32_o) || File.Exists(api64) if (old_api32.Exists(form: this) || old_api64.Exists(form: this) || api32.Exists(form: this) || api32_o.Exists(form: this)
|| File.Exists(api64_o) || File.Exists(config) || File.Exists(log)) || api64.Exists(form: this) || api64_o.Exists(form: this) || config.Exists(form: this) || log.Exists(form: this))
items.Add(new ContextMenuItem($"Open Uplay R2 Directory #{++r2}", "File Explorer", items.Add(new ContextMenuItem($"Open Uplay R2 Directory #{++r2}", "File Explorer",
(_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory))); (_, _) => Diagnostics.OpenDirectoryInFileExplorer(directory)));
} }

View file

@ -41,7 +41,7 @@ internal static class EpicLibrary
{ {
if (Program.Canceled) if (Program.Canceled)
return games; return games;
string json = File.ReadAllText(file); string json = file.Read();
try try
{ {
Manifest manifest = JsonSerializer.Deserialize<Manifest>(json); Manifest manifest = JsonSerializer.Deserialize<Manifest>(json);

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -26,14 +25,14 @@ internal static class EpicStore
{ {
List<(string id, string name, string product, string icon, string developer)> dlcIds = new(); List<(string id, string name, string product, string icon, string developer)> dlcIds = new();
string cacheFile = ProgramData.AppInfoPath + @$"\{categoryNamespace}.json"; string cacheFile = ProgramData.AppInfoPath + @$"\{categoryNamespace}.json";
bool cachedExists = File.Exists(cacheFile); bool cachedExists = cacheFile.Exists();
Response response = null; Response response = null;
if (!cachedExists || ProgramData.CheckCooldown(categoryNamespace, CooldownEntitlement)) if (!cachedExists || ProgramData.CheckCooldown(categoryNamespace, CooldownEntitlement))
{ {
response = await QueryGraphQL(categoryNamespace); response = await QueryGraphQL(categoryNamespace);
try try
{ {
await File.WriteAllTextAsync(cacheFile, JsonConvert.SerializeObject(response, Formatting.Indented)); cacheFile.Write(JsonConvert.SerializeObject(response, Formatting.Indented));
} }
catch catch
{ {
@ -43,11 +42,11 @@ internal static class EpicStore
else else
try try
{ {
response = JsonConvert.DeserializeObject<Response>(await File.ReadAllTextAsync(cacheFile)); response = JsonConvert.DeserializeObject<Response>(cacheFile.Read());
} }
catch catch
{ {
File.Delete(cacheFile); cacheFile.Delete();
} }
if (response is null) if (response is null)
return dlcIds; return dlcIds;

View file

@ -90,28 +90,28 @@ internal static class ParadoxLauncher
foreach (string directory in selection.DllDirectories) foreach (string directory in selection.DllDirectories)
{ {
bool koaloaderInstalled = Koaloader.AutoLoadDLLs.Select(pair => (pair.unlocker, path: directory + @"\" + pair.dll)) bool koaloaderInstalled = Koaloader.AutoLoadDLLs.Select(pair => (pair.unlocker, path: directory + @"\" + pair.dll))
.Any(pair => File.Exists(pair.path) && pair.path.IsResourceFile()); .Any(pair => pair.path.Exists(form: form) && pair.path.IsResourceFile());
directory.GetSmokeApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string old_config, 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 _); out string config, out _, out _, out _);
smokeInstalled = smokeInstalled || File.Exists(api32_o) || File.Exists(api64_o) smokeInstalled = smokeInstalled || api32_o.Exists(form: form) || api64_o.Exists(form: form)
|| (File.Exists(old_config) || File.Exists(config)) && !koaloaderInstalled || (old_config.Exists(form: form) || config.Exists(form: form)) && !koaloaderInstalled
|| File.Exists(api32) && api32.IsResourceFile(ResourceIdentifier.Steamworks32) || api32.Exists(form: form) && api32.IsResourceFile(ResourceIdentifier.Steamworks32)
|| File.Exists(api64) && api64.IsResourceFile(ResourceIdentifier.Steamworks64); || api64.Exists(form: form) && api64.IsResourceFile(ResourceIdentifier.Steamworks64);
await SmokeAPI.Uninstall(directory, deleteOthers: false); await SmokeAPI.Uninstall(directory, deleteOthers: false);
if (steamOriginalSdk32 is null && File.Exists(api32) && !api32.IsResourceFile(ResourceIdentifier.Steamworks32)) if (steamOriginalSdk32 is null && api32.Exists(form: form) && !api32.IsResourceFile(ResourceIdentifier.Steamworks32))
steamOriginalSdk32 = await File.ReadAllBytesAsync(api32); steamOriginalSdk32 = api32.ReadBytes(true);
if (steamOriginalSdk64 is null && File.Exists(api64) && !api64.IsResourceFile(ResourceIdentifier.Steamworks64)) if (steamOriginalSdk64 is null && api64.Exists(form: form) && !api64.IsResourceFile(ResourceIdentifier.Steamworks64))
steamOriginalSdk64 = await File.ReadAllBytesAsync(api64); steamOriginalSdk64 = api64.ReadBytes(true);
directory.GetScreamApiComponents(out api32, out api32_o, out api64, out api64_o, out config, out string log); directory.GetScreamApiComponents(out api32, out api32_o, out api64, out api64_o, out config, out string log);
screamInstalled = screamInstalled || File.Exists(api32_o) || File.Exists(api64_o) screamInstalled = screamInstalled || api32_o.Exists(form: form) || api64_o.Exists(form: form)
|| (File.Exists(config) || File.Exists(log)) && !koaloaderInstalled || (config.Exists(form: form) || log.Exists(form: form)) && !koaloaderInstalled
|| File.Exists(api32) && api32.IsResourceFile(ResourceIdentifier.EpicOnlineServices32) || api32.Exists(form: form) && api32.IsResourceFile(ResourceIdentifier.EpicOnlineServices32)
|| File.Exists(api64) && api64.IsResourceFile(ResourceIdentifier.EpicOnlineServices64); || api64.Exists(form: form) && api64.IsResourceFile(ResourceIdentifier.EpicOnlineServices64);
await ScreamAPI.Uninstall(directory, deleteOthers: false); await ScreamAPI.Uninstall(directory, deleteOthers: false);
if (epicOriginalSdk32 is null && File.Exists(api32) && !api32.IsResourceFile(ResourceIdentifier.EpicOnlineServices32)) if (epicOriginalSdk32 is null && api32.Exists(form: form) && !api32.IsResourceFile(ResourceIdentifier.EpicOnlineServices32))
epicOriginalSdk32 = await File.ReadAllBytesAsync(api32); epicOriginalSdk32 = api32.ReadBytes(true);
if (epicOriginalSdk64 is null && File.Exists(api64) && !api64.IsResourceFile(ResourceIdentifier.EpicOnlineServices64)) if (epicOriginalSdk64 is null && api64.Exists(form: form) && !api64.IsResourceFile(ResourceIdentifier.EpicOnlineServices64))
epicOriginalSdk64 = await File.ReadAllBytesAsync(api64); epicOriginalSdk64 = api64.ReadBytes(true);
} }
using DialogForm dialogForm = new(form); using DialogForm dialogForm = new(form);
if (steamOriginalSdk32 is not null || steamOriginalSdk64 is not null || epicOriginalSdk32 is not null || epicOriginalSdk64 is not null) if (steamOriginalSdk32 is not null || steamOriginalSdk64 is not null || epicOriginalSdk32 is not null || epicOriginalSdk64 is not null)

View file

@ -120,7 +120,7 @@ internal static class SteamCMD
internal static async Task Setup(IProgress<int> progress) internal static async Task Setup(IProgress<int> progress)
{ {
await Cleanup(); await Cleanup();
if (!File.Exists(FilePath)) if (!FilePath.Exists())
{ {
HttpClient httpClient = HttpClientManager.HttpClient; HttpClient httpClient = HttpClientManager.HttpClient;
if (httpClient is null) if (httpClient is null)
@ -128,12 +128,12 @@ internal static class SteamCMD
byte[] file = await httpClient.GetByteArrayAsync(new Uri("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip")); byte[] file = await httpClient.GetByteArrayAsync(new Uri("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip"));
file.Write(ArchivePath); file.Write(ArchivePath);
ZipFile.ExtractToDirectory(ArchivePath, DirectoryPath); ZipFile.ExtractToDirectory(ArchivePath, DirectoryPath);
File.Delete(ArchivePath); ArchivePath.Delete();
} }
if (!File.Exists(DllPath)) if (!DllPath.Exists())
{ {
FileSystemWatcher watcher = new(DirectoryPath) { Filter = "*", IncludeSubdirectories = true, EnableRaisingEvents = true }; FileSystemWatcher watcher = new(DirectoryPath) { Filter = "*", IncludeSubdirectories = true, EnableRaisingEvents = true };
if (File.Exists(DllPath)) if (DllPath.Exists())
progress.Report(-15); // update (not used at the moment) progress.Report(-15); // update (not used at the moment)
else else
progress.Report(-1660); // install progress.Report(-1660); // install
@ -155,15 +155,15 @@ internal static class SteamCMD
{ {
if (Directory.Exists(ConfigPath)) if (Directory.Exists(ConfigPath))
foreach (string file in Directory.EnumerateFiles(ConfigPath, "*.tmp")) foreach (string file in Directory.EnumerateFiles(ConfigPath, "*.tmp"))
File.Delete(file); file.Delete();
foreach (string file in Directory.EnumerateFiles(DirectoryPath, "*.old")) foreach (string file in Directory.EnumerateFiles(DirectoryPath, "*.old"))
File.Delete(file); file.Delete();
foreach (string file in Directory.EnumerateFiles(DirectoryPath, "*.delete")) foreach (string file in Directory.EnumerateFiles(DirectoryPath, "*.delete"))
File.Delete(file); file.Delete();
foreach (string file in Directory.EnumerateFiles(DirectoryPath, "*.crash")) foreach (string file in Directory.EnumerateFiles(DirectoryPath, "*.crash"))
File.Delete(file); file.Delete();
foreach (string file in Directory.EnumerateFiles(DirectoryPath, "*.ntfs_transaction_failed")) foreach (string file in Directory.EnumerateFiles(DirectoryPath, "*.ntfs_transaction_failed"))
File.Delete(file); file.Delete();
if (Directory.Exists(AppCachePath)) if (Directory.Exists(AppCachePath))
Directory.Delete(AppCachePath, true); // this is definitely needed, so SteamCMD gets the latest information for us Directory.Delete(AppCachePath, true); // this is definitely needed, so SteamCMD gets the latest information for us
if (Directory.Exists(DumpsPath)) if (Directory.Exists(DumpsPath))
@ -183,21 +183,12 @@ internal static class SteamCMD
{ {
if (Program.Canceled) if (Program.Canceled)
return null; return null;
string output;
string appUpdateFile = $@"{AppInfoPath}\{appId}.vdf"; string appUpdateFile = $@"{AppInfoPath}\{appId}.vdf";
restart: restart:
if (Program.Canceled) if (Program.Canceled)
return null; return null;
if (File.Exists(appUpdateFile)) string output = appUpdateFile.Read();
try if (output is null)
{
output = await File.ReadAllTextAsync(appUpdateFile, Encoding.UTF8);
}
catch
{
goto restart;
}
else
{ {
output = await Run(appId) ?? ""; output = await Run(appId) ?? "";
int openBracket = output.IndexOf("{", StringComparison.Ordinal); int openBracket = output.IndexOf("{", StringComparison.Ordinal);
@ -206,14 +197,7 @@ internal static class SteamCMD
{ {
output = $"\"{appId}\"\n" + output[openBracket..(1 + closeBracket)]; output = $"\"{appId}\"\n" + output[openBracket..(1 + closeBracket)];
output = output.Replace("ERROR! Failed to install app '4' (Invalid platform)", ""); output = output.Replace("ERROR! Failed to install app '4' (Invalid platform)", "");
try appUpdateFile.Write(output);
{
await File.WriteAllTextAsync(appUpdateFile, output, Encoding.UTF8);
}
catch
{
goto restart;
}
} }
else else
goto restart; goto restart;
@ -222,7 +206,7 @@ internal static class SteamCMD
return null; return null;
if (!ValveDataFile.TryDeserialize(output, out VProperty appInfo) || appInfo.Value is VValue) if (!ValveDataFile.TryDeserialize(output, out VProperty appInfo) || appInfo.Value is VValue)
{ {
File.Delete(appUpdateFile); appUpdateFile.Delete();
goto restart; goto restart;
} }
if (appInfo.Value.Children().ToList().Count == 0) if (appInfo.Value.Children().ToList().Count == 0)
@ -237,10 +221,8 @@ internal static class SteamCMD
return appInfo; return appInfo;
List<string> dlcAppIds = await ParseDlcAppIds(appInfo); List<string> dlcAppIds = await ParseDlcAppIds(appInfo);
foreach (string dlcAppUpdateFile in dlcAppIds.Select(id => $@"{AppInfoPath}\{id}.vdf")) foreach (string dlcAppUpdateFile in dlcAppIds.Select(id => $@"{AppInfoPath}\{id}.vdf"))
if (File.Exists(dlcAppUpdateFile)) dlcAppUpdateFile.Delete();
File.Delete(dlcAppUpdateFile); appUpdateFile.Delete();
if (File.Exists(appUpdateFile))
File.Delete(appUpdateFile);
goto restart; goto restart;
} }

View file

@ -1,7 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using CreamInstaller.Utility; using CreamInstaller.Utility;
using Gameloop.Vdf.Linq; using Gameloop.Vdf.Linq;
@ -55,7 +54,7 @@ internal static class SteamLibrary
{ {
if (Program.Canceled) if (Program.Canceled)
return games; return games;
if (!ValveDataFile.TryDeserialize(File.ReadAllText(file, Encoding.UTF8), out VProperty result)) if (!ValveDataFile.TryDeserialize(file.Read(), out VProperty result))
continue; continue;
string appId = result.Value.GetChild("appid")?.ToString(); string appId = result.Value.GetChild("appid")?.ToString();
string installdir = result.Value.GetChild("installdir")?.ToString(); string installdir = result.Value.GetChild("installdir")?.ToString();
@ -93,7 +92,7 @@ internal static class SteamLibrary
return gameDirectories; return gameDirectories;
gameDirectories.Add(libraryFolder); gameDirectories.Add(libraryFolder);
string libraryFolders = libraryFolder + @"\libraryfolders.vdf"; string libraryFolders = libraryFolder + @"\libraryfolders.vdf";
if (!File.Exists(libraryFolders) || !ValveDataFile.TryDeserialize(File.ReadAllText(libraryFolders, Encoding.UTF8), out VProperty result)) if (!libraryFolders.Exists() || !ValveDataFile.TryDeserialize(libraryFolders.Read(), out VProperty result))
return gameDirectories; return gameDirectories;
foreach (VToken vToken in result.Value.Where(p => p is VProperty property && int.TryParse(property.Key, out int _))) foreach (VToken vToken in result.Value.Where(p => p is VProperty property && int.TryParse(property.Key, out int _)))
{ {

View file

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -35,7 +34,7 @@ internal static class SteamStore
if (Program.Canceled) if (Program.Canceled)
return null; return null;
string cacheFile = ProgramData.AppInfoPath + @$"\{appId}.json"; string cacheFile = ProgramData.AppInfoPath + @$"\{appId}.json";
bool cachedExists = File.Exists(cacheFile); bool cachedExists = cacheFile.Exists();
if (!cachedExists || ProgramData.CheckCooldown(appId, isDlc ? CooldownDlc : CooldownGame)) if (!cachedExists || ProgramData.CheckCooldown(appId, isDlc ? CooldownDlc : CooldownGame))
{ {
string response = await HttpClientManager.EnsureGet($"https://store.steampowered.com/api/appdetails?appids={appId}"); string response = await HttpClientManager.EnsureGet($"https://store.steampowered.com/api/appdetails?appids={appId}");
@ -64,7 +63,7 @@ internal static class SteamStore
{ {
try try
{ {
await File.WriteAllTextAsync(cacheFile, JsonConvert.SerializeObject(data, Formatting.Indented)); cacheFile.Write(JsonConvert.SerializeObject(data, Formatting.Indented));
} }
catch catch
#if DEBUG #if DEBUG
@ -118,18 +117,11 @@ internal static class SteamStore
if (cachedExists) if (cachedExists)
try try
{ {
return JsonConvert.DeserializeObject<AppData>(await File.ReadAllTextAsync(cacheFile)); return JsonConvert.DeserializeObject<AppData>(cacheFile.Read());
} }
catch catch
{ {
try cacheFile.Delete();
{
File.Delete(cacheFile);
}
catch
{
// ignored
}
} }
if (isDlc || attempts >= 10) if (isDlc || attempts >= 10)
return null; return null;

View file

@ -59,16 +59,16 @@ internal static class Koaloader
private static void CheckConfig(string directory, InstallForm installForm = null) private static void CheckConfig(string directory, InstallForm installForm = null)
{ {
directory.GetKoaloaderComponents(out string old_config, out string config); directory.GetKoaloaderComponents(out string old_config, out string config);
if (File.Exists(old_config)) if (old_config.Exists(form: installForm))
{ {
if (!File.Exists(config)) if (!config.Exists(form: installForm))
{ {
File.Move(old_config, config!); old_config.Move(config!);
installForm?.UpdateUser($"Converted old configuration: {Path.GetFileName(old_config)} -> {Path.GetFileName(config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Converted old configuration: {Path.GetFileName(old_config)} -> {Path.GetFileName(config)}", LogTextBox.Action, false);
} }
else else
{ {
File.Delete(old_config); old_config.Delete();
installForm?.UpdateUser($"Deleted old configuration: {Path.GetFileName(old_config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted old configuration: {Path.GetFileName(old_config)}", LogTextBox.Action, false);
} }
} }
@ -78,15 +78,15 @@ internal static class Koaloader
{ {
/*if (installForm is not null) /*if (installForm is not null)
installForm.UpdateUser("Generating Koaloader configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation);*/ installForm.UpdateUser("Generating Koaloader configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation);*/
File.Create(config).Close(); config.Create(true, installForm);
StreamWriter writer = new(config, true, Encoding.UTF8); StreamWriter writer = new(config, true, Encoding.UTF8);
WriteConfig(writer, targets, modules, installForm); WriteConfig(writer, targets, modules, installForm);
writer.Flush(); writer.Flush();
writer.Close(); writer.Close();
} }
else if (File.Exists(config)) else if (config.Exists(form: installForm))
{ {
File.Delete(config); config.Delete();
installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false);
} }
} }
@ -136,25 +136,25 @@ internal static class Koaloader
{ {
directory.GetKoaloaderComponents(out string old_config, out string config); directory.GetKoaloaderComponents(out string old_config, out string config);
foreach (string proxyPath in directory.GetKoaloaderProxies() foreach (string proxyPath in directory.GetKoaloaderProxies()
.Where(proxyPath => File.Exists(proxyPath) && proxyPath.IsResourceFile(ResourceIdentifier.Koaloader))) .Where(proxyPath => proxyPath.Exists(form: installForm) && proxyPath.IsResourceFile(ResourceIdentifier.Koaloader)))
{ {
File.Delete(proxyPath); proxyPath.Delete();
installForm?.UpdateUser($"Deleted Koaloader: {Path.GetFileName(proxyPath)}", LogTextBox.Action, false); 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)) foreach ((string unlocker, string path) in AutoLoadDLLs.Select(pair => (pair.unlocker, path: directory + @"\" + pair.dll))
.Where(pair => File.Exists(pair.path) && pair.path.IsResourceFile())) .Where(pair => pair.path.Exists(form: installForm) && pair.path.IsResourceFile()))
{ {
File.Delete(path); path.Delete();
installForm?.UpdateUser($"Deleted {unlocker}: {Path.GetFileName(path)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted {unlocker}: {Path.GetFileName(path)}", LogTextBox.Action, false);
} }
if (deleteConfig && File.Exists(old_config)) if (deleteConfig && old_config.Exists(form: installForm))
{ {
File.Delete(old_config); old_config.Delete();
installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(old_config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(old_config)}", LogTextBox.Action, false);
} }
if (deleteConfig && File.Exists(config)) if (deleteConfig && config.Exists(form: installForm))
{ {
File.Delete(config); config.Delete();
installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false);
} }
await SmokeAPI.Uninstall(directory, installForm, deleteConfig); await SmokeAPI.Uninstall(directory, installForm, deleteConfig);
@ -171,12 +171,13 @@ internal static class Koaloader
{ {
string proxy = selection.KoaloaderProxy ?? ProgramSelection.DefaultKoaloaderProxy; string proxy = selection.KoaloaderProxy ?? ProgramSelection.DefaultKoaloaderProxy;
string path = directory + @"\" + proxy + ".dll"; string path = directory + @"\" + proxy + ".dll";
foreach (string _path in directory.GetKoaloaderProxies().Where(p => p != path && File.Exists(p) && p.IsResourceFile(ResourceIdentifier.Koaloader))) foreach (string _path in directory.GetKoaloaderProxies()
.Where(p => p != path && p.Exists(form: installForm) && p.IsResourceFile(ResourceIdentifier.Koaloader)))
{ {
File.Delete(_path); _path.Delete();
installForm?.UpdateUser($"Deleted Koaloader: {Path.GetFileName(_path)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted Koaloader: {Path.GetFileName(_path)}", LogTextBox.Action, false);
} }
if (File.Exists(path) && !path.IsResourceFile(ResourceIdentifier.Koaloader)) if (path.Exists(form: installForm) && !path.IsResourceFile(ResourceIdentifier.Koaloader))
throw new CustomMessageException("A non-Koaloader DLL named " + proxy + ".dll already exists in this directory!"); throw new CustomMessageException("A non-Koaloader DLL named " + proxy + ".dll already exists in this directory!");
path.WriteProxy(proxy, binaryType); path.WriteProxy(proxy, binaryType);
installForm?.UpdateUser($"Wrote {(binaryType == BinaryType.BIT32 ? "32-bit" : "64-bit")} Koaloader: {Path.GetFileName(path)}", LogTextBox.Action, installForm?.UpdateUser($"Wrote {(binaryType == BinaryType.BIT32 ? "32-bit" : "64-bit")} Koaloader: {Path.GetFileName(path)}", LogTextBox.Action,
@ -204,9 +205,9 @@ internal static class Koaloader
path = directory + @"\SmokeAPI32.dll"; path = directory + @"\SmokeAPI32.dll";
if (rootDirectory is not null && directory != rootDirectory) if (rootDirectory is not null && directory != rootDirectory)
{ {
if (File.Exists(path)) if (path.Exists(form: installForm))
{ {
File.Delete(path); path.Delete();
installForm?.UpdateUser($"Deleted SmokeAPI from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted SmokeAPI from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, false);
} }
path = rootDirectory + @"\SmokeAPI32.dll"; path = rootDirectory + @"\SmokeAPI32.dll";
@ -221,9 +222,9 @@ internal static class Koaloader
path = directory + @"\SmokeAPI64.dll"; path = directory + @"\SmokeAPI64.dll";
if (rootDirectory is not null && directory != rootDirectory) if (rootDirectory is not null && directory != rootDirectory)
{ {
if (File.Exists(path)) if (path.Exists(form: installForm))
{ {
File.Delete(path); path.Delete();
installForm?.UpdateUser($"Deleted SmokeAPI from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted SmokeAPI from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, false);
} }
path = rootDirectory + @"\SmokeAPI64.dll"; path = rootDirectory + @"\SmokeAPI64.dll";
@ -244,9 +245,9 @@ internal static class Koaloader
path = directory + @"\ScreamAPI32.dll"; path = directory + @"\ScreamAPI32.dll";
if (rootDirectory is not null && directory != rootDirectory) if (rootDirectory is not null && directory != rootDirectory)
{ {
if (File.Exists(path)) if (path.Exists(form: installForm))
{ {
File.Delete(path); path.Delete();
installForm?.UpdateUser($"Deleted ScreamAPI from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted ScreamAPI from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, false);
} }
path = rootDirectory + @"\ScreamAPI32.dll"; path = rootDirectory + @"\ScreamAPI32.dll";
@ -261,9 +262,9 @@ internal static class Koaloader
path = directory + @"\ScreamAPI64.dll"; path = directory + @"\ScreamAPI64.dll";
if (rootDirectory is not null && directory != rootDirectory) if (rootDirectory is not null && directory != rootDirectory)
{ {
if (File.Exists(path)) if (path.Exists(form: installForm))
{ {
File.Delete(path); path.Delete();
installForm?.UpdateUser($"Deleted ScreamAPI from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted ScreamAPI from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, false);
} }
path = rootDirectory + @"\ScreamAPI64.dll"; path = rootDirectory + @"\ScreamAPI64.dll";
@ -283,9 +284,9 @@ internal static class Koaloader
path = directory + @"\UplayR1Unlocker32.dll"; path = directory + @"\UplayR1Unlocker32.dll";
if (rootDirectory is not null && directory != rootDirectory) if (rootDirectory is not null && directory != rootDirectory)
{ {
if (File.Exists(path)) if (path.Exists(form: installForm))
{ {
File.Delete(path); path.Delete();
installForm?.UpdateUser($"Deleted Uplay R1 Unlocker from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, installForm?.UpdateUser($"Deleted Uplay R1 Unlocker from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action,
false); false);
} }
@ -301,9 +302,9 @@ internal static class Koaloader
path = directory + @"\UplayR1Unlocker64.dll"; path = directory + @"\UplayR1Unlocker64.dll";
if (rootDirectory is not null && directory != rootDirectory) if (rootDirectory is not null && directory != rootDirectory)
{ {
if (File.Exists(path)) if (path.Exists(form: installForm))
{ {
File.Delete(path); path.Delete();
installForm?.UpdateUser($"Deleted Uplay R1 Unlocker from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, installForm?.UpdateUser($"Deleted Uplay R1 Unlocker from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action,
false); false);
} }
@ -320,9 +321,9 @@ internal static class Koaloader
path = directory + @"\UplayR2Unlocker32.dll"; path = directory + @"\UplayR2Unlocker32.dll";
if (rootDirectory is not null && directory != rootDirectory) if (rootDirectory is not null && directory != rootDirectory)
{ {
if (File.Exists(path)) if (path.Exists(form: installForm))
{ {
File.Delete(path); path.Delete();
installForm?.UpdateUser($"Deleted Uplay R2 Unlocker from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, installForm?.UpdateUser($"Deleted Uplay R2 Unlocker from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action,
false); false);
} }
@ -338,9 +339,9 @@ internal static class Koaloader
path = directory + @"\UplayR2Unlocker64.dll"; path = directory + @"\UplayR2Unlocker64.dll";
if (rootDirectory is not null && directory != rootDirectory) if (rootDirectory is not null && directory != rootDirectory)
{ {
if (File.Exists(path)) if (path.Exists(form: installForm))
{ {
File.Delete(path); path.Delete();
installForm?.UpdateUser($"Deleted Uplay R2 Unlocker from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action, installForm?.UpdateUser($"Deleted Uplay R2 Unlocker from non-root directory: {Path.GetFileName(path)}", LogTextBox.Action,
false); false);
} }

View file

@ -7,6 +7,7 @@ using System.Runtime.InteropServices;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms;
using CreamInstaller.Utility; using CreamInstaller.Utility;
namespace CreamInstaller.Resources; namespace CreamInstaller.Resources;
@ -466,8 +467,7 @@ internal static class Resources
return false; return false;
} }
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode), DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
private static extern bool GetBinaryType(string lpApplicationName, out BinaryType lpBinaryType); 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) => GetBinaryType(path, out binaryType);
@ -522,7 +522,7 @@ internal static class Resources
|| subPath.Contains("ANTICHEAT"); || subPath.Contains("ANTICHEAT");
} }
internal static async Task<List<string>> GetDllDirectoriesFromGameDirectory(this string gameDirectory, Platform platform) internal static async Task<List<string>> GetDllDirectoriesFromGameDirectory(this string gameDirectory, Platform platform, Form form = null)
=> await Task.Run(() => => await Task.Run(() =>
{ {
List<string> dllDirectories = new(); List<string> dllDirectories = new();
@ -537,35 +537,35 @@ internal static class Resources
if (dllDirectories.Contains(subDirectory)) if (dllDirectories.Contains(subDirectory))
continue; continue;
bool koaloaderInstalled = Koaloader.AutoLoadDLLs.Select(pair => (pair.unlocker, path: directory + @"\" + pair.dll)) bool koaloaderInstalled = Koaloader.AutoLoadDLLs.Select(pair => (pair.unlocker, path: directory + @"\" + pair.dll))
.Any(pair => File.Exists(pair.path) && pair.path.IsResourceFile()); .Any(pair => pair.path.Exists(form: form) && pair.path.IsResourceFile());
if (platform is Platform.Steam or Platform.Paradox) 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, 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); out string config, out string old_log, out string log, out string cache);
if (File.Exists(api) || File.Exists(api_o) || File.Exists(api64) || File.Exists(api64_o) if (api.Exists(form: form) || api_o.Exists(form: form) || api64.Exists(form: form) || api64_o.Exists(form: form)
|| (File.Exists(old_config) || File.Exists(config) || File.Exists(old_log) || File.Exists(log) || File.Exists(cache)) || (old_config.Exists(form: form) || config.Exists(form: form) || old_log.Exists(form: form) || log.Exists(form: form)
&& !koaloaderInstalled) || cache.Exists(form: form)) && !koaloaderInstalled)
dllDirectories.Add(subDirectory); dllDirectories.Add(subDirectory);
} }
if (platform is Platform.Epic or Platform.Paradox) 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, subDirectory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config,
out string log); out string log);
if (File.Exists(api32) || File.Exists(api32_o) || File.Exists(api64) || File.Exists(api64_o) if (api32.Exists(form: form) || api32_o.Exists(form: form) || api64.Exists(form: form) || api64_o.Exists(form: form)
|| (File.Exists(config) || File.Exists(log)) && !koaloaderInstalled) || (config.Exists(form: form) || log.Exists(form: form)) && !koaloaderInstalled)
dllDirectories.Add(subDirectory); dllDirectories.Add(subDirectory);
} }
if (platform is Platform.Ubisoft) if (platform is Platform.Ubisoft)
{ {
subDirectory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config, subDirectory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config,
out string log); out string log);
if (File.Exists(api32) || File.Exists(api32_o) || File.Exists(api64) || File.Exists(api64_o) if (api32.Exists(form: form) || api32_o.Exists(form: form) || api64.Exists(form: form) || api64_o.Exists(form: form)
|| (File.Exists(config) || File.Exists(log)) && !koaloaderInstalled) || (config.Exists(form: form) || log.Exists(form: form)) && !koaloaderInstalled)
dllDirectories.Add(subDirectory); 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, subDirectory.GetUplayR2Components(out string old_api32, out string old_api64, out api32, out api32_o, out api64, out api64_o, out config,
out log); out log);
if (File.Exists(old_api32) || File.Exists(old_api64) || File.Exists(api32) || File.Exists(api32_o) || File.Exists(api64) if (old_api32.Exists(form: form) || old_api64.Exists(form: form) || api32.Exists(form: form) || api32_o.Exists(form: form)
|| File.Exists(api64_o) || (File.Exists(config) || File.Exists(log)) && !koaloaderInstalled) || api64.Exists(form: form) || api64_o.Exists(form: form) || (config.Exists(form: form) || log.Exists(form: form)) && !koaloaderInstalled)
dllDirectories.Add(subDirectory); dllDirectories.Add(subDirectory);
} }
} }
@ -584,7 +584,7 @@ internal static class Resources
private static string ComputeMD5(this string filePath) private static string ComputeMD5(this string filePath)
{ {
if (!File.Exists(filePath)) if (!filePath.Exists())
return null; return null;
#pragma warning disable CA5351 #pragma warning disable CA5351
using MD5 md5 = MD5.Create(); using MD5 md5 = MD5.Create();

View file

@ -39,16 +39,16 @@ internal static class ScreamAPI
{ {
/*if (installForm is not null) /*if (installForm is not null)
installForm.UpdateUser("Generating ScreamAPI configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation);*/ installForm.UpdateUser("Generating ScreamAPI configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation);*/
File.Create(config).Close(); config.Create(true, installForm);
StreamWriter writer = new(config, true, Encoding.UTF8); StreamWriter writer = new(config, true, Encoding.UTF8);
WriteConfig(writer, new(overrideCatalogItems.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), WriteConfig(writer, new(overrideCatalogItems.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String),
new(entitlements.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), installForm); new(entitlements.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), installForm);
writer.Flush(); writer.Flush();
writer.Close(); writer.Close();
} }
else if (File.Exists(config)) else if (config.Exists(form: installForm))
{ {
File.Delete(config); config.Delete();
installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false);
} }
} }
@ -105,36 +105,36 @@ internal static class ScreamAPI
=> await Task.Run(() => => 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); directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log);
if (File.Exists(api32_o)) if (api32_o.Exists(form: installForm))
{ {
if (File.Exists(api32)) if (api32.Exists(form: installForm))
{ {
File.Delete(api32); api32.Delete();
installForm?.UpdateUser($"Deleted ScreamAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted ScreamAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false);
} }
File.Move(api32_o, api32!); api32_o.Move(api32!);
installForm?.UpdateUser($"Restored EOS: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false); installForm?.UpdateUser($"Restored EOS: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false);
} }
if (File.Exists(api64_o)) if (api64_o.Exists(form: installForm))
{ {
if (File.Exists(api64)) if (api64.Exists(form: installForm))
{ {
File.Delete(api64); api64.Delete();
installForm?.UpdateUser($"Deleted ScreamAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted ScreamAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false);
} }
File.Move(api64_o, api64!); api64_o.Move(api64!);
installForm?.UpdateUser($"Restored EOS: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api64)}", LogTextBox.Action, false); installForm?.UpdateUser($"Restored EOS: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api64)}", LogTextBox.Action, false);
} }
if (!deleteOthers) if (!deleteOthers)
return; return;
if (File.Exists(config)) if (config.Exists(form: installForm))
{ {
File.Delete(config); config.Delete();
installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false);
} }
if (File.Exists(log)) if (log.Exists(form: installForm))
{ {
File.Delete(log); log.Delete();
installForm?.UpdateUser($"Deleted log: {Path.GetFileName(log)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted log: {Path.GetFileName(log)}", LogTextBox.Action, false);
} }
}); });
@ -143,22 +143,22 @@ internal static class ScreamAPI
=> await Task.Run(() => => await Task.Run(() =>
{ {
directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out _, out _); directory.GetScreamApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out _, out _);
if (File.Exists(api32) && !File.Exists(api32_o)) if (api32.Exists(form: installForm) && !api32_o.Exists(form: installForm))
{ {
File.Move(api32, api32_o!); api32.Move(api32_o!);
installForm?.UpdateUser($"Renamed EOS: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false); installForm?.UpdateUser($"Renamed EOS: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false);
} }
if (File.Exists(api32_o)) if (api32_o.Exists(form: installForm))
{ {
"ScreamAPI.EOSSDK-Win32-Shipping.dll".Write(api32); "ScreamAPI.EOSSDK-Win32-Shipping.dll".Write(api32);
installForm?.UpdateUser($"Wrote ScreamAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false); installForm?.UpdateUser($"Wrote ScreamAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false);
} }
if (File.Exists(api64) && !File.Exists(api64_o)) if (api64.Exists(form: installForm) && !api64_o.Exists(form: installForm))
{ {
File.Move(api64, api64_o!); api64.Move(api64_o!);
installForm?.UpdateUser($"Renamed EOS: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false); installForm?.UpdateUser($"Renamed EOS: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false);
} }
if (File.Exists(api64_o)) if (api64_o.Exists(form: installForm))
{ {
"ScreamAPI.EOSSDK-Win64-Shipping.dll".Write(api64); "ScreamAPI.EOSSDK-Win64-Shipping.dll".Write(api64);
installForm?.UpdateUser($"Wrote ScreamAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false); installForm?.UpdateUser($"Wrote ScreamAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false);

View file

@ -51,16 +51,16 @@ internal static class SmokeAPI
extraApps.Add(newExtraPair); extraApps.Add(newExtraPair);
} }
injectDlc = injectDlc.ToList(); injectDlc = injectDlc.ToList();
if (File.Exists(old_config)) if (old_config.Exists(form: installForm))
{ {
File.Delete(old_config); old_config.Delete();
installForm?.UpdateUser($"Deleted old configuration: {Path.GetFileName(old_config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted old configuration: {Path.GetFileName(old_config)}", LogTextBox.Action, false);
} }
if (selection.ExtraSelectedDlc.Any(p => p.Value.dlc.Any()) || overrideDlc.Any() || injectDlc.Any()) if (selection.ExtraSelectedDlc.Any(p => p.Value.dlc.Any()) || overrideDlc.Any() || injectDlc.Any())
{ {
/*if (installForm is not null) /*if (installForm is not null)
installForm.UpdateUser("Generating SmokeAPI configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation);*/ installForm.UpdateUser("Generating SmokeAPI configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation);*/
File.Create(config).Close(); config.Create(true, installForm);
StreamWriter writer = new(config, true, Encoding.UTF8); StreamWriter writer = new(config, true, Encoding.UTF8);
WriteConfig(writer, selection.Id, new(extraApps.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), WriteConfig(writer, selection.Id, new(extraApps.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String),
new(overrideDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), new(overrideDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String),
@ -68,9 +68,9 @@ internal static class SmokeAPI
writer.Flush(); writer.Flush();
writer.Close(); writer.Close();
} }
else if (File.Exists(config)) else if (config.Exists(form: installForm))
{ {
File.Delete(config); config.Delete();
installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false);
} }
} }
@ -155,58 +155,58 @@ internal static class SmokeAPI
=> await Task.Run(() => => await Task.Run(() =>
{ {
directory.GetCreamApiComponents(out _, out _, out _, out _, out string oldConfig); directory.GetCreamApiComponents(out _, out _, out _, out _, out string oldConfig);
if (File.Exists(oldConfig)) if (oldConfig.Exists(form: installForm))
{ {
File.Delete(oldConfig); oldConfig.Delete();
installForm?.UpdateUser($"Deleted old CreamAPI configuration: {Path.GetFileName(oldConfig)}", LogTextBox.Action, false); 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, 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); out string config, out string old_log, out string log, out string cache);
if (File.Exists(api32_o)) if (api32_o.Exists(form: installForm))
{ {
if (File.Exists(api32)) if (api32.Exists(form: installForm))
{ {
File.Delete(api32); api32.Delete();
installForm?.UpdateUser($"Deleted SmokeAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted SmokeAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false);
} }
File.Move(api32_o, api32!); api32_o.Move(api32!);
installForm?.UpdateUser($"Restored Steamworks: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false); installForm?.UpdateUser($"Restored Steamworks: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false);
} }
if (File.Exists(api64_o)) if (api64_o.Exists(form: installForm))
{ {
if (File.Exists(api64)) if (api64.Exists(form: installForm))
{ {
File.Delete(api64); api64.Delete();
installForm?.UpdateUser($"Deleted SmokeAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted SmokeAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false);
} }
File.Move(api64_o, api64!); api64_o.Move(api64!);
installForm?.UpdateUser($"Restored Steamworks: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api64)}", LogTextBox.Action, false); installForm?.UpdateUser($"Restored Steamworks: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api64)}", LogTextBox.Action, false);
} }
if (!deleteOthers) if (!deleteOthers)
return; return;
if (File.Exists(old_config)) if (old_config.Exists(form: installForm))
{ {
File.Delete(old_config); old_config.Delete();
installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(old_config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(old_config)}", LogTextBox.Action, false);
} }
if (File.Exists(config)) if (config.Exists(form: installForm))
{ {
File.Delete(config); config.Delete();
installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false);
} }
if (File.Exists(cache)) if (cache.Exists(form: installForm))
{ {
File.Delete(cache); cache.Delete();
installForm?.UpdateUser($"Deleted cache: {Path.GetFileName(cache)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted cache: {Path.GetFileName(cache)}", LogTextBox.Action, false);
} }
if (File.Exists(old_log)) if (old_log.Exists(form: installForm))
{ {
File.Delete(old_log); old_log.Delete();
installForm?.UpdateUser($"Deleted log: {Path.GetFileName(old_log)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted log: {Path.GetFileName(old_log)}", LogTextBox.Action, false);
} }
if (File.Exists(log)) if (log.Exists(form: installForm))
{ {
File.Delete(log); log.Delete();
installForm?.UpdateUser($"Deleted log: {Path.GetFileName(log)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted log: {Path.GetFileName(log)}", LogTextBox.Action, false);
} }
}); });
@ -215,28 +215,28 @@ internal static class SmokeAPI
=> await Task.Run(() => => await Task.Run(() =>
{ {
directory.GetCreamApiComponents(out _, out _, out _, out _, out string oldConfig); directory.GetCreamApiComponents(out _, out _, out _, out _, out string oldConfig);
if (File.Exists(oldConfig)) if (oldConfig.Exists(form: installForm))
{ {
File.Delete(oldConfig); oldConfig.Delete();
installForm?.UpdateUser($"Deleted old CreamAPI configuration: {Path.GetFileName(oldConfig)}", LogTextBox.Action, false); 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 _); directory.GetSmokeApiComponents(out string api32, out string api32_o, out string api64, out string api64_o, out _, out _, out _, out _, out _);
if (File.Exists(api32) && !File.Exists(api32_o)) if (api32.Exists(form: installForm) && !api32_o.Exists(form: installForm))
{ {
File.Move(api32, api32_o!); api32.Move(api32_o!);
installForm?.UpdateUser($"Renamed Steamworks: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false); installForm?.UpdateUser($"Renamed Steamworks: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false);
} }
if (File.Exists(api32_o)) if (api32_o.Exists(form: installForm))
{ {
"SmokeAPI.steam_api.dll".Write(api32); "SmokeAPI.steam_api.dll".Write(api32);
installForm?.UpdateUser($"Wrote SmokeAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false); installForm?.UpdateUser($"Wrote SmokeAPI: {Path.GetFileName(api32)}", LogTextBox.Action, false);
} }
if (File.Exists(api64) && !File.Exists(api64_o)) if (api64.Exists(form: installForm) && !api64_o.Exists(form: installForm))
{ {
File.Move(api64, api64_o!); api64.Move(api64_o!);
installForm?.UpdateUser($"Renamed Steamworks: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false); installForm?.UpdateUser($"Renamed Steamworks: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false);
} }
if (File.Exists(api64_o)) if (api64_o.Exists(form: installForm))
{ {
"SmokeAPI.steam_api64.dll".Write(api64); "SmokeAPI.steam_api64.dll".Write(api64);
installForm?.UpdateUser($"Wrote SmokeAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false); installForm?.UpdateUser($"Wrote SmokeAPI: {Path.GetFileName(api64)}", LogTextBox.Action, false);

View file

@ -33,15 +33,15 @@ internal static class UplayR1
{ {
/*if (installForm is not null) /*if (installForm is not null)
installForm.UpdateUser("Generating Uplay R1 Unlocker configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation);*/ installForm.UpdateUser("Generating Uplay R1 Unlocker configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation);*/
File.Create(config).Close(); config.Create(true, installForm);
StreamWriter writer = new(config, true, Encoding.UTF8); StreamWriter writer = new(config, true, Encoding.UTF8);
WriteConfig(writer, new(blacklistDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), installForm); WriteConfig(writer, new(blacklistDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), installForm);
writer.Flush(); writer.Flush();
writer.Close(); writer.Close();
} }
else if (File.Exists(config)) else if (config.Exists(form: installForm))
{ {
File.Delete(config); config.Delete();
installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false);
} }
} }
@ -75,36 +75,36 @@ internal static class UplayR1
=> await Task.Run(() => => 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); directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out string config, out string log);
if (File.Exists(api32_o)) if (api32_o.Exists(form: installForm))
{ {
if (File.Exists(api32)) if (api32.Exists(form: installForm))
{ {
File.Delete(api32); api32.Delete();
installForm?.UpdateUser($"Deleted Uplay R1 Unlocker: {Path.GetFileName(api32)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted Uplay R1 Unlocker: {Path.GetFileName(api32)}", LogTextBox.Action, false);
} }
File.Move(api32_o, api32!); api32_o.Move(api32!);
installForm?.UpdateUser($"Restored Uplay R1: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false); installForm?.UpdateUser($"Restored Uplay R1: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api32)}", LogTextBox.Action, false);
} }
if (File.Exists(api64_o)) if (api64_o.Exists(form: installForm))
{ {
if (File.Exists(api64)) if (api64.Exists(form: installForm))
{ {
File.Delete(api64); api64.Delete();
installForm?.UpdateUser($"Deleted Uplay R1 Unlocker: {Path.GetFileName(api64)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted Uplay R1 Unlocker: {Path.GetFileName(api64)}", LogTextBox.Action, false);
} }
File.Move(api64_o, api64!); api64_o.Move(api64!);
installForm?.UpdateUser($"Restored Uplay R1: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api64)}", LogTextBox.Action, false); installForm?.UpdateUser($"Restored Uplay R1: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api64)}", LogTextBox.Action, false);
} }
if (!deleteOthers) if (!deleteOthers)
return; return;
if (File.Exists(config)) if (config.Exists(form: installForm))
{ {
File.Delete(config); config.Delete();
installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false);
} }
if (File.Exists(log)) if (log.Exists(form: installForm))
{ {
File.Delete(log); log.Delete();
installForm?.UpdateUser($"Deleted log: {Path.GetFileName(log)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted log: {Path.GetFileName(log)}", LogTextBox.Action, false);
} }
}); });
@ -113,22 +113,22 @@ internal static class UplayR1
=> await Task.Run(() => => await Task.Run(() =>
{ {
directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out _, out _); directory.GetUplayR1Components(out string api32, out string api32_o, out string api64, out string api64_o, out _, out _);
if (File.Exists(api32) && !File.Exists(api32_o)) if (api32.Exists(form: installForm) && !api32_o.Exists(form: installForm))
{ {
File.Move(api32, api32_o!); api32.Move(api32_o!);
installForm?.UpdateUser($"Renamed Uplay R1: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false); installForm?.UpdateUser($"Renamed Uplay R1: {Path.GetFileName(api32)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false);
} }
if (File.Exists(api32_o)) if (api32_o.Exists(form: installForm))
{ {
"UplayR1.uplay_r1_loader.dll".Write(api32); "UplayR1.uplay_r1_loader.dll".Write(api32);
installForm?.UpdateUser($"Wrote Uplay R1 Unlocker: {Path.GetFileName(api32)}", LogTextBox.Action, false); installForm?.UpdateUser($"Wrote Uplay R1 Unlocker: {Path.GetFileName(api32)}", LogTextBox.Action, false);
} }
if (File.Exists(api64) && !File.Exists(api64_o)) if (api64.Exists(form: installForm) && !api64_o.Exists(form: installForm))
{ {
File.Move(api64, api64_o!); api64.Move(api64_o!);
installForm?.UpdateUser($"Renamed Uplay R1: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false); installForm?.UpdateUser($"Renamed Uplay R1: {Path.GetFileName(api64)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false);
} }
if (File.Exists(api64_o)) if (api64_o.Exists(form: installForm))
{ {
"UplayR1.uplay_r1_loader64.dll".Write(api64); "UplayR1.uplay_r1_loader64.dll".Write(api64);
installForm?.UpdateUser($"Wrote Uplay R1 Unlocker: {Path.GetFileName(api64)}", LogTextBox.Action, false); installForm?.UpdateUser($"Wrote Uplay R1 Unlocker: {Path.GetFileName(api64)}", LogTextBox.Action, false);

View file

@ -35,15 +35,15 @@ internal static class UplayR2
{ {
/*if (installForm is not null) /*if (installForm is not null)
installForm.UpdateUser("Generating Uplay R2 Unlocker configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation);*/ installForm.UpdateUser("Generating Uplay R2 Unlocker configuration for " + selection.Name + $" in directory \"{directory}\" . . . ", LogTextBox.Operation);*/
File.Create(config).Close(); config.Create(true, installForm);
StreamWriter writer = new(config, true, Encoding.UTF8); StreamWriter writer = new(config, true, Encoding.UTF8);
WriteConfig(writer, new(blacklistDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), installForm); WriteConfig(writer, new(blacklistDlc.ToDictionary(pair => pair.Key, pair => pair.Value), PlatformIdComparer.String), installForm);
writer.Flush(); writer.Flush();
writer.Close(); writer.Close();
} }
else if (File.Exists(config)) else if (config.Exists(form: installForm))
{ {
File.Delete(config); config.Delete();
installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted unnecessary configuration: {Path.GetFileName(config)}", LogTextBox.Action, false);
} }
} }
@ -80,38 +80,38 @@ internal static class UplayR2
{ {
directory.GetUplayR2Components(out string old_api32, out string old_api64, out string api32, out string api32_o, out string api64, 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); out string api64_o, out string config, out string log);
if (File.Exists(api32_o)) if (api32_o.Exists(form: installForm))
{ {
string api = File.Exists(old_api32) ? old_api32 : api32; string api = old_api32.Exists(form: installForm) ? old_api32 : api32;
if (File.Exists(api)) if (api.Exists(form: installForm))
{ {
File.Delete(api); api.Delete();
installForm?.UpdateUser($"Deleted Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false);
} }
File.Move(api32_o, api!); api32_o.Move(api!);
installForm?.UpdateUser($"Restored Uplay R2: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api)}", LogTextBox.Action, false); installForm?.UpdateUser($"Restored Uplay R2: {Path.GetFileName(api32_o)} -> {Path.GetFileName(api)}", LogTextBox.Action, false);
} }
if (File.Exists(api64_o)) if (api64_o.Exists(form: installForm))
{ {
string api = File.Exists(old_api64) ? old_api64 : api64; string api = old_api64.Exists(form: installForm) ? old_api64 : api64;
if (File.Exists(api)) if (api.Exists(form: installForm))
{ {
File.Delete(api); api.Delete();
installForm?.UpdateUser($"Deleted Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false);
} }
File.Move(api64_o, api!); api64_o.Move(api!);
installForm?.UpdateUser($"Restored Uplay R2: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api)}", LogTextBox.Action, false); installForm?.UpdateUser($"Restored Uplay R2: {Path.GetFileName(api64_o)} -> {Path.GetFileName(api)}", LogTextBox.Action, false);
} }
if (!deleteOthers) if (!deleteOthers)
return; return;
if (File.Exists(config)) if (config.Exists(form: installForm))
{ {
File.Delete(config); config.Delete();
installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false); installForm?.UpdateUser($"Deleted configuration: {Path.GetFileName(config)}", LogTextBox.Action, false);
} }
if (File.Exists(log)) if (log.Exists(form: installForm))
{ {
File.Delete(log); log.Delete();
installForm?.UpdateUser($"Deleted log: {Path.GetFileName(log)}", LogTextBox.Action, false); 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, 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 _); out string api64_o, out _, out _);
string api = File.Exists(old_api32) ? old_api32 : api32; string api = old_api32.Exists(form: installForm) ? old_api32 : api32;
if (File.Exists(api) && !File.Exists(api32_o)) if (api.Exists(form: installForm) && !api32_o.Exists(form: installForm))
{ {
File.Move(api, api32_o!); api.Move(api32_o!);
installForm?.UpdateUser($"Renamed Uplay R2: {Path.GetFileName(api)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false); installForm?.UpdateUser($"Renamed Uplay R2: {Path.GetFileName(api)} -> {Path.GetFileName(api32_o)}", LogTextBox.Action, false);
} }
if (File.Exists(api32_o)) if (api32_o.Exists(form: installForm))
{ {
"UplayR2.upc_r2_loader.dll".Write(api); "UplayR2.upc_r2_loader.dll".Write(api);
installForm?.UpdateUser($"Wrote Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false); installForm?.UpdateUser($"Wrote Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false);
} }
api = File.Exists(old_api64) ? old_api64 : api64; api = old_api64.Exists(form: installForm) ? old_api64 : api64;
if (File.Exists(api) && !File.Exists(api64_o)) if (api.Exists(form: installForm) && !api64_o.Exists(form: installForm))
{ {
File.Move(api, api64_o!); api.Move(api64_o!);
installForm?.UpdateUser($"Renamed Uplay R2: {Path.GetFileName(api)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false); installForm?.UpdateUser($"Renamed Uplay R2: {Path.GetFileName(api)} -> {Path.GetFileName(api64_o)}", LogTextBox.Action, false);
} }
if (File.Exists(api64_o)) if (api64_o.Exists(form: installForm))
{ {
"UplayR2.upc_r2_loader64.dll".Write(api); "UplayR2.upc_r2_loader64.dll".Write(api);
installForm?.UpdateUser($"Wrote Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false); installForm?.UpdateUser($"Wrote Uplay R2 Unlocker: {Path.GetFileName(api)}", LogTextBox.Action, false);

View file

@ -7,28 +7,28 @@ namespace CreamInstaller.Utility;
internal static class Diagnostics internal static class Diagnostics
{ {
private static string notepadPlusPlusPath; private static string nppPath;
internal static string NotepadPlusPlusPath private static string NppPath
{ {
get get
{ {
notepadPlusPlusPath ??= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Notepad++", "", null) as string; nppPath ??= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Notepad++", "", null) as string;
notepadPlusPlusPath ??= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432NODE\Notepad++", "", null) as string; nppPath ??= Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432NODE\Notepad++", "", null) as string;
return notepadPlusPlusPath; return nppPath;
} }
} }
internal static string GetNotepadPath() internal static string GetNotepadPath()
{ {
string npp = NotepadPlusPlusPath + @"\notepad++.exe"; string npp = NppPath + @"\notepad++.exe";
return File.Exists(npp) ? npp : Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\notepad.exe"; return npp.Exists() ? npp : Environment.GetFolderPath(Environment.SpecialFolder.Windows) + @"\notepad.exe";
} }
internal static void OpenFileInNotepad(string path) internal static void OpenFileInNotepad(string path)
{ {
string npp = NotepadPlusPlusPath + @"\notepad++.exe"; string npp = NppPath + @"\notepad++.exe";
if (File.Exists(npp)) if (npp.Exists())
OpenFileInNotepadPlusPlus(npp, path); OpenFileInNotepadPlusPlus(npp, path);
else else
OpenFileInWindowsNotepad(path); OpenFileInWindowsNotepad(path);

View file

@ -24,9 +24,8 @@ internal static class ExceptionHandler
if (stackTrace is not null && stackTrace.Length > 0) if (stackTrace is not null && stackTrace.Length > 0)
{ {
_ = output.Append(e.GetType() + (": " + e.Message)); _ = output.Append(e.GetType() + (": " + e.Message));
for (int i = 0; i < stackTrace.Length; i++) foreach (string line in stackTrace)
{ {
string line = stackTrace[i];
int atNum = line.IndexOf("at ", StringComparison.Ordinal); int atNum = line.IndexOf("at ", StringComparison.Ordinal);
int inNum = line.IndexOf("in ", StringComparison.Ordinal); int inNum = line.IndexOf("in ", StringComparison.Ordinal);
int ciNum = line.LastIndexOf(@"CreamInstaller\", StringComparison.Ordinal); int ciNum = line.LastIndexOf(@"CreamInstaller\", StringComparison.Ordinal);
@ -42,26 +41,24 @@ internal static class ExceptionHandler
e = e.InnerException; e = e.InnerException;
stackDepth++; stackDepth++;
} }
string outputString = output.ToString();
if (string.IsNullOrWhiteSpace(outputString))
outputString = e?.ToString() ?? "Unknown exception";
using DialogForm dialogForm = new(form ?? Form.ActiveForm); using DialogForm dialogForm = new(form ?? Form.ActiveForm);
return dialogForm.Show(SystemIcons.Error, output.ToString(), acceptButtonText, cancelButtonText, caption) == DialogResult.OK; return dialogForm.Show(SystemIcons.Error, outputString, acceptButtonText, cancelButtonText, caption) == DialogResult.OK;
} }
internal static void HandleFatalException(this Exception e) internal static void HandleFatalException(this Exception e)
{ {
bool? restart = e?.HandleException(caption: Program.Name + " encountered a fatal exception", acceptButtonText: "Restart"); e.HandleException(caption: Program.Name + " encountered a fatal exception", acceptButtonText: "OK", cancelButtonText: null);
if (restart.HasValue && restart.Value)
Application.Restart();
Application.Exit(); Application.Exit();
} }
} }
public class CustomMessageException : Exception public class CustomMessageException : Exception
{ {
public CustomMessageException() => Message = "CustomMessageException";
public CustomMessageException(string message) : base(message) => Message = message; public CustomMessageException(string message) : base(message) => Message = message;
public CustomMessageException(string message, Exception e) : base(message, e) => Message = message;
public override string Message { get; } public override string Message { get; }
public override string ToString() => Message; public override string ToString() => Message;

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.IO;
namespace CreamInstaller.Utility; namespace CreamInstaller.Utility;
@ -8,7 +7,7 @@ internal static class IconGrabber
{ {
internal const string SteamAppImagesPath = "https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/"; internal const string SteamAppImagesPath = "https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/";
internal const string GoogleFaviconsApiUrl = "https://www.google.com/s2/favicons"; private const string GoogleFaviconsApiUrl = "https://www.google.com/s2/favicons";
internal static Icon ToIcon(this Image image) internal static Icon ToIcon(this Image image)
{ {
@ -18,7 +17,7 @@ internal static class IconGrabber
internal static string GetDomainFaviconUrl(string domain, int size = 16) => GoogleFaviconsApiUrl + $"?domain={domain}&sz={size}"; internal static string GetDomainFaviconUrl(string domain, int size = 16) => GoogleFaviconsApiUrl + $"?domain={domain}&sz={size}";
internal static Image GetFileIconImage(this string path) => File.Exists(path) ? Icon.ExtractAssociatedIcon(path)?.ToBitmap() : null; internal static Image GetFileIconImage(this string path) => path.Exists() ? Icon.ExtractAssociatedIcon(path)?.ToBitmap() : null;
internal static Image GetNotepadImage() => GetFileIconImage(Diagnostics.GetNotepadPath()); internal static Image GetNotepadImage() => GetFileIconImage(Diagnostics.GetNotepadPath());

View file

@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace CreamInstaller.Utility; namespace CreamInstaller.Utility;
@ -27,7 +27,7 @@ internal static class ProgramData
private static readonly string DlcChoicesPath = DirectoryPath + @"\dlc.json"; private static readonly string DlcChoicesPath = DirectoryPath + @"\dlc.json";
private static readonly string KoaloaderProxyChoicesPath = DirectoryPath + @"\proxies.json"; private static readonly string KoaloaderProxyChoicesPath = DirectoryPath + @"\proxies.json";
internal static async Task Setup() internal static async Task Setup(Form form = null)
=> await Task.Run(() => => await Task.Run(() =>
{ {
if (Directory.Exists(DirectoryPathOld)) if (Directory.Exists(DirectoryPathOld))
@ -38,18 +38,17 @@ internal static class ProgramData
} }
if (!Directory.Exists(DirectoryPath)) if (!Directory.Exists(DirectoryPath))
_ = Directory.CreateDirectory(DirectoryPath); _ = Directory.CreateDirectory(DirectoryPath);
if (!File.Exists(AppInfoVersionPath) || !Version.TryParse(File.ReadAllText(AppInfoVersionPath, Encoding.UTF8), out Version version) if (!AppInfoVersionPath.Exists(form: form) || !Version.TryParse(AppInfoVersionPath.Read(), out Version version) || version < MinimumAppInfoVersion)
|| version < MinimumAppInfoVersion)
{ {
if (Directory.Exists(AppInfoPath)) if (Directory.Exists(AppInfoPath))
Directory.Delete(AppInfoPath, true); Directory.Delete(AppInfoPath, true);
_ = Directory.CreateDirectory(AppInfoPath); _ = Directory.CreateDirectory(AppInfoPath);
File.WriteAllText(AppInfoVersionPath, Program.Version, Encoding.UTF8); AppInfoVersionPath.Write(Program.Version);
} }
if (!Directory.Exists(CooldownPath)) if (!Directory.Exists(CooldownPath))
_ = Directory.CreateDirectory(CooldownPath); _ = Directory.CreateDirectory(CooldownPath);
if (File.Exists(OldProgramChoicesPath)) if (OldProgramChoicesPath.Exists(form: form))
File.Delete(OldProgramChoicesPath); OldProgramChoicesPath.Delete();
}); });
internal static bool CheckCooldown(string identifier, int cooldown) internal static bool CheckCooldown(string identifier, int cooldown)
@ -67,11 +66,11 @@ internal static class ProgramData
if (!Directory.Exists(CooldownPath)) if (!Directory.Exists(CooldownPath))
return null; return null;
string cooldownFile = CooldownPath + @$"\{identifier}.txt"; string cooldownFile = CooldownPath + @$"\{identifier}.txt";
if (!File.Exists(cooldownFile)) if (!cooldownFile.Exists())
return null; return null;
try try
{ {
if (DateTime.TryParse(File.ReadAllText(cooldownFile), out DateTime cooldown)) if (DateTime.TryParse(cooldownFile.Read(), out DateTime cooldown))
return cooldown; return cooldown;
} }
catch catch
@ -88,7 +87,7 @@ internal static class ProgramData
string cooldownFile = CooldownPath + @$"\{identifier}.txt"; string cooldownFile = CooldownPath + @$"\{identifier}.txt";
try try
{ {
File.WriteAllText(cooldownFile, time.ToString(CultureInfo.InvariantCulture)); cooldownFile.Write(time.ToString(CultureInfo.InvariantCulture));
} }
catch catch
{ {
@ -98,17 +97,18 @@ internal static class ProgramData
internal static IEnumerable<(Platform platform, string id)> ReadProgramChoices() internal static IEnumerable<(Platform platform, string id)> ReadProgramChoices()
{ {
if (!File.Exists(ProgramChoicesPath)) if (ProgramChoicesPath.Exists())
return Enumerable.Empty<(Platform platform, string id)>();
try try
{ {
return JsonConvert.DeserializeObject(File.ReadAllText(ProgramChoicesPath), typeof(List<(Platform platform, string id)>)) as if (JsonConvert.DeserializeObject(ProgramChoicesPath.Read(), typeof(List<(Platform platform, string id)>)) is
List<(Platform platform, string id)>; List<(Platform platform, string id)> choices)
return choices;
} }
catch catch
{ {
return Enumerable.Empty<(Platform platform, string id)>(); // ignored
} }
return Enumerable.Empty<(Platform platform, string id)>();
} }
internal static void WriteProgramChoices(IEnumerable<(Platform platform, string id)> choices) internal static void WriteProgramChoices(IEnumerable<(Platform platform, string id)> choices)
@ -116,9 +116,9 @@ internal static class ProgramData
try try
{ {
if (choices is null || !choices.Any()) if (choices is null || !choices.Any())
File.Delete(ProgramChoicesPath); ProgramChoicesPath.Delete();
else else
File.WriteAllText(ProgramChoicesPath, JsonConvert.SerializeObject(choices)); ProgramChoicesPath.Write(JsonConvert.SerializeObject(choices));
} }
catch catch
{ {
@ -128,17 +128,18 @@ internal static class ProgramData
internal static IEnumerable<(Platform platform, string gameId, string dlcId)> ReadDlcChoices() internal static IEnumerable<(Platform platform, string gameId, string dlcId)> ReadDlcChoices()
{ {
if (!File.Exists(DlcChoicesPath)) if (DlcChoicesPath.Exists())
return Enumerable.Empty<(Platform platform, string gameId, string dlcId)>();
try try
{ {
return JsonConvert.DeserializeObject(File.ReadAllText(DlcChoicesPath), typeof(IEnumerable<(Platform platform, string gameId, string dlcId)>)) as if (JsonConvert.DeserializeObject(DlcChoicesPath.Read(), typeof(IEnumerable<(Platform platform, string gameId, string dlcId)>)) is
IEnumerable<(Platform platform, string gameId, string dlcId)>; IEnumerable<(Platform platform, string gameId, string dlcId)> choices)
return choices;
} }
catch catch
{ {
return Enumerable.Empty<(Platform platform, string gameId, string dlcId)>(); // ignored
} }
return Enumerable.Empty<(Platform platform, string gameId, string dlcId)>();
} }
internal static void WriteDlcChoices(List<(Platform platform, string gameId, string dlcId)> choices) internal static void WriteDlcChoices(List<(Platform platform, string gameId, string dlcId)> choices)
@ -146,9 +147,9 @@ internal static class ProgramData
try try
{ {
if (choices is null || !choices.Any()) if (choices is null || !choices.Any())
File.Delete(DlcChoicesPath); DlcChoicesPath.Delete();
else else
File.WriteAllText(DlcChoicesPath, JsonConvert.SerializeObject(choices)); DlcChoicesPath.Write(JsonConvert.SerializeObject(choices));
} }
catch catch
{ {
@ -158,18 +159,19 @@ internal static class ProgramData
internal static IEnumerable<(Platform platform, string id, string proxy, bool enabled)> ReadKoaloaderChoices() internal static IEnumerable<(Platform platform, string id, string proxy, bool enabled)> ReadKoaloaderChoices()
{ {
if (!File.Exists(KoaloaderProxyChoicesPath)) if (KoaloaderProxyChoicesPath.Exists())
return Enumerable.Empty<(Platform platform, string id, string proxy, bool enabled)>();
try try
{ {
return JsonConvert.DeserializeObject(File.ReadAllText(KoaloaderProxyChoicesPath), if (JsonConvert.DeserializeObject(KoaloaderProxyChoicesPath.Read(),
typeof(IEnumerable<(Platform platform, string id, string proxy, bool enabled)>)) as typeof(IEnumerable<(Platform platform, string id, string proxy, bool enabled)>)) is
IEnumerable<(Platform platform, string id, string proxy, bool enabled)>; IEnumerable<(Platform platform, string id, string proxy, bool enabled)> choices)
return choices;
} }
catch catch
{ {
return Enumerable.Empty<(Platform platform, string id, string proxy, bool enabled)>(); // ignored
} }
return Enumerable.Empty<(Platform platform, string id, string proxy, bool enabled)>();
} }
internal static void WriteKoaloaderProxyChoices(IEnumerable<(Platform platform, string id, string proxy, bool enabled)> choices) internal static void WriteKoaloaderProxyChoices(IEnumerable<(Platform platform, string id, string proxy, bool enabled)> choices)
@ -177,9 +179,9 @@ internal static class ProgramData
try try
{ {
if (choices is null || !choices.Any()) if (choices is null || !choices.Any())
File.Delete(KoaloaderProxyChoicesPath); KoaloaderProxyChoicesPath.Delete();
else else
File.WriteAllText(KoaloaderProxyChoicesPath, JsonConvert.SerializeObject(choices)); KoaloaderProxyChoicesPath.Write(JsonConvert.SerializeObject(choices));
} }
catch catch
{ {

View file

@ -0,0 +1,119 @@
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using CreamInstaller.Forms;
namespace CreamInstaller.Utility;
internal static class SafeIO
{
internal static bool Exists(this string filePath, bool crucial = false, Form form = null)
{
while (!Program.Canceled)
{
bool exists = File.Exists(filePath);
if (exists || !crucial || filePath.Warn("Failed to find a crucial file", form) is not DialogResult.OK)
return exists;
}
return false;
}
internal static void Create(this string filePath, bool crucial = false, Form form = null)
{
while (!Program.Canceled)
try
{
File.Create(filePath).Close();
break;
}
catch
{
if (!crucial || filePath.Warn("Failed to create a crucial file", form) is not DialogResult.OK)
break;
}
}
internal static void Move(this string filePath, string newFilePath, bool crucial = false, Form form = null)
{
while (!Program.Canceled)
try
{
File.Move(filePath, newFilePath);
break;
}
catch
{
if (!crucial || !filePath.Exists(true) || filePath.Warn("Failed to move a crucial file", form) is not DialogResult.OK)
break;
}
}
internal static void Delete(this string filePath, bool crucial = false, Form form = null)
{
if (!filePath.Exists(form: form))
return;
while (!Program.Canceled)
try
{
File.Delete(filePath);
break;
}
catch
{
if (!crucial || filePath.Warn("Failed to delete a crucial file", form) is not DialogResult.OK)
break;
}
}
internal static string Read(this string filePath, bool crucial = false, Form form = null)
{
while (!Program.Canceled)
try
{
return File.ReadAllText(filePath, Encoding.UTF8);
}
catch
{
if (!crucial || !filePath.Exists(true) || filePath.Warn("Failed to read a crucial file", form) is not DialogResult.OK)
break;
}
return null;
}
internal static byte[] ReadBytes(this string filePath, bool crucial = false, Form form = null)
{
while (!Program.Canceled)
try
{
return File.ReadAllBytes(filePath);
}
catch
{
if (!crucial || !filePath.Exists(true) || filePath.Warn("Failed to read a crucial file", form) is not DialogResult.OK)
break;
}
return null;
}
internal static void Write(this string filePath, string text, bool crucial = false, Form form = null)
{
while (!Program.Canceled)
try
{
File.WriteAllText(filePath, text, Encoding.UTF8);
break;
}
catch
{
if (!crucial || filePath.Warn("Failed to write a crucial file", form) is not DialogResult.OK)
break;
}
}
private static DialogResult Warn(this string filePath, string message, Form form = null)
{
using DialogForm dialogForm = new(form ?? Form.ActiveForm);
return dialogForm.Show(SystemIcons.Warning, message + ": " + filePath.BeautifyPath(), "Retry", "OK");
}
}