better exception handling, fix error for outdated creamAPI files

This commit is contained in:
pointfeev 2021-10-22 16:27:53 -04:00
parent ace422e051
commit 2c9943fe92
No known key found for this signature in database
GPG key ID: AA14DC36C4D7D13C
8 changed files with 42 additions and 24 deletions

View file

@ -6,7 +6,7 @@
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<ApplicationIcon>ini.ico</ApplicationIcon> <ApplicationIcon>ini.ico</ApplicationIcon>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>1.0.6.3</Version> <Version>1.0.6.4</Version>
<PackageIcon>ini.ico</PackageIcon> <PackageIcon>ini.ico</PackageIcon>
<PackageIconUrl /> <PackageIconUrl />
<Description>Automatically downloads and installs CreamAPI files for programs/games.</Description> <Description>Automatically downloads and installs CreamAPI files for programs/games.</Description>
@ -26,8 +26,8 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType> <DebugType>full</DebugType>
<DebugSymbols>false</DebugSymbols> <DebugSymbols>true</DebugSymbols>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -21,4 +21,4 @@ namespace CreamInstaller
return ShowDialog(); return ShowDialog();
} }
} }
} }

View file

@ -10,6 +10,19 @@ using System.Windows.Forms;
namespace CreamInstaller 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 partial class InstallForm : Form
{ {
public bool Reselecting = false; public bool Reselecting = false;
@ -25,6 +38,7 @@ namespace CreamInstaller
private int OperationsCount; private int OperationsCount;
private int CompleteOperationsCount; private int CompleteOperationsCount;
public void UpdateProgress(int progress) public void UpdateProgress(int progress)
{ {
int value = (int)((float)(CompleteOperationsCount / (float)OperationsCount) * 100) + (progress / OperationsCount); int value = (int)((float)(CompleteOperationsCount / (float)OperationsCount) * 100) + (progress / OperationsCount);
@ -59,7 +73,7 @@ namespace CreamInstaller
} }
catch catch
{ {
throw new Exception($"Unable to delete old archive file: {Program.OutputFile}"); throw new CustomMessageException($"Unable to delete old archive file: {Program.OutputFile}");
} }
} }
Progress<double> progress = new Progress<double>(delegate (double progress) Progress<double> progress = new Progress<double>(delegate (double progress)
@ -101,7 +115,7 @@ namespace CreamInstaller
} }
if (resources.Count < 1) 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)) if (!Program.IsProgramRunningDialog(this, selection))
{ {
@ -151,7 +165,7 @@ namespace CreamInstaller
UpdateUser("Reversed changes to Steam API file: " + file, LogColor.Warning); 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); UpdateUser("Installed file: " + file, LogColor.Resource);
UpdateProgress((currentFileCount / (resources.Count * selection.SteamApiDllDirectories.Count)) * 100); UpdateProgress((currentFileCount / (resources.Count * selection.SteamApiDllDirectories.Count)) * 100);
@ -199,7 +213,7 @@ namespace CreamInstaller
} }
catch (Exception exception) catch (Exception exception)
{ {
UpdateUser($"Operation failed for {selection.ProgramName}: " + exception.Message, LogColor.Error); UpdateUser($"Operation failed for {selection.ProgramName}: " + exception.ToString(), LogColor.Error);
} }
++CompleteOperationsCount; ++CompleteOperationsCount;
@ -212,11 +226,11 @@ namespace CreamInstaller
{ {
if (FailedSelections.Count == 1) if (FailedSelections.Count == 1)
{ {
throw new Exception($"Operation failed for {FailedSelections.First().ProgramName}."); throw new CustomMessageException($"Operation failed for {FailedSelections.First().ProgramName}.");
} }
else 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) 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; retryButton.Enabled = true;
} }
userProgressBar.Value = userProgressBar.Maximum; userProgressBar.Value = userProgressBar.Maximum;
@ -278,4 +292,4 @@ namespace CreamInstaller
Close(); Close();
} }
} }
} }

View file

@ -22,4 +22,4 @@ namespace CreamInstaller
logTextBox.SelectionColor = logTextBox.ForeColor; logTextBox.SelectionColor = logTextBox.ForeColor;
} }
} }
} }

View file

@ -171,4 +171,4 @@ namespace CreamInstaller
updateManager = null; updateManager = null;
} }
} }
} }

View file

@ -138,4 +138,4 @@ namespace CreamInstaller
Cleanup(); Cleanup();
} }
} }
} }

View file

@ -38,4 +38,4 @@ namespace CreamInstaller
this.Enabled = Enabled; this.Enabled = Enabled;
} }
} }
} }

View file

@ -99,6 +99,7 @@ namespace CreamInstaller
} }
private readonly List<CheckBox> checkBoxes = new(); private readonly List<CheckBox> checkBoxes = new();
private void GetCreamApiApplicablePrograms(IProgress<int> progress) private void GetCreamApiApplicablePrograms(IProgress<int> progress)
{ {
if (Program.Canceled) { return; } if (Program.Canceled) { return; }
@ -152,21 +153,24 @@ namespace CreamInstaller
{ {
if (Program.Canceled) { return; } if (Program.Canceled) { return; }
ProgramSelection selection = new(); INode downloadNode = null;
selection.ProgramName = node.Name;
selection.ProgramDirectory = rootDirectory;
selection.SteamApiDllDirectories = new();
selection.SteamApiDllDirectories.AddRange(directories);
foreach (INode _node in fileNodes) foreach (INode _node in fileNodes)
{ {
if (_node.Type == NodeType.File && _node.ParentId == node.Id) if (_node.Type == NodeType.File && _node.ParentId == node.Id)
{ {
selection.DownloadNode = _node; downloadNode = _node;
break; 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(); CheckBox checkBox = new();
checkBoxes.Add(checkBox); checkBoxes.Add(checkBox);
checkBox.AutoSize = true; checkBox.AutoSize = true;
@ -324,4 +328,4 @@ namespace CreamInstaller
allCheckBox.Checked = shouldCheck; allCheckBox.Checked = shouldCheck;
} }
} }
} }