- 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.Windows.Forms;
namespace CreamInstaller;
namespace CreamInstaller.Classes;
internal static class ExceptionHandler
{
internal static bool OutputException(Exception e)
{
while (e.InnerException is not null)
{
e = e.InnerException;
}
string output = "";
string[] stackTrace = e.StackTrace?.Split('\n');
@ -21,27 +19,21 @@ internal static class ExceptionHandler
{
string line = stackTrace[i];
if (line is not null)
{
output += "\n " + line[line.IndexOf("at")..];
}
}
}
string[] messageLines = e.Message?.Split('\n');
if (messageLines is not null && messageLines.Length > 0)
{
if (output.Length > 0)
{
output += "\n\n";
}
output += "MESSAGE\n";
for (int i = 0; i < messageLines.Length; i++)
{
string line = messageLines[i];
if (line is not null)
{
output += "\n " + messageLines[i];
}
}
}
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.Windows.Forms;
namespace CreamInstaller;
namespace CreamInstaller.Classes;
internal static class InstallationLog
{

View file

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

View file

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

View file

@ -1,7 +1,8 @@
using Gameloop.Vdf;

using Gameloop.Vdf;
using Gameloop.Vdf.Linq;
namespace CreamInstaller;
namespace CreamInstaller.Classes;
internal static class ValveDataFile
{

View file

@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<TargetFramework>net6.0-windows10.0.22000.0</TargetFramework>
<UseWindowsForms>True</UseWindowsForms>
<ApplicationIcon>Resources\ini.ico</ApplicationIcon>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<Version>2.3.0.0</Version>
<Version>2.3.1.0</Version>
<PackageIcon>Resources\ini.ico</PackageIcon>
<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>
@ -23,7 +23,8 @@
<Authors>pointfeev</Authors>
<PackageId>pointfeev.creaminstaller</PackageId>
<StartupObject>CreamInstaller.Program</StartupObject>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>embedded</DebugType>

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -9,6 +9,9 @@ using System.Threading.Tasks;
using System.Web;
using System.Windows.Forms;
using CreamInstaller.Classes;
using CreamInstaller.Forms.Components;
using HtmlAgilityPack;
using Onova;
@ -113,7 +116,7 @@ internal partial class MainForm : CustomForm
document.LoadHtml(reader.ReadToEnd());
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();
change.Text = $"{HttpUtility.HtmlDecode(node.InnerText)}";

View file

@ -1,6 +1,8 @@

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

View file

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

View file

@ -10,6 +10,8 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using CreamInstaller.Classes;
namespace CreamInstaller;
internal static class Program
@ -18,7 +20,7 @@ internal static class Program
internal static readonly Assembly EntryAssembly = Assembly.GetEntryAssembly();
internal static readonly Process CurrentProcess = Process.GetCurrentProcess();
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 bool BlockProtectedGames = true;
@ -123,14 +125,7 @@ internal static class Program
await SteamCMD.Kill();
}
internal static void TryMethodInvoke(this Control control, MethodInvoker methodInvoker)
{
try
{
control.Invoke(methodInvoker);
}
catch { }
}
internal static void Invoke(this Control control, MethodInvoker methodInvoker) => control.Invoke(methodInvoker);
private static void OnApplicationExit(object s, EventArgs e) => Cleanup();

View file

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