more dynamic app variables

This commit is contained in:
pointfeev 2022-09-20 10:38:27 -04:00
parent 1998bdef9b
commit f672e52ffc
6 changed files with 34 additions and 23 deletions

View file

@ -13,7 +13,6 @@
<PackageProjectUrl>https://github.com/pointfeev/CreamInstaller</PackageProjectUrl> <PackageProjectUrl>https://github.com/pointfeev/CreamInstaller</PackageProjectUrl>
<RepositoryUrl>https://github.com/pointfeev/CreamInstaller</RepositoryUrl> <RepositoryUrl>https://github.com/pointfeev/CreamInstaller</RepositoryUrl>
<RepositoryType>git</RepositoryType> <RepositoryType>git</RepositoryType>
<AssemblyName>CreamInstaller</AssemblyName>
<Company>CreamInstaller</Company> <Company>CreamInstaller</Company>
<Product>Automatic DLC Unlocker Installer &amp; Configuration Generator</Product> <Product>Automatic DLC Unlocker Installer &amp; Configuration Generator</Product>
<Authors>pointfeev</Authors> <Authors>pointfeev</Authors>
@ -24,21 +23,23 @@
<SignAssembly>False</SignAssembly> <SignAssembly>False</SignAssembly>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild> <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<AnalysisLevel>latest-all</AnalysisLevel> <AnalysisLevel>latest-all</AnalysisLevel>
<Title>CreamInstaller</Title> <Title>$(Company)</Title>
<Description>Automatic DLC Unlocker Installer &amp; Configuration Generator</Description> <Description>$(Product)</Description>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<AssemblyName>$(Company)</AssemblyName>
<DebugType>embedded</DebugType> <DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DefineConstants>$(DefineConstants)</DefineConstants> <DefineConstants>$(DefineConstants)</DefineConstants>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> <AssemblyName>$(Company)-debug</AssemblyName>
<Optimize>True</Optimize> <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DebugType>embedded</DebugType> <Optimize>True</Optimize>
<DefineConstants>$(DefineConstants)</DefineConstants> <DebugType>embedded</DebugType>
<DefineConstants>$(DefineConstants)</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Remove="Resources\Koaloader\audioses-32\audioses.dll" /> <None Remove="Resources\Koaloader\audioses-32\audioses.dll" />

View file

@ -66,7 +66,7 @@ internal partial class MainForm : CustomForm
#if DEBUG #if DEBUG
DebugForm.Current.Attach(this); DebugForm.Current.Attach(this);
#endif #endif
GithubPackageResolver resolver = new("pointfeev", "CreamInstaller", "CreamInstaller.zip"); GithubPackageResolver resolver = new(Program.RepositoryOwner, Program.RepositoryName, Program.RepositoryPackage);
ZipPackageExtractor extractor = new(); ZipPackageExtractor extractor = new();
updateManager = new(AssemblyMetadata.FromAssembly(Program.EntryAssembly, Program.CurrentProcessFilePath), resolver, extractor); updateManager = new(AssemblyMetadata.FromAssembly(Program.EntryAssembly, Program.CurrentProcessFilePath), resolver, extractor);
if (latestVersion is null) if (latestVersion is null)
@ -80,8 +80,8 @@ internal partial class MainForm : CustomForm
if (checkForUpdatesResult.CanUpdate) if (checkForUpdatesResult.CanUpdate)
{ {
#endif #endif
latestVersion = checkForUpdatesResult.LastVersion; latestVersion = checkForUpdatesResult.LastVersion;
versions = checkForUpdatesResult.Versions; versions = checkForUpdatesResult.Versions;
#if !DEBUG #if !DEBUG
} }
#endif #endif
@ -114,7 +114,7 @@ internal partial class MainForm : CustomForm
updateButton.Enabled = true; updateButton.Enabled = true;
updateButton.Click += new(OnUpdate); updateButton.Click += new(OnUpdate);
changelogTreeView.Visible = true; changelogTreeView.Visible = true;
Version currentVersion = new(Application.ProductVersion); Version currentVersion = new(Program.Version);
#if DEBUG #if DEBUG
foreach (Version version in versions.Where(v => (v > currentVersion || v == latestVersion) && !changelogTreeView.Nodes.ContainsKey(v.ToString()))) foreach (Version version in versions.Where(v => (v > currentVersion || v == latestVersion) && !changelogTreeView.Nodes.ContainsKey(v.ToString())))
#else #else
@ -161,12 +161,12 @@ internal partial class MainForm : CustomForm
try try
{ {
string FileName = Path.GetFileName(Program.CurrentProcessFilePath); string FileName = Path.GetFileName(Program.CurrentProcessFilePath);
if (FileName != "CreamInstaller.exe") if (FileName != Program.ApplicationExecutable)
{ {
using DialogForm form = new(this); using DialogForm form = new(this);
if (form.Show(SystemIcons.Warning, if (form.Show(SystemIcons.Warning,
"WARNING: CreamInstaller.exe was renamed!" + "WARNING: " + Program.ApplicationExecutable + " was renamed!" +
"\n\nThis will cause unwanted behavior when updating the program!", "\n\nThis will cause undesirable behavior when updating the program!",
"Ignore", "Abort") == DialogResult.Cancel) "Ignore", "Abort") == DialogResult.Cancel)
{ {
Application.Exit(); Application.Exit();

View file

@ -14,12 +14,21 @@ namespace CreamInstaller;
internal static class Program internal static class Program
{ {
internal static readonly string Name = Application.CompanyName;
internal static readonly string Description = Application.ProductName;
internal static readonly string Version = Application.ProductVersion;
internal const string RepositoryOwner = "pointfeev";
internal static readonly string RepositoryName = Name;
internal static readonly string RepositoryPackage = Name + ".zip";
#if DEBUG #if DEBUG
internal static readonly string ApplicationName = Application.CompanyName + " v" + Application.ProductVersion + "-debug: " + Application.ProductName; internal static readonly string ApplicationName = Name + " v" + Version + "-debug: " + Description;
internal static readonly string ApplicationNameShort = Application.CompanyName + " v" + Application.ProductVersion + "-debug"; internal static readonly string ApplicationNameShort = Name + " v" + Version + "-debug";
internal static readonly string ApplicationExecutable = Name + "-debug.exe"; // should be the same as in .csproj
#else #else
internal static readonly string ApplicationName = Application.CompanyName + " v" + Application.ProductVersion + ": " + Application.ProductName; internal static readonly string ApplicationName = Name + " v" + Version + ": " + Description;
internal static readonly string ApplicationNameShort = Application.CompanyName + " v" + Application.ProductVersion; internal static readonly string ApplicationNameShort = Name + " v" + Version;
internal static readonly string ApplicationExecutable = Name + ".exe"; // should be the same as in .csproj
#endif #endif
internal static readonly Assembly EntryAssembly = Assembly.GetEntryAssembly(); internal static readonly Assembly EntryAssembly = Assembly.GetEntryAssembly();
@ -59,7 +68,7 @@ internal static class Program
[STAThread] [STAThread]
private static void Main() private static void Main()
{ {
using Mutex mutex = new(true, "CreamInstaller", out bool createdNew); using Mutex mutex = new(true, Name, out bool createdNew);
if (createdNew) if (createdNew)
{ {
_ = Application.SetHighDpiMode(HighDpiMode.SystemAware); _ = Application.SetHighDpiMode(HighDpiMode.SystemAware);

View file

@ -7,8 +7,9 @@ namespace CreamInstaller.Utility;
internal static class ExceptionHandler internal static class ExceptionHandler
{ {
internal static bool HandleException(this Exception e, Form form = null, string caption = "CreamInstaller encountered an exception", string acceptButtonText = "Retry", string cancelButtonText = "Cancel") internal static bool HandleException(this Exception e, Form form = null, string caption = null, string acceptButtonText = "Retry", string cancelButtonText = "Cancel")
{ {
caption ??= Program.Name + " encountered a fatal exception";
while (e.InnerException is not null) // we usually don't need the outer exceptions while (e.InnerException is not null) // we usually don't need the outer exceptions
e = e.InnerException; e = e.InnerException;
StringBuilder output = new(); StringBuilder output = new();
@ -53,7 +54,7 @@ internal static class ExceptionHandler
internal static void HandleFatalException(this Exception e) internal static void HandleFatalException(this Exception e)
{ {
bool? restart = e?.HandleException(caption: "CreamInstaller encountered a fatal exception", acceptButtonText: "Restart"); bool? restart = e?.HandleException(acceptButtonText: "Restart");
if (restart.HasValue && restart.Value) if (restart.HasValue && restart.Value)
Application.Restart(); Application.Restart();
Application.Exit(); Application.Exit();

View file

@ -14,7 +14,7 @@ internal static class HttpClientManager
internal static void Setup() internal static void Setup()
{ {
HttpClient = new(); HttpClient = new();
HttpClient.DefaultRequestHeaders.Add("User-Agent", $"CI{Application.ProductVersion.Replace(".", "")}"); HttpClient.DefaultRequestHeaders.Add("User-Agent", $"CI{Program.Version.Replace(".", "")}");
} }
internal static async Task<string> EnsureGet(string url) internal static async Task<string> EnsureGet(string url)

View file

@ -41,7 +41,7 @@ internal static class ProgramData
{ {
if (Directory.Exists(AppInfoPath)) Directory.Delete(AppInfoPath, true); if (Directory.Exists(AppInfoPath)) Directory.Delete(AppInfoPath, true);
_ = Directory.CreateDirectory(AppInfoPath); _ = Directory.CreateDirectory(AppInfoPath);
File.WriteAllText(AppInfoVersionPath, Application.ProductVersion, Encoding.UTF8); File.WriteAllText(AppInfoVersionPath, Program.Version, Encoding.UTF8);
} }
if (!Directory.Exists(CooldownPath)) if (!Directory.Exists(CooldownPath))
_ = Directory.CreateDirectory(CooldownPath); _ = Directory.CreateDirectory(CooldownPath);