From a36eac87fc6d2c5ba1f99cbac1c021797db50cf6 Mon Sep 17 00:00:00 2001 From: rjindael Date: Mon, 31 Jul 2023 05:35:38 -0700 Subject: [PATCH] nit: clean up constants --- Kiseki.Launcher.Windows/Directories.cs | 2 +- Kiseki.Launcher.Windows/Launcher.cs | 20 ++++++++++---------- Kiseki.Launcher.Windows/MainWindow.cs | 2 +- Kiseki.Launcher.Windows/Program.cs | 4 ++-- Kiseki.Launcher.Windows/Protocol.cs | 2 +- Kiseki.Launcher/Constants.cs | 4 ++-- Kiseki.Launcher/Controller.cs | 4 ++-- Kiseki.Launcher/Web.cs | 14 ++++++-------- 8 files changed, 25 insertions(+), 27 deletions(-) diff --git a/Kiseki.Launcher.Windows/Directories.cs b/Kiseki.Launcher.Windows/Directories.cs index 8282dc8..37fb550 100644 --- a/Kiseki.Launcher.Windows/Directories.cs +++ b/Kiseki.Launcher.Windows/Directories.cs @@ -18,7 +18,7 @@ namespace Kiseki.Launcher.Windows Versions = Path.Combine(Base, "Versions"); License = Path.Combine(Base, "license.bin"); - Application = Path.Combine(Base, $"{Constants.ProjectName}.Launcher.exe"); + Application = Path.Combine(Base, $"{Constants.PROJECT_NAME}.Launcher.exe"); } } } \ No newline at end of file diff --git a/Kiseki.Launcher.Windows/Launcher.cs b/Kiseki.Launcher.Windows/Launcher.cs index 4e6da79..fda193f 100644 --- a/Kiseki.Launcher.Windows/Launcher.cs +++ b/Kiseki.Launcher.Windows/Launcher.cs @@ -20,7 +20,7 @@ namespace Kiseki.Launcher.Windows if (response != Web.RESPONSE_MAINTENANCE) { // The Kiseki website is either down or we can't connect to the internet. - MessageBox.Show($"Failed to connect to the {Constants.ProjectName} website. Please check your internet connection.", Constants.ProjectName, MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Failed to connect to the {Constants.PROJECT_NAME} website. Please check your internet connection.", Constants.PROJECT_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); } else @@ -36,7 +36,7 @@ namespace Kiseki.Launcher.Windows { // ... and if it's invalid, keep asking for a new one. File.Delete(Directories.License); - MessageBox.Show($"Corrupt license file! Please verify the contents of your license file (it should be named \"license.bin\".)", Constants.ProjectName, MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show($"Corrupt license file! Please verify the contents of your license file (it should be named \"license.bin\".)", Constants.PROJECT_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); AskForLicense(Directories.License, false); } @@ -50,7 +50,7 @@ namespace Kiseki.Launcher.Windows private static void AskForLicense(string licensePath, bool showDialog = true) { - DialogResult answer = showDialog ? MessageBox.Show($"{Constants.ProjectName} is currently under maintenance and requires a license in order to access games. Would you like to look for the license file now?", Constants.ProjectName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) : DialogResult.Yes; + DialogResult answer = showDialog ? MessageBox.Show($"{Constants.PROJECT_NAME} is currently under maintenance and requires a license in order to access games. Would you like to look for the license file now?", Constants.PROJECT_NAME, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) : DialogResult.Yes; if (answer == DialogResult.Yes) { @@ -71,15 +71,15 @@ namespace Kiseki.Launcher.Windows // TODO: Implement this public static void Register() { - using (RegistryKey applicationKey = Registry.CurrentUser.CreateSubKey($@"Software\{Constants.ProjectName}")) + using (RegistryKey applicationKey = Registry.CurrentUser.CreateSubKey($@"Software\{Constants.PROJECT_NAME}")) { applicationKey.SetValue("InstallLocation", Directories.Base); } - using RegistryKey uninstallKey = Registry.CurrentUser.CreateSubKey($@"Software\Microsoft\Windows\CurrentVersion\Uninstall\{Constants.ProjectName}"); + using RegistryKey uninstallKey = Registry.CurrentUser.CreateSubKey($@"Software\Microsoft\Windows\CurrentVersion\Uninstall\{Constants.PROJECT_NAME}"); uninstallKey.SetValue("DisplayIcon", $"{Directories.Application},0"); - uninstallKey.SetValue("DisplayName", Constants.ProjectName); + uninstallKey.SetValue("DisplayName", Constants.PROJECT_NAME); uninstallKey.SetValue("DisplayVersion", Version); if (uninstallKey.GetValue("InstallDate") is null) @@ -87,18 +87,18 @@ namespace Kiseki.Launcher.Windows uninstallKey.SetValue("InstallLocation", Directories.Base); uninstallKey.SetValue("NoRepair", 1); - uninstallKey.SetValue("Publisher", Constants.ProjectName); + uninstallKey.SetValue("Publisher", Constants.PROJECT_NAME); uninstallKey.SetValue("ModifyPath", $"\"{Directories.Application}\" -menu"); uninstallKey.SetValue("QuietUninstallString", $"\"{Directories.Application}\" -uninstall -quiet"); uninstallKey.SetValue("UninstallString", $"\"{Directories.Application}\" -uninstall"); - uninstallKey.SetValue("URLInfoAbout", $"https://github.com/{Constants.ProjectRepository}"); - uninstallKey.SetValue("URLUpdateInfo", $"https://github.com/{Constants.ProjectRepository}/releases/latest"); + uninstallKey.SetValue("URLInfoAbout", $"https://github.com/{Constants.PROJECT_REPOSITORY}"); + uninstallKey.SetValue("URLUpdateInfo", $"https://github.com/{Constants.PROJECT_REPOSITORY}/releases/latest"); } // TODO: Implement this public static void Unregister() { - Registry.CurrentUser.DeleteSubKey($@"Software\{Constants.ProjectName}"); + Registry.CurrentUser.DeleteSubKey($@"Software\{Constants.PROJECT_NAME}"); } } } \ No newline at end of file diff --git a/Kiseki.Launcher.Windows/MainWindow.cs b/Kiseki.Launcher.Windows/MainWindow.cs index 98ec7af..36f6925 100644 --- a/Kiseki.Launcher.Windows/MainWindow.cs +++ b/Kiseki.Launcher.Windows/MainWindow.cs @@ -21,7 +21,7 @@ namespace Kiseki.Launcher.Windows CloseButton = TaskDialogButton.Close; Page = new TaskDialogPage() { - Caption = Constants.ProjectName, + Caption = Constants.PROJECT_NAME, AllowMinimize = true, ProgressBar = new TaskDialogProgressBar() diff --git a/Kiseki.Launcher.Windows/Program.cs b/Kiseki.Launcher.Windows/Program.cs index b4db7cf..c99ad51 100644 --- a/Kiseki.Launcher.Windows/Program.cs +++ b/Kiseki.Launcher.Windows/Program.cs @@ -8,7 +8,7 @@ namespace Kiseki.Launcher.Windows static void Main(string[] args) { string parentFolder = Path.GetDirectoryName(AppContext.BaseDirectory)!; - if (parentFolder.ToLower().Contains(Constants.ProjectName)) + if (parentFolder.ToLower().Contains(Constants.PROJECT_NAME)) { // Set to the current directory (either user-installed or default; it has "Kiseki" in the path, so that's good enough for us) Directories.Initialize(AppContext.BaseDirectory); @@ -16,7 +16,7 @@ namespace Kiseki.Launcher.Windows else { // Set to the default directory (user likely hasn't installed the launcher yet) - Directories.Initialize(Path.Combine(Directories.LocalAppData, Constants.ProjectName)); + Directories.Initialize(Path.Combine(Directories.LocalAppData, Constants.PROJECT_NAME)); } Web.Initialize(); diff --git a/Kiseki.Launcher.Windows/Protocol.cs b/Kiseki.Launcher.Windows/Protocol.cs index 8766841..b6d81ec 100644 --- a/Kiseki.Launcher.Windows/Protocol.cs +++ b/Kiseki.Launcher.Windows/Protocol.cs @@ -4,7 +4,7 @@ namespace Kiseki.Launcher.Windows { public class Protocol : IProtocol { - public const string ProtocolKey = "kiseki"; + public const string PROTOCOL_KEY = "kiseki"; public void Register(string key, string name, string handler) { diff --git a/Kiseki.Launcher/Constants.cs b/Kiseki.Launcher/Constants.cs index c6f2ba5..26d718a 100644 --- a/Kiseki.Launcher/Constants.cs +++ b/Kiseki.Launcher/Constants.cs @@ -2,7 +2,7 @@ namespace Kiseki.Launcher { public static class Constants { - public const string ProjectName = "Kiseki"; - public const string ProjectRepository = "kiseki-lol/launcher"; + public const string PROJECT_NAME = "Kiseki"; + public const string PROJECT_REPOSITORY = "kiseki-lol/launcher"; } } \ No newline at end of file diff --git a/Kiseki.Launcher/Controller.cs b/Kiseki.Launcher/Controller.cs index 3bf2949..9f3531f 100644 --- a/Kiseki.Launcher/Controller.cs +++ b/Kiseki.Launcher/Controller.cs @@ -22,7 +22,7 @@ namespace Kiseki.Launcher { if (!Base64.IsBase64String(payload)) { - ErrorShow($"Failed to launch {Constants.ProjectName}", $"Try launching {Constants.ProjectName} from the website again."); + ErrorShow($"Failed to launch {Constants.PROJECT_NAME}", $"Try launching {Constants.PROJECT_NAME} from the website again."); return; } @@ -30,7 +30,7 @@ namespace Kiseki.Launcher payload = Base64.ConvertBase64ToString(payload); if (payload.Split("|").Length != 2) { - ErrorShow($"Failed to launch {Constants.ProjectName}", $"Try launching {Constants.ProjectName} from the website again."); + ErrorShow($"Failed to launch {Constants.PROJECT_NAME}", $"Try launching {Constants.PROJECT_NAME} from the website again."); return; } diff --git a/Kiseki.Launcher/Web.cs b/Kiseki.Launcher/Web.cs index 098a893..81ca983 100644 --- a/Kiseki.Launcher/Web.cs +++ b/Kiseki.Launcher/Web.cs @@ -5,22 +5,20 @@ namespace Kiseki.Launcher { public static class Web { - public const int RESPONSE_SUCCESS = 0; public const int RESPONSE_FAILURE = -1; - + public const int RESPONSE_SUCCESS = 0; public const int RESPONSE_MAINTENANCE = 1; - public const string BaseUrl = "kiseki.lol"; - public const string MaintenanceDomain = "test"; + public const string BASE_URL = "kiseki.lol"; + public const string MAINTENANCE_DOMAIN = "test"; public static readonly HttpClient HttpClient = new(); public static string CurrentUrl { get; private set; } = ""; + public static bool MaintenanceMode { get; private set; } = false; - public static void Initialize() => CurrentUrl = BaseUrl; + public static void Initialize() => CurrentUrl = BASE_URL; public static string Url(string path) => $"https://{CurrentUrl}{path}"; - private static bool MaintenanceMode = false; - public static int CheckHealth() { var response = Helpers.Http.GetJson(Url("/api/health")); @@ -32,7 +30,7 @@ namespace Kiseki.Launcher { if (!MaintenanceMode) { - CurrentUrl = $"{MaintenanceDomain}.{CurrentUrl}"; + CurrentUrl = $"{MAINTENANCE_DOMAIN}.{CurrentUrl}"; MaintenanceMode = true; }