From 2c9943fe927be51eb34e2aa0028ab8d4eda0fd3e Mon Sep 17 00:00:00 2001 From: pointfeev Date: Fri, 22 Oct 2021 16:27:53 -0400 Subject: [PATCH] better exception handling, fix error for outdated creamAPI files --- CreamInstaller/CreamInstaller.csproj | 6 +++--- CreamInstaller/DialogForm.cs | 2 +- CreamInstaller/InstallForm.cs | 30 ++++++++++++++++++++-------- CreamInstaller/LogColor.cs | 2 +- CreamInstaller/MainForm.cs | 2 +- CreamInstaller/Program.cs | 2 +- CreamInstaller/ProgramSelection.cs | 2 +- CreamInstaller/SelectForm.cs | 20 +++++++++++-------- 8 files changed, 42 insertions(+), 24 deletions(-) diff --git a/CreamInstaller/CreamInstaller.csproj b/CreamInstaller/CreamInstaller.csproj index 7552040..a8c99c6 100644 --- a/CreamInstaller/CreamInstaller.csproj +++ b/CreamInstaller/CreamInstaller.csproj @@ -6,7 +6,7 @@ true ini.ico true - 1.0.6.3 + 1.0.6.4 ini.ico Automatically downloads and installs CreamAPI files for programs/games. @@ -26,8 +26,8 @@ - none - false + full + true diff --git a/CreamInstaller/DialogForm.cs b/CreamInstaller/DialogForm.cs index df222b6..c1a0ef2 100644 --- a/CreamInstaller/DialogForm.cs +++ b/CreamInstaller/DialogForm.cs @@ -21,4 +21,4 @@ namespace CreamInstaller return ShowDialog(); } } -} +} \ No newline at end of file diff --git a/CreamInstaller/InstallForm.cs b/CreamInstaller/InstallForm.cs index 955dd0c..76bdfd3 100644 --- a/CreamInstaller/InstallForm.cs +++ b/CreamInstaller/InstallForm.cs @@ -10,6 +10,19 @@ using System.Windows.Forms; namespace CreamInstaller { + public class CustomMessageException : Exception + { + private string message; + public override string Message => message ?? "CustomMessageException"; + + public override string ToString() => Message; + + public CustomMessageException(string message) + { + this.message = message; + } + } + public partial class InstallForm : Form { public bool Reselecting = false; @@ -25,6 +38,7 @@ namespace CreamInstaller private int OperationsCount; private int CompleteOperationsCount; + public void UpdateProgress(int progress) { int value = (int)((float)(CompleteOperationsCount / (float)OperationsCount) * 100) + (progress / OperationsCount); @@ -59,7 +73,7 @@ namespace CreamInstaller } catch { - throw new Exception($"Unable to delete old archive file: {Program.OutputFile}"); + throw new CustomMessageException($"Unable to delete old archive file: {Program.OutputFile}"); } } Progress progress = new Progress(delegate (double progress) @@ -101,7 +115,7 @@ namespace CreamInstaller } if (resources.Count < 1) { - throw new Exception($"Unable to find CreamAPI files in downloaded archive: {Program.OutputFile}"); + throw new CustomMessageException($"Unable to find CreamAPI files in downloaded archive: {Program.OutputFile}"); } if (!Program.IsProgramRunningDialog(this, selection)) { @@ -151,7 +165,7 @@ namespace CreamInstaller UpdateUser("Reversed changes to Steam API file: " + file, LogColor.Warning); } } - throw new Exception($"Unable to overwrite Steam API file: {file}"); + throw new CustomMessageException($"Unable to overwrite Steam API file: {file}"); } UpdateUser("Installed file: " + file, LogColor.Resource); UpdateProgress((currentFileCount / (resources.Count * selection.SteamApiDllDirectories.Count)) * 100); @@ -199,7 +213,7 @@ namespace CreamInstaller } catch (Exception exception) { - UpdateUser($"Operation failed for {selection.ProgramName}: " + exception.Message, LogColor.Error); + UpdateUser($"Operation failed for {selection.ProgramName}: " + exception.ToString(), LogColor.Error); } ++CompleteOperationsCount; @@ -212,11 +226,11 @@ namespace CreamInstaller { if (FailedSelections.Count == 1) { - throw new Exception($"Operation failed for {FailedSelections.First().ProgramName}."); + throw new CustomMessageException($"Operation failed for {FailedSelections.First().ProgramName}."); } else { - throw new Exception($"Operation failed for {FailedSelections.Count} programs."); + throw new CustomMessageException($"Operation failed for {FailedSelections.Count} programs."); } } } @@ -238,7 +252,7 @@ namespace CreamInstaller } catch (Exception exception) { - UpdateUser("CreamAPI download and/or installation failed: " + exception.Message, LogColor.Error); + UpdateUser("CreamAPI download and/or installation failed: " + exception.ToString(), LogColor.Error); retryButton.Enabled = true; } userProgressBar.Value = userProgressBar.Maximum; @@ -278,4 +292,4 @@ namespace CreamInstaller Close(); } } -} +} \ No newline at end of file diff --git a/CreamInstaller/LogColor.cs b/CreamInstaller/LogColor.cs index 7fe9bec..392bd32 100644 --- a/CreamInstaller/LogColor.cs +++ b/CreamInstaller/LogColor.cs @@ -22,4 +22,4 @@ namespace CreamInstaller logTextBox.SelectionColor = logTextBox.ForeColor; } } -} +} \ No newline at end of file diff --git a/CreamInstaller/MainForm.cs b/CreamInstaller/MainForm.cs index 60958f0..9190a1d 100644 --- a/CreamInstaller/MainForm.cs +++ b/CreamInstaller/MainForm.cs @@ -171,4 +171,4 @@ namespace CreamInstaller updateManager = null; } } -} +} \ No newline at end of file diff --git a/CreamInstaller/Program.cs b/CreamInstaller/Program.cs index a8d6ddc..98f304e 100644 --- a/CreamInstaller/Program.cs +++ b/CreamInstaller/Program.cs @@ -138,4 +138,4 @@ namespace CreamInstaller Cleanup(); } } -} +} \ No newline at end of file diff --git a/CreamInstaller/ProgramSelection.cs b/CreamInstaller/ProgramSelection.cs index 71615f1..5c35469 100644 --- a/CreamInstaller/ProgramSelection.cs +++ b/CreamInstaller/ProgramSelection.cs @@ -38,4 +38,4 @@ namespace CreamInstaller this.Enabled = Enabled; } } -} +} \ No newline at end of file diff --git a/CreamInstaller/SelectForm.cs b/CreamInstaller/SelectForm.cs index 72a97c1..b011585 100644 --- a/CreamInstaller/SelectForm.cs +++ b/CreamInstaller/SelectForm.cs @@ -99,6 +99,7 @@ namespace CreamInstaller } private readonly List checkBoxes = new(); + private void GetCreamApiApplicablePrograms(IProgress progress) { if (Program.Canceled) { return; } @@ -152,21 +153,24 @@ namespace CreamInstaller { if (Program.Canceled) { return; } - ProgramSelection selection = new(); - selection.ProgramName = node.Name; - selection.ProgramDirectory = rootDirectory; - selection.SteamApiDllDirectories = new(); - selection.SteamApiDllDirectories.AddRange(directories); - + INode downloadNode = null; foreach (INode _node in fileNodes) { if (_node.Type == NodeType.File && _node.ParentId == node.Id) { - selection.DownloadNode = _node; + downloadNode = _node; break; } } + if (downloadNode is null) return; + ProgramSelection selection = new(); + selection.DownloadNode = downloadNode; + selection.ProgramName = node.Name; + selection.ProgramDirectory = rootDirectory; + selection.SteamApiDllDirectories = new(); + selection.SteamApiDllDirectories.AddRange(directories); + CheckBox checkBox = new(); checkBoxes.Add(checkBox); checkBox.AutoSize = true; @@ -324,4 +328,4 @@ namespace CreamInstaller allCheckBox.Checked = shouldCheck; } } -} +} \ No newline at end of file