diff --git a/CreamInstaller/InstallForm.cs b/CreamInstaller/InstallForm.cs index fb037ac..2d34d0a 100644 --- a/CreamInstaller/InstallForm.cs +++ b/CreamInstaller/InstallForm.cs @@ -1,12 +1,12 @@ using System; +using System.Collections.Generic; +using System.Drawing; using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; -using System.Threading; -using System.IO.Compression; -using System.Collections.Generic; -using System.Linq; -using System.Drawing; namespace CreamInstaller { @@ -34,7 +34,10 @@ namespace CreamInstaller if (log && !logTextBox.IsDisposed) { if (logTextBox.Text.Length > 0) + { logTextBox.AppendText(Environment.NewLine, color); + } + logTextBox.AppendText(userInfoLabel.Text, color); } } @@ -102,7 +105,9 @@ namespace CreamInstaller UpdateProgress(100); if (!Program.IsProgramRunningDialog(this, selection)) + { throw new OperationCanceledException(); + } UpdateProgress(0); UpdateUser("Installing CreamAPI files for " + selection.ProgramName + " . . . ", LogColor.Operation); @@ -159,7 +164,9 @@ namespace CreamInstaller string file = keyValuePair.Key; string backup = keyValuePair.Value; if (!string.IsNullOrEmpty(backup)) + { File.Delete(backup); + } } } UpdateProgress(100); @@ -170,12 +177,16 @@ namespace CreamInstaller foreach (ProgramSelection selection in Program.ProgramSelections.ToList()) { if (Program.Canceled) + { break; + } Program.Cleanup(cancel: false, logout: false); if (!Program.IsProgramRunningDialog(this, selection)) + { throw new OperationCanceledException(); + } try { @@ -202,7 +213,7 @@ namespace CreamInstaller } } - private int ProgramCount = Program.ProgramSelections.Count; + private readonly int ProgramCount = Program.ProgramSelections.Count; private async void Start() { diff --git a/CreamInstaller/MainForm.cs b/CreamInstaller/MainForm.cs index b467ea2..b2b6590 100644 --- a/CreamInstaller/MainForm.cs +++ b/CreamInstaller/MainForm.cs @@ -1,12 +1,12 @@ -using System; +using CG.Web.MegaApiClient; +using Onova; +using Onova.Models; +using Onova.Services; +using System; using System.Drawing; using System.IO; using System.Threading; using System.Windows.Forms; -using CG.Web.MegaApiClient; -using Onova; -using Onova.Models; -using Onova.Services; namespace CreamInstaller { @@ -28,7 +28,7 @@ namespace CreamInstaller cancellationTokenSource.Dispose(); cancellationTokenSource = null; } - + Hide(); new SelectForm(this).ShowDialog(); Close(); @@ -60,7 +60,9 @@ namespace CreamInstaller cancellationTokenSource.Dispose(); cancellationTokenSource = null; if (checkForUpdatesResult.CanUpdate) + { latestVersion = checkForUpdatesResult.LastVersion; + } } catch { } } diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index 3dc28ff..819c501 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -24,10 +24,9 @@ namespace CreamInstaller public static string BackupFileExtension = ".creaminstaller.backup"; [STAThread] - static void Main() + private static void Main() { - bool createdNew = true; - Mutex mutex = new Mutex(true, "CreamInstaller", out createdNew); + Mutex mutex = new Mutex(true, "CreamInstaller", out bool createdNew); if (createdNew) { Application.SetHighDpiMode(HighDpiMode.SystemAware); @@ -47,7 +46,9 @@ namespace CreamInstaller $"ERROR: {selection.ProgramName} is currently running!" + "\n\nPlease close the program/game to continue . . .", "Retry", "Cancel") == DialogResult.OK) + { return IsProgramRunningDialog(form, selection); + } } else { diff --git a/CreamInstaller/ProgramSelection.cs b/CreamInstaller/ProgramSelection.cs index bc1438b..9757d21 100644 --- a/CreamInstaller/ProgramSelection.cs +++ b/CreamInstaller/ProgramSelection.cs @@ -18,7 +18,9 @@ namespace CreamInstaller { string file = directory + "\\steam_api64.dll"; if (file.IsFilePathLocked()) + { return true; + } } return false; } @@ -32,13 +34,17 @@ namespace CreamInstaller public void Add() { if (!Program.ProgramSelections.Contains(this)) + { Program.ProgramSelections.Add(this); + } } public void Remove() { if (Program.ProgramSelections.Contains(this)) + { Program.ProgramSelections.Remove(this); + } } } } diff --git a/CreamInstaller/SelectForm.cs b/CreamInstaller/SelectForm.cs index 326e882..69f75ee 100644 --- a/CreamInstaller/SelectForm.cs +++ b/CreamInstaller/SelectForm.cs @@ -1,14 +1,14 @@ -using System; -using System.Windows.Forms; -using CG.Web.MegaApiClient; -using System.Collections.Generic; -using System.IO; -using Microsoft.Win32; +using CG.Web.MegaApiClient; using Gameloop.Vdf; using Gameloop.Vdf.Linq; -using System.Threading.Tasks; +using Microsoft.Win32; +using System; +using System.Collections.Generic; using System.Drawing; +using System.IO; using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; namespace CreamInstaller { @@ -59,16 +59,25 @@ namespace CreamInstaller private List GetSteamApiDllDirectoriesFromGameDirectory(string gameDirectory, List steamApiDllDirectories = null) { if (steamApiDllDirectories is null) + { steamApiDllDirectories = new(); + } + string file = gameDirectory + "\\steam_api64.dll"; if (File.Exists(file)) + { steamApiDllDirectories.Add(gameDirectory); + } + foreach (string _directory in Directory.GetDirectories(gameDirectory)) { GetSteamApiDllDirectoriesFromGameDirectory(_directory, steamApiDllDirectories); } if (!steamApiDllDirectories.Any()) + { return null; + } + return steamApiDllDirectories; } @@ -93,7 +102,7 @@ namespace CreamInstaller return null; } - private List checkBoxes = new(); + private readonly List checkBoxes = new(); private void GetCreamApiApplicablePrograms(IProgress progress) { int maxProgress = 0; @@ -120,7 +129,9 @@ namespace CreamInstaller rootDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); string launcherDirectory = rootDirectory + "\\Programs\\Paradox Interactive"; if (Directory.Exists(launcherDirectory)) + { directories = GetSteamApiDllDirectoriesFromGameDirectory(launcherDirectory); + } } else { @@ -138,51 +149,51 @@ namespace CreamInstaller } if (!(directories is null)) { - flowLayoutPanel1.Invoke((MethodInvoker) delegate - { - ProgramSelection selection = new(); - selection.ProgramName = node.Name; - selection.ProgramDirectory = rootDirectory; - selection.SteamApiDllDirectories = new(); - selection.SteamApiDllDirectories.AddRange(directories); + flowLayoutPanel1.Invoke((MethodInvoker)delegate + { + ProgramSelection selection = new(); + selection.ProgramName = node.Name; + selection.ProgramDirectory = rootDirectory; + selection.SteamApiDllDirectories = new(); + selection.SteamApiDllDirectories.AddRange(directories); - foreach (INode _node in fileNodes) - { - if (_node.Type == NodeType.File && _node.ParentId == node.Id) - { - selection.DownloadNode = _node; - break; - } - } + foreach (INode _node in fileNodes) + { + if (_node.Type == NodeType.File && _node.ParentId == node.Id) + { + selection.DownloadNode = _node; + break; + } + } - CheckBox checkBox = new(); - checkBoxes.Add(checkBox); - checkBox.AutoSize = true; - checkBox.Parent = flowLayoutPanel1; - checkBox.Text = node.Name; - checkBox.Checked = true; - checkBox.Enabled = false; - checkBox.TabStop = true; - checkBox.TabIndex = 1 + checkBoxes.Count; + CheckBox checkBox = new(); + checkBoxes.Add(checkBox); + checkBox.AutoSize = true; + checkBox.Parent = flowLayoutPanel1; + checkBox.Text = node.Name; + checkBox.Checked = true; + checkBox.Enabled = false; + checkBox.TabStop = true; + checkBox.TabIndex = 1 + checkBoxes.Count; - checkBox.CheckedChanged += (sender, e) => - { - if (checkBox.Checked) - { - selection.Add(); - } - else - { - selection.Remove(); - } + checkBox.CheckedChanged += (sender, e) => + { + if (checkBox.Checked) + { + selection.Add(); + } + else + { + selection.Remove(); + } - acceptButton.Enabled = Program.ProgramSelections.Count > 0; + acceptButton.Enabled = Program.ProgramSelections.Count > 0; - allCheckBox.CheckedChanged -= OnAllCheckBoxChanged; - allCheckBox.Checked = checkBoxes.TrueForAll(checkBox => checkBox.Checked); - allCheckBox.CheckedChanged += OnAllCheckBoxChanged; - }; - }); + allCheckBox.CheckedChanged -= OnAllCheckBoxChanged; + allCheckBox.Checked = checkBoxes.TrueForAll(checkBox => checkBox.Checked); + allCheckBox.CheckedChanged += OnAllCheckBoxChanged; + }; + }); } } } @@ -202,7 +213,7 @@ namespace CreamInstaller } else { - int p = (int)((float)((float)_progress / (float)maxProgress) * 100); + int p = (int)((float)(_progress / (float)maxProgress) * 100); label2.Text = "Finding CreamAPI-applicable programs on your computer . . . " + p + "% (" + _progress + "/" + maxProgress + ")"; progressBar1.Value = p; } @@ -218,7 +229,9 @@ namespace CreamInstaller { allCheckBox.Enabled = true; foreach (CheckBox checkBox in checkBoxes) + { checkBox.Enabled = true; + } acceptButton.Enabled = true; } @@ -226,7 +239,7 @@ namespace CreamInstaller { noneFoundLabel.Visible = true; } - + } private void OnAccept(object sender, EventArgs e) @@ -236,7 +249,9 @@ namespace CreamInstaller foreach (ProgramSelection selection in Program.ProgramSelections) { if (!Program.IsProgramRunningDialog(this, selection)) + { return; + } } Hide(); @@ -254,7 +269,10 @@ namespace CreamInstaller Location = new Point(X, Y); Show(); } - else Close(); + else + { + Close(); + } } } @@ -267,10 +285,18 @@ namespace CreamInstaller { bool shouldCheck = false; foreach (CheckBox checkBox in checkBoxes) + { if (!checkBox.Checked) + { shouldCheck = true; + } + } + foreach (CheckBox checkBox in checkBoxes) + { checkBox.Checked = shouldCheck; + } + allCheckBox.Checked = shouldCheck; } }