diff --git a/Kiseki.Launcher.Windows/Directories.cs b/Kiseki.Launcher.Windows/Directories.cs new file mode 100644 index 0000000..9eb09ea --- /dev/null +++ b/Kiseki.Launcher.Windows/Directories.cs @@ -0,0 +1,22 @@ +namespace Kiseki.Launcher.Windows +{ + public static class Directories + { + public static string LocalAppData => Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); + + public static string Base { get; private set; } = ""; + public static string Logs { get; private set; } = ""; + public static string Versions { get; private set; } = ""; + public static string Application { get; private set; } = ""; + + public static void Initialize(string baseDirectory) + { + Base = baseDirectory; + + Logs = Path.Combine(Base, "Logs"); + Versions = Path.Combine(Base, "Versions"); + + Application = Path.Combine(Base, $"{Launcher.ProjectName}.exe"); + } + } +} \ No newline at end of file diff --git a/Kiseki.Launcher.Windows/Launcher.cs b/Kiseki.Launcher.Windows/Launcher.cs index 74a4d6d..1ca46ff 100644 --- a/Kiseki.Launcher.Windows/Launcher.cs +++ b/Kiseki.Launcher.Windows/Launcher.cs @@ -1,20 +1,46 @@ +using System.Reflection; + +using Microsoft.Win32; + namespace Kiseki.Launcher.Windows { public class Launcher : ILauncher { + public const string ProjectName = "Kiseki"; + public const string ProjectRepository = "kiseki-lol/launcher"; + + public readonly static string BaseUrl = "test.kiseki.lol"; // TODO: This should be set dynamically somehow + public readonly static string Version = Assembly.GetExecutingAssembly().GetName().Version!.ToString()[..^2]; + public void Register() { - throw new NotImplementedException(); + using (RegistryKey applicationKey = Registry.CurrentUser.CreateSubKey($@"Software\{ProjectName}")) + { + applicationKey.SetValue("InstallLocation", Directories.Base); + } + + using RegistryKey uninstallKey = Registry.CurrentUser.CreateSubKey($@"Software\Microsoft\Windows\CurrentVersion\Uninstall\{ProjectName}"); + + uninstallKey.SetValue("DisplayIcon", $"{Directories.Application},0"); + uninstallKey.SetValue("DisplayName", ProjectName); + uninstallKey.SetValue("DisplayVersion", Version); + + if (uninstallKey.GetValue("InstallDate") is null) + uninstallKey.SetValue("InstallDate", DateTime.Now.ToString("yyyyMMdd")); + + uninstallKey.SetValue("InstallLocation", Directories.Base); + uninstallKey.SetValue("NoRepair", 1); + uninstallKey.SetValue("Publisher", ProjectName); + 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/{ProjectRepository}"); + uninstallKey.SetValue("URLUpdateInfo", $"https://github.com/{ProjectRepository}/releases/latest"); } public void Unregister() { - throw new NotImplementedException(); - } - - public void CreateShortcuts() - { - throw new NotImplementedException(); + Registry.CurrentUser.DeleteSubKey($@"Software\{ProjectName}"); } } } \ No newline at end of file diff --git a/Kiseki.Launcher.Windows/MainWindow.cs b/Kiseki.Launcher.Windows/MainWindow.cs index 0981797..c6ac042 100644 --- a/Kiseki.Launcher.Windows/MainWindow.cs +++ b/Kiseki.Launcher.Windows/MainWindow.cs @@ -15,7 +15,7 @@ namespace Kiseki.Launcher.Windows Page = new TaskDialogPage() { - Caption = "Kiseki", + Caption = Launcher.ProjectName, AllowMinimize = true, ProgressBar = new TaskDialogProgressBar() @@ -26,7 +26,7 @@ namespace Kiseki.Launcher.Windows Buttons = { CloseButton } }; - Controller = new Controller("test.kiseki.lol", args); + Controller = new Controller(Launcher.BaseUrl, args); Controller.PageHeadingChanged += Controller_PageHeadingChanged; Controller.ProgressBarChanged += Controller_ProgressBarChanged; Controller.ProgressBarStateChanged += Controller_ProgressBarStateChanged; @@ -84,4 +84,4 @@ namespace Kiseki.Launcher.Windows TaskDialog.ShowDialog(Page); } } -} +} \ No newline at end of file diff --git a/Kiseki.Launcher.Windows/Program.cs b/Kiseki.Launcher.Windows/Program.cs index 91e0924..54176c7 100644 --- a/Kiseki.Launcher.Windows/Program.cs +++ b/Kiseki.Launcher.Windows/Program.cs @@ -2,14 +2,9 @@ namespace Kiseki.Launcher.Windows { internal static class Program { - /// - /// The main entry point for the application. - /// [STAThread] static void Main(string[] args) { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); Application.Run(new MainWindow(args)); } diff --git a/Kiseki.Launcher.Windows/Protocol.cs b/Kiseki.Launcher.Windows/Protocol.cs index d6d4b22..8766841 100644 --- a/Kiseki.Launcher.Windows/Protocol.cs +++ b/Kiseki.Launcher.Windows/Protocol.cs @@ -4,6 +4,8 @@ namespace Kiseki.Launcher.Windows { public class Protocol : IProtocol { + public const string ProtocolKey = "kiseki"; + public void Register(string key, string name, string handler) { string arguments = $"\"{handler}\" \"%1\""; @@ -30,17 +32,7 @@ namespace Kiseki.Launcher.Windows public void Unregister(string key) { - try - { - Registry.CurrentUser.DeleteSubKeyTree(@$"Software\Classes\{key}"); - } - catch (Exception) - { - // Key doesn't exist (and why are we here?) -#if DEBUG - throw; -#endif - } + Registry.CurrentUser.DeleteSubKeyTree(@$"Software\Classes\{key}"); } } } \ No newline at end of file diff --git a/Kiseki.Launcher/Interfaces.cs b/Kiseki.Launcher/Interfaces.cs index 891ef08..2fd07c4 100644 --- a/Kiseki.Launcher/Interfaces.cs +++ b/Kiseki.Launcher/Interfaces.cs @@ -4,7 +4,6 @@ namespace Kiseki.Launcher { void Register(); void Unregister(); - void CreateShortcuts(); } interface IProtocol diff --git a/README.md b/README.md index a7615a9..626581a 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,6 @@ Launches Kiseki game clients from the website # License -Kiseki.Launcher is licensed under the Licensed under the [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.txt). A copy of it has been included with Kiseki.Launcher. \ No newline at end of file +Kiseki.Launcher is licensed under the Licensed under the [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.txt). A copy of it has been included with Kiseki.Launcher. + +Some parts of Kiseki.Launcher are loosely adapted from [@pizzaboxer/bloxstrap](https://github.com/pizzaboxer/bloxstrap). Bloxstrap is a project licensed under the [MIT license](https://github.com/pizzaboxer/bloxstrap/blob/main/LICENSE). \ No newline at end of file