feat: implement licenses
This commit is contained in:
parent
98abb0566b
commit
9f75a83c6b
|
|
@ -45,4 +45,8 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="..\Kiseki.Launcher\**\*.cs" />
|
<Compile Include="..\Kiseki.Launcher\**\*.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Syroot.Windows.IO.KnownFolders" Version="1.3.0" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -2,6 +2,8 @@ using System.Reflection;
|
||||||
|
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
|
using Syroot.Windows.IO;
|
||||||
|
|
||||||
namespace Kiseki.Launcher.Windows
|
namespace Kiseki.Launcher.Windows
|
||||||
{
|
{
|
||||||
public class Launcher : ILauncher
|
public class Launcher : ILauncher
|
||||||
|
|
@ -24,10 +26,20 @@ namespace Kiseki.Launcher.Windows
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// We are in maintenance mode, so let's ask for a license.
|
// We are in maintenance mode, so let's ask for a license.
|
||||||
AskForLicense(Directories.License);
|
if (!File.Exists(Directories.License))
|
||||||
Web.LoadLicense(File.ReadAllText(Directories.License));
|
{
|
||||||
|
AskForLicense(Directories.License);
|
||||||
|
}
|
||||||
|
|
||||||
// ... try this again;
|
// ... 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);
|
||||||
|
AskForLicense(Directories.License, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ... and then try this again;
|
||||||
Install();
|
Install();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -35,21 +47,27 @@ namespace Kiseki.Launcher.Windows
|
||||||
// okay, now download the launcher from the Kiseki website...
|
// okay, now download the launcher from the Kiseki website...
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AskForLicense(string licensePath)
|
private static void AskForLicense(string licensePath, bool showDialog = true)
|
||||||
{
|
{
|
||||||
using OpenFileDialog dialog = new()
|
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;
|
||||||
{
|
|
||||||
Title = "Select your license file",
|
|
||||||
Filter = "License files (*.bin)|*.bin",
|
|
||||||
InitialDirectory = Directories.Base
|
|
||||||
};
|
|
||||||
|
|
||||||
if (dialog.ShowDialog() == DialogResult.OK)
|
if (answer == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
File.Copy(dialog.FileName, licensePath, true);
|
using OpenFileDialog dialog = new()
|
||||||
|
{
|
||||||
|
Title = "Select your license file",
|
||||||
|
Filter = "License files (*.bin)|*.bin",
|
||||||
|
InitialDirectory = KnownFolders.Downloads.Path
|
||||||
|
};
|
||||||
|
|
||||||
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
File.Copy(dialog.FileName, licensePath, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.ProjectName}"))
|
||||||
|
|
@ -76,6 +94,7 @@ namespace Kiseki.Launcher.Windows
|
||||||
uninstallKey.SetValue("URLUpdateInfo", $"https://github.com/{Constants.ProjectRepository}/releases/latest");
|
uninstallKey.SetValue("URLUpdateInfo", $"https://github.com/{Constants.ProjectRepository}/releases/latest");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Implement this
|
||||||
public static void Unregister()
|
public static void Unregister()
|
||||||
{
|
{
|
||||||
Registry.CurrentUser.DeleteSubKey($@"Software\{Constants.ProjectName}");
|
Registry.CurrentUser.DeleteSubKey($@"Software\{Constants.ProjectName}");
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
using System.Net;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Kiseki.Launcher
|
namespace Kiseki.Launcher
|
||||||
{
|
{
|
||||||
public static class Web
|
public static class Web
|
||||||
|
|
@ -23,11 +26,36 @@ namespace Kiseki.Launcher
|
||||||
return response is null ? RESPONSE_FAILURE : response.Status;
|
return response is null ? RESPONSE_FAILURE : response.Status;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void LoadLicense(string license)
|
public static bool LoadLicense(string license)
|
||||||
{
|
{
|
||||||
CurrentUrl = $"{MaintenanceDomain}.{CurrentUrl}";
|
CurrentUrl = $"{MaintenanceDomain}.{CurrentUrl}";
|
||||||
|
|
||||||
|
// the "license" is actually just headers required to access the website.
|
||||||
|
// this can be cloudflare zero-trust headers (like what Kiseki does), or however
|
||||||
|
// else you'd like to do auth-walls. either way; it's just a JSON document that
|
||||||
|
// has each byte XORed by 55 (for some basic obfuscation).
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string json = "";
|
||||||
|
for (int i = 0; i < license.Length; i++)
|
||||||
|
{
|
||||||
|
json += (char)(license[i] ^ 55);
|
||||||
|
}
|
||||||
|
|
||||||
|
var headers = JsonSerializer.Deserialize<Dictionary<string, string>>(json)!;
|
||||||
|
for (int i = 0; i < headers.Count; i++)
|
||||||
|
{
|
||||||
|
HttpClient.DefaultRequestHeaders.Add(headers.ElementAt(i).Key, headers.ElementAt(i).Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue