diff --git a/Kiseki.Launcher.Windows/Launcher.cs b/Kiseki.Launcher.Windows/Launcher.cs index 996538e..78ec55e 100644 --- a/Kiseki.Launcher.Windows/Launcher.cs +++ b/Kiseki.Launcher.Windows/Launcher.cs @@ -8,45 +8,8 @@ namespace Kiseki.Launcher.Windows { public readonly static string Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[..^2]; -#region Licensing - public static void TryLoadLicense() - { - if (!File.Exists(Directories.License)) - { - AskForLicense(Directories.License); - } + #region ILauncher implementation - // ... load the license ... - while (!Web.LoadLicense(File.ReadAllText(Directories.License))) - { - // ... 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.PROJECT_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); - AskForLicense(Directories.License, false); - } - } - - private static void AskForLicense(string licensePath, bool showDialog = true) - { - 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) - { - using OpenFileDialog dialog = new() - { - Title = "Select your license file", - Filter = "License files (*.bin)|*.bin", - InitialDirectory = Win32.GetDownloadsPath() - }; - - if (dialog.ShowDialog() == DialogResult.OK) - { - File.Copy(dialog.FileName, licensePath, true); - } - } - } -#endregion -#region ILauncher implementation public static void Install() { Directory.CreateDirectory(Directories.Base); @@ -84,6 +47,56 @@ namespace Kiseki.Launcher.Windows { Registry.CurrentUser.DeleteSubKey($@"Software\{Constants.PROJECT_NAME}"); } -#endregion + + #endregion + #region Licensing + + public static void TryLoadLicense() + { + if (!File.Exists(Directories.License)) + { + if (!AskForLicense(Directories.License)) + { + // They don't want us :( + return; + } + } + + // ... load the license ... + while (!Web.LoadLicense(File.ReadAllText(Directories.License))) + { + // ... 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.PROJECT_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error); + AskForLicense(Directories.License, false); + } + } + + private static bool AskForLicense(string licensePath, bool showDialog = true) + { + 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) + { + using OpenFileDialog dialog = new() + { + Title = "Select your license file", + Filter = "License files (*.bin)|*.bin", + InitialDirectory = Win32.GetDownloadsPath() + }; + + if (dialog.ShowDialog() == DialogResult.OK) + { + Directory.CreateDirectory(Directories.Base); // failsafe + File.Copy(dialog.FileName, licensePath, true); + } + + return true; + } + + return false; + } + + #endregion } } \ No newline at end of file