nit: clean up constants

This commit is contained in:
rjindael 2023-07-31 05:35:38 -07:00
parent 23a362d40e
commit a36eac87fc
No known key found for this signature in database
GPG Key ID: D069369C906CCF31
8 changed files with 25 additions and 27 deletions

View File

@ -18,7 +18,7 @@ namespace Kiseki.Launcher.Windows
Versions = Path.Combine(Base, "Versions"); Versions = Path.Combine(Base, "Versions");
License = Path.Combine(Base, "license.bin"); License = Path.Combine(Base, "license.bin");
Application = Path.Combine(Base, $"{Constants.ProjectName}.Launcher.exe"); Application = Path.Combine(Base, $"{Constants.PROJECT_NAME}.Launcher.exe");
} }
} }
} }

View File

@ -20,7 +20,7 @@ namespace Kiseki.Launcher.Windows
if (response != Web.RESPONSE_MAINTENANCE) if (response != Web.RESPONSE_MAINTENANCE)
{ {
// The Kiseki website is either down or we can't connect to the internet. // 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); Environment.Exit(0);
} }
else else
@ -36,7 +36,7 @@ namespace Kiseki.Launcher.Windows
{ {
// ... and if it's invalid, keep asking for a new one. // ... and if it's invalid, keep asking for a new one.
File.Delete(Directories.License); 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); AskForLicense(Directories.License, false);
} }
@ -50,7 +50,7 @@ namespace Kiseki.Launcher.Windows
private static void AskForLicense(string licensePath, bool showDialog = true) 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) if (answer == DialogResult.Yes)
{ {
@ -71,15 +71,15 @@ namespace Kiseki.Launcher.Windows
// TODO: Implement this // TODO: Implement this
public static void Register() 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); 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("DisplayIcon", $"{Directories.Application},0");
uninstallKey.SetValue("DisplayName", Constants.ProjectName); uninstallKey.SetValue("DisplayName", Constants.PROJECT_NAME);
uninstallKey.SetValue("DisplayVersion", Version); uninstallKey.SetValue("DisplayVersion", Version);
if (uninstallKey.GetValue("InstallDate") is null) if (uninstallKey.GetValue("InstallDate") is null)
@ -87,18 +87,18 @@ namespace Kiseki.Launcher.Windows
uninstallKey.SetValue("InstallLocation", Directories.Base); uninstallKey.SetValue("InstallLocation", Directories.Base);
uninstallKey.SetValue("NoRepair", 1); uninstallKey.SetValue("NoRepair", 1);
uninstallKey.SetValue("Publisher", Constants.ProjectName); uninstallKey.SetValue("Publisher", Constants.PROJECT_NAME);
uninstallKey.SetValue("ModifyPath", $"\"{Directories.Application}\" -menu"); uninstallKey.SetValue("ModifyPath", $"\"{Directories.Application}\" -menu");
uninstallKey.SetValue("QuietUninstallString", $"\"{Directories.Application}\" -uninstall -quiet"); uninstallKey.SetValue("QuietUninstallString", $"\"{Directories.Application}\" -uninstall -quiet");
uninstallKey.SetValue("UninstallString", $"\"{Directories.Application}\" -uninstall"); uninstallKey.SetValue("UninstallString", $"\"{Directories.Application}\" -uninstall");
uninstallKey.SetValue("URLInfoAbout", $"https://github.com/{Constants.ProjectRepository}"); uninstallKey.SetValue("URLInfoAbout", $"https://github.com/{Constants.PROJECT_REPOSITORY}");
uninstallKey.SetValue("URLUpdateInfo", $"https://github.com/{Constants.ProjectRepository}/releases/latest"); uninstallKey.SetValue("URLUpdateInfo", $"https://github.com/{Constants.PROJECT_REPOSITORY}/releases/latest");
} }
// TODO: Implement this // TODO: Implement this
public static void Unregister() public static void Unregister()
{ {
Registry.CurrentUser.DeleteSubKey($@"Software\{Constants.ProjectName}"); Registry.CurrentUser.DeleteSubKey($@"Software\{Constants.PROJECT_NAME}");
} }
} }
} }

View File

@ -21,7 +21,7 @@ namespace Kiseki.Launcher.Windows
CloseButton = TaskDialogButton.Close; CloseButton = TaskDialogButton.Close;
Page = new TaskDialogPage() Page = new TaskDialogPage()
{ {
Caption = Constants.ProjectName, Caption = Constants.PROJECT_NAME,
AllowMinimize = true, AllowMinimize = true,
ProgressBar = new TaskDialogProgressBar() ProgressBar = new TaskDialogProgressBar()

View File

@ -8,7 +8,7 @@ namespace Kiseki.Launcher.Windows
static void Main(string[] args) static void Main(string[] args)
{ {
string parentFolder = Path.GetDirectoryName(AppContext.BaseDirectory)!; 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) // 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); Directories.Initialize(AppContext.BaseDirectory);
@ -16,7 +16,7 @@ namespace Kiseki.Launcher.Windows
else else
{ {
// Set to the default directory (user likely hasn't installed the launcher yet) // 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(); Web.Initialize();

View File

@ -4,7 +4,7 @@ namespace Kiseki.Launcher.Windows
{ {
public class Protocol : IProtocol public class Protocol : IProtocol
{ {
public const string ProtocolKey = "kiseki"; public const string PROTOCOL_KEY = "kiseki";
public void Register(string key, string name, string handler) public void Register(string key, string name, string handler)
{ {

View File

@ -2,7 +2,7 @@ namespace Kiseki.Launcher
{ {
public static class Constants public static class Constants
{ {
public const string ProjectName = "Kiseki"; public const string PROJECT_NAME = "Kiseki";
public const string ProjectRepository = "kiseki-lol/launcher"; public const string PROJECT_REPOSITORY = "kiseki-lol/launcher";
} }
} }

View File

@ -22,7 +22,7 @@ namespace Kiseki.Launcher
{ {
if (!Base64.IsBase64String(payload)) 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; return;
} }
@ -30,7 +30,7 @@ namespace Kiseki.Launcher
payload = Base64.ConvertBase64ToString(payload); payload = Base64.ConvertBase64ToString(payload);
if (payload.Split("|").Length != 2) 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; return;
} }

View File

@ -5,22 +5,20 @@ namespace Kiseki.Launcher
{ {
public static class Web public static class Web
{ {
public const int RESPONSE_SUCCESS = 0;
public const int RESPONSE_FAILURE = -1; public const int RESPONSE_FAILURE = -1;
public const int RESPONSE_SUCCESS = 0;
public const int RESPONSE_MAINTENANCE = 1; public const int RESPONSE_MAINTENANCE = 1;
public const string BaseUrl = "kiseki.lol"; public const string BASE_URL = "kiseki.lol";
public const string MaintenanceDomain = "test"; public const string MAINTENANCE_DOMAIN = "test";
public static readonly HttpClient HttpClient = new(); public static readonly HttpClient HttpClient = new();
public static string CurrentUrl { get; private set; } = ""; 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}"; public static string Url(string path) => $"https://{CurrentUrl}{path}";
private static bool MaintenanceMode = false;
public static int CheckHealth() public static int CheckHealth()
{ {
var response = Helpers.Http.GetJson<Models.HealthCheck>(Url("/api/health")); var response = Helpers.Http.GetJson<Models.HealthCheck>(Url("/api/health"));
@ -32,7 +30,7 @@ namespace Kiseki.Launcher
{ {
if (!MaintenanceMode) if (!MaintenanceMode)
{ {
CurrentUrl = $"{MaintenanceDomain}.{CurrentUrl}"; CurrentUrl = $"{MAINTENANCE_DOMAIN}.{CurrentUrl}";
MaintenanceMode = true; MaintenanceMode = true;
} }