- Synchronized namespaces
- Code cleanup & refactoring
- Moved target OS version up to 10.0.22000.0 (7.0+ still supported)
This commit is contained in:
pointfeev 2022-02-06 20:17:51 -05:00
parent 0d4c1630d6
commit 3840aa9f1b
16 changed files with 52 additions and 63 deletions

View file

@ -1,16 +1,14 @@
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
namespace CreamInstaller; namespace CreamInstaller.Classes;
internal static class ExceptionHandler internal static class ExceptionHandler
{ {
internal static bool OutputException(Exception e) internal static bool OutputException(Exception e)
{ {
while (e.InnerException is not null) while (e.InnerException is not null)
{
e = e.InnerException; e = e.InnerException;
}
string output = ""; string output = "";
string[] stackTrace = e.StackTrace?.Split('\n'); string[] stackTrace = e.StackTrace?.Split('\n');
@ -21,27 +19,21 @@ internal static class ExceptionHandler
{ {
string line = stackTrace[i]; string line = stackTrace[i];
if (line is not null) if (line is not null)
{
output += "\n " + line[line.IndexOf("at")..]; output += "\n " + line[line.IndexOf("at")..];
}
} }
} }
string[] messageLines = e.Message?.Split('\n'); string[] messageLines = e.Message?.Split('\n');
if (messageLines is not null && messageLines.Length > 0) if (messageLines is not null && messageLines.Length > 0)
{ {
if (output.Length > 0) if (output.Length > 0)
{
output += "\n\n"; output += "\n\n";
}
output += "MESSAGE\n"; output += "MESSAGE\n";
for (int i = 0; i < messageLines.Length; i++) for (int i = 0; i < messageLines.Length; i++)
{ {
string line = messageLines[i]; string line = messageLines[i];
if (line is not null) if (line is not null)
{
output += "\n " + messageLines[i]; output += "\n " + messageLines[i];
}
} }
} }
return MessageBox.Show(output, caption: "CreamInstaller encountered an exception", buttons: MessageBoxButtons.RetryCancel, icon: MessageBoxIcon.Error) == DialogResult.Retry; return MessageBox.Show(output, caption: "CreamInstaller encountered an exception", buttons: MessageBoxButtons.RetryCancel, icon: MessageBoxIcon.Error) == DialogResult.Retry;

View file

@ -1,7 +1,7 @@
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
namespace CreamInstaller; namespace CreamInstaller.Classes;
internal static class InstallationLog internal static class InstallationLog
{ {

View file

@ -7,7 +7,7 @@ using System.Threading.Tasks;
using Gameloop.Vdf.Linq; using Gameloop.Vdf.Linq;
namespace CreamInstaller; namespace CreamInstaller.Classes;
internal class ProgramSelection internal class ProgramSelection
{ {

View file

@ -9,9 +9,11 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using CreamInstaller.Resources;
using Gameloop.Vdf.Linq; using Gameloop.Vdf.Linq;
namespace CreamInstaller; namespace CreamInstaller.Classes;
internal static class SteamCMD internal static class SteamCMD
{ {
@ -158,8 +160,6 @@ internal static class SteamCMD
{ {
Kill().Wait(); Kill().Wait();
if (Directory.Exists(DirectoryPath)) if (Directory.Exists(DirectoryPath))
{
Directory.Delete(DirectoryPath, true); Directory.Delete(DirectoryPath, true);
}
} }
} }

View file

@ -1,7 +1,8 @@
using Gameloop.Vdf; 
using Gameloop.Vdf;
using Gameloop.Vdf.Linq; using Gameloop.Vdf.Linq;
namespace CreamInstaller; namespace CreamInstaller.Classes;
internal static class ValveDataFile internal static class ValveDataFile
{ {

View file

@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>True</UseWindowsForms>
<ApplicationIcon>Resources\ini.ico</ApplicationIcon> <ApplicationIcon>Resources\ini.ico</ApplicationIcon>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract> <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>2.3.0.0</Version> <Version>2.3.1.0</Version>
<PackageIcon>Resources\ini.ico</PackageIcon> <PackageIcon>Resources\ini.ico</PackageIcon>
<PackageIconUrl /> <PackageIconUrl />
<Description>Automatically generates and installs CreamAPI files for Steam games on the user's computer. It can also generate and install CreamAPI for the Paradox Launcher should the user select a Paradox Interactive game.</Description> <Description>Automatically generates and installs CreamAPI files for Steam games on the user's computer. It can also generate and install CreamAPI for the Paradox Launcher should the user select a Paradox Interactive game.</Description>
@ -23,7 +23,8 @@
<Authors>pointfeev</Authors> <Authors>pointfeev</Authors>
<PackageId>pointfeev.creaminstaller</PackageId> <PackageId>pointfeev.creaminstaller</PackageId>
<StartupObject>CreamInstaller.Program</StartupObject> <StartupObject>CreamInstaller.Program</StartupObject>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild> <GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>embedded</DebugType> <DebugType>embedded</DebugType>

View file

@ -1,6 +1,6 @@
using System.Windows.Forms; using System.Windows.Forms;
namespace CreamInstaller; namespace CreamInstaller.Forms.Components;
internal class CustomForm : Form internal class CustomForm : Form
{ {

View file

@ -2,20 +2,16 @@
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
namespace CreamInstaller; namespace CreamInstaller.Forms.Components;
internal class CustomTreeView : TreeView internal class CustomTreeView : TreeView
{ {
protected override void WndProc(ref Message m) protected override void WndProc(ref Message m)
{ {
if (m.Msg == 0x203) if (m.Msg == 0x203)
{
m.Result = IntPtr.Zero; m.Result = IntPtr.Zero;
}
else else
{
base.WndProc(ref m); base.WndProc(ref m);
}
} }
internal CustomTreeView() : base() internal CustomTreeView() : base()
@ -29,9 +25,7 @@ internal class CustomTreeView : TreeView
e.DrawDefault = true; e.DrawDefault = true;
TreeNode node = e.Node; TreeNode node = e.Node;
if (!node.IsVisible) if (!node.IsVisible)
{
return; return;
}
Graphics graphics = e.Graphics; Graphics graphics = e.Graphics;
Color backColor = BackColor; Color backColor = BackColor;
@ -41,9 +35,7 @@ internal class CustomTreeView : TreeView
string subText = node.Name; string subText = node.Name;
if (subText is null || !int.TryParse(subText, out int subInt) || subInt <= 0) if (subText is null || !int.TryParse(subText, out int subInt) || subInt <= 0)
{
return; return;
}
Size subSize = TextRenderer.MeasureText(graphics, subText, subFont); Size subSize = TextRenderer.MeasureText(graphics, subText, subFont);
Rectangle bounds = node.Bounds; Rectangle bounds = node.Bounds;

View file

@ -1,6 +1,8 @@
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using CreamInstaller.Forms.Components;
namespace CreamInstaller; namespace CreamInstaller;
internal partial class DialogForm : CustomForm internal partial class DialogForm : CustomForm

View file

@ -8,6 +8,10 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using CreamInstaller.Classes;
using CreamInstaller.Forms.Components;
using CreamInstaller.Resources;
namespace CreamInstaller; namespace CreamInstaller;
internal partial class InstallForm : CustomForm internal partial class InstallForm : CustomForm

View file

@ -2,6 +2,8 @@
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
using CreamInstaller.Forms.Components;
namespace CreamInstaller namespace CreamInstaller
{ {
partial class MainForm partial class MainForm
@ -36,7 +38,7 @@ namespace CreamInstaller
this.updateButton = new System.Windows.Forms.Button(); this.updateButton = new System.Windows.Forms.Button();
this.ignoreButton = new System.Windows.Forms.Button(); this.ignoreButton = new System.Windows.Forms.Button();
this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.changelogTreeView = new CreamInstaller.CustomTreeView(); this.changelogTreeView = new CustomTreeView();
this.SuspendLayout(); this.SuspendLayout();
// //
// label1 // label1

View file

@ -9,6 +9,9 @@ using System.Threading.Tasks;
using System.Web; using System.Web;
using System.Windows.Forms; using System.Windows.Forms;
using CreamInstaller.Classes;
using CreamInstaller.Forms.Components;
using HtmlAgilityPack; using HtmlAgilityPack;
using Onova; using Onova;
@ -113,7 +116,7 @@ internal partial class MainForm : CustomForm
document.LoadHtml(reader.ReadToEnd()); document.LoadHtml(reader.ReadToEnd());
foreach (HtmlNode node in document.DocumentNode.SelectNodes("//div[@data-test-selector='body-content']/ul/li")) foreach (HtmlNode node in document.DocumentNode.SelectNodes("//div[@data-test-selector='body-content']/ul/li"))
{ {
changelogTreeView.TryMethodInvoke(delegate Program.Invoke(changelogTreeView, delegate
{ {
TreeNode change = new(); TreeNode change = new();
change.Text = $"{HttpUtility.HtmlDecode(node.InnerText)}"; change.Text = $"{HttpUtility.HtmlDecode(node.InnerText)}";

View file

@ -1,6 +1,8 @@
 
using System.Windows.Forms; using System.Windows.Forms;
using CreamInstaller.Forms.Components;
namespace CreamInstaller namespace CreamInstaller
{ {
partial class SelectForm partial class SelectForm
@ -40,7 +42,7 @@ namespace CreamInstaller
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.blockedGamesCheckBox = new System.Windows.Forms.CheckBox(); this.blockedGamesCheckBox = new System.Windows.Forms.CheckBox();
this.blockProtectedHelpButton = new System.Windows.Forms.Button(); this.blockProtectedHelpButton = new System.Windows.Forms.Button();
this.selectionTreeView = new CreamInstaller.CustomTreeView(); this.selectionTreeView = new CustomTreeView();
this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel(); this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel();
this.allCheckBox = new System.Windows.Forms.CheckBox(); this.allCheckBox = new System.Windows.Forms.CheckBox();
this.progressBar = new System.Windows.Forms.ProgressBar(); this.progressBar = new System.Windows.Forms.ProgressBar();

View file

@ -10,6 +10,9 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using CreamInstaller.Classes;
using CreamInstaller.Forms.Components;
using Gameloop.Vdf.Linq; using Gameloop.Vdf.Linq;
using Microsoft.Win32; using Microsoft.Win32;
@ -117,19 +120,15 @@ internal partial class SelectForm : CustomForm
return treeNodes; return treeNodes;
} }
internal List<Task> RunningTasks = new(); private static void UpdateRemaining(Label label, List<string> list, string descriptor) =>
label.Text = list.Any() ? $"Remaining {descriptor} ({list.Count}): " + string.Join(", ", list).Replace("&", "&&") : "";
private List<string> RemainingGames = new(); private readonly List<string> RemainingGames = new();
private void UpdateRemainingGames() private void UpdateRemainingGames() => UpdateRemaining(progressLabelGames, RemainingGames, "games");
{
if (Program.Canceled) return;
progressLabelGames.Text = $"Remaining games ({RemainingGames.Count}): "
+ (RemainingGames.Any() ? string.Join(", ", RemainingGames).Replace("&", "&&") : "None");
}
private void AddToRemainingGames(string gameName) private void AddToRemainingGames(string gameName)
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
progressLabelGames.TryMethodInvoke(delegate Program.Invoke(progressLabelGames, delegate
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
if (!RemainingGames.Contains(gameName)) if (!RemainingGames.Contains(gameName))
@ -140,7 +139,7 @@ internal partial class SelectForm : CustomForm
private void RemoveFromRemainingGames(string gameName) private void RemoveFromRemainingGames(string gameName)
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
progressLabelGames.TryMethodInvoke(delegate Program.Invoke(progressLabelGames, delegate
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
if (RemainingGames.Contains(gameName)) if (RemainingGames.Contains(gameName))
@ -149,17 +148,12 @@ internal partial class SelectForm : CustomForm
}); });
} }
private List<string> RemainingDLCs = new(); private readonly List<string> RemainingDLCs = new();
private void UpdateRemainingDLCs() private void UpdateRemainingDLCs() => UpdateRemaining(progressLabelDLCs, RemainingDLCs, "DLCs");
{
if (Program.Canceled) return;
progressLabelDLCs.Text = $"Remaining DLCs ({RemainingDLCs.Count}): "
+ (RemainingDLCs.Any() ? string.Join(", ", RemainingDLCs).Replace("&", "&&") : "None");
}
private void AddToRemainingDLCs(string dlcId) private void AddToRemainingDLCs(string dlcId)
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
progressLabelDLCs.TryMethodInvoke(delegate Program.Invoke(progressLabelDLCs, delegate
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
if (!RemainingDLCs.Contains(dlcId)) if (!RemainingDLCs.Contains(dlcId))
@ -170,7 +164,7 @@ internal partial class SelectForm : CustomForm
private void RemoveFromRemainingDLCs(string dlcId) private void RemoveFromRemainingDLCs(string dlcId)
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
progressLabelDLCs.TryMethodInvoke(delegate Program.Invoke(progressLabelDLCs, delegate
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
if (RemainingDLCs.Contains(dlcId)) if (RemainingDLCs.Contains(dlcId))
@ -179,6 +173,7 @@ internal partial class SelectForm : CustomForm
}); });
} }
internal readonly List<Task> RunningTasks = new();
private async Task GetCreamApiApplicablePrograms(IProgress<int> progress) private async Task GetCreamApiApplicablePrograms(IProgress<int> progress)
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
@ -295,7 +290,7 @@ internal partial class SelectForm : CustomForm
await task; await task;
} }
if (Program.Canceled) return; if (Program.Canceled) return;
selectionTreeView.TryMethodInvoke(delegate Program.Invoke(selectionTreeView, delegate
{ {
if (Program.Canceled) return; if (Program.Canceled) return;
TreeNode programNode = TreeNodes.Find(s => s.Name == "" + appId) ?? new(); TreeNode programNode = TreeNodes.Find(s => s.Name == "" + appId) ?? new();

View file

@ -10,6 +10,8 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using CreamInstaller.Classes;
namespace CreamInstaller; namespace CreamInstaller;
internal static class Program internal static class Program
@ -18,7 +20,7 @@ internal static class Program
internal static readonly Assembly EntryAssembly = Assembly.GetEntryAssembly(); internal static readonly Assembly EntryAssembly = Assembly.GetEntryAssembly();
internal static readonly Process CurrentProcess = Process.GetCurrentProcess(); internal static readonly Process CurrentProcess = Process.GetCurrentProcess();
internal static readonly string CurrentProcessFilePath = CurrentProcess.MainModule.FileName; internal static readonly string CurrentProcessFilePath = CurrentProcess.MainModule.FileName;
internal static readonly string CurrentProcessDirectory = CurrentProcessFilePath.Substring(0, CurrentProcessFilePath.LastIndexOf("\\")); internal static readonly string CurrentProcessDirectory = CurrentProcessFilePath[..CurrentProcessFilePath.LastIndexOf("\\")];
internal static readonly string BackupFileExtension = ".creaminstaller.backup"; internal static readonly string BackupFileExtension = ".creaminstaller.backup";
internal static bool BlockProtectedGames = true; internal static bool BlockProtectedGames = true;
@ -123,14 +125,7 @@ internal static class Program
await SteamCMD.Kill(); await SteamCMD.Kill();
} }
internal static void TryMethodInvoke(this Control control, MethodInvoker methodInvoker) internal static void Invoke(this Control control, MethodInvoker methodInvoker) => control.Invoke(methodInvoker);
{
try
{
control.Invoke(methodInvoker);
}
catch { }
}
private static void OnApplicationExit(object s, EventArgs e) => Cleanup(); private static void OnApplicationExit(object s, EventArgs e) => Cleanup();

View file

@ -1,6 +1,6 @@
using System.IO; using System.IO;
namespace CreamInstaller; namespace CreamInstaller.Resources;
internal static class FileResourceExtensions internal static class FileResourceExtensions
{ {