mirror of
https://github.com/JuniorDark/RustyHearts-Launcher.git
synced 2026-05-07 05:21:44 -04:00
Add project files.
This commit is contained in:
commit
5d3b4542bf
120 changed files with 36258 additions and 0 deletions
55
RHLauncher.Helper/Configuration.cs
Normal file
55
RHLauncher.Helper/Configuration.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
namespace RHLauncher.RHLauncher.Helper;
|
||||
|
||||
public class Configuration
|
||||
{
|
||||
private static readonly string DefaultIniFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.ini");
|
||||
|
||||
public static readonly Configuration Default = new();
|
||||
|
||||
private readonly IniFile iniFile = new(DefaultIniFilePath);
|
||||
|
||||
public Configuration()
|
||||
{
|
||||
string apiUrl = iniFile.ReadValue("Info", "LoginURL");
|
||||
|
||||
//Client endpoints
|
||||
GateXMLUrl = $"{apiUrl}/serverApi/gateway";
|
||||
GateInfoUrl = $"{apiUrl}/serverApi/gateway/info";
|
||||
GateStatusUrl = $"{apiUrl}/serverApi/gateway/status";
|
||||
|
||||
//Launcher endpoints
|
||||
LoginUrl = $"{apiUrl}/accountApi/login";
|
||||
RegisterUrl = $"{apiUrl}/accountApi/register";
|
||||
SendCodeUrl = $"{apiUrl}/accountApi/sendVerificationEmail";
|
||||
VerifyCodeUrl = $"{apiUrl}/accountApi/codeVerification";
|
||||
SendPasswordCodeUrl = $"{apiUrl}/accountApi/sendPasswordResetEmail";
|
||||
ChangePasswordUrl = $"{apiUrl}/accountApi/changePassword";
|
||||
LauncherNewsUrl = $"{apiUrl}/launcher/news";
|
||||
AgreementUrl = $"{apiUrl}/launcher/agreement";
|
||||
|
||||
//Client update endpoints
|
||||
FileListUrl = $"{apiUrl}/launcher/patch/filelist.txt";
|
||||
DownloadUpdateFileUrl = $"{apiUrl}/launcher/patch";
|
||||
|
||||
//Launcher update endpoints
|
||||
GetLauncherVersion = $"{apiUrl}/launcherApi/launcherUpdater/getLauncherVersion";
|
||||
UpdateLauncherVersion = $"{apiUrl}/launcherApi/launcherUpdater/updateLauncherVersion";
|
||||
}
|
||||
|
||||
public string GateXMLUrl { get; set; }
|
||||
public string GateInfoUrl { get; set; }
|
||||
public string GateStatusUrl { get; set; }
|
||||
public string LoginUrl { get; set; }
|
||||
public string RegisterUrl { get; set; }
|
||||
public string SendCodeUrl { get; set; }
|
||||
public string VerifyCodeUrl { get; set; }
|
||||
public string SendPasswordCodeUrl { get; set; }
|
||||
public string ChangePasswordUrl { get; set; }
|
||||
public string FileListUrl { get; set; }
|
||||
public string LauncherNewsUrl { get; set; }
|
||||
public string AgreementUrl { get; set; }
|
||||
public string GetLauncherVersion { get; set; }
|
||||
public string UpdateLauncherVersion { get; set; }
|
||||
public string DownloadUpdateFileUrl { get; set; }
|
||||
}
|
||||
|
||||
15
RHLauncher.Helper/ExceptionHandler.cs
Normal file
15
RHLauncher.Helper/ExceptionHandler.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using RHLauncher.Helper;
|
||||
|
||||
namespace RHLauncher.RHLauncher.Helper
|
||||
{
|
||||
public class ExceptionHandler
|
||||
{
|
||||
public static void HandleException(Exception ex, Exception exlog)
|
||||
{
|
||||
string errorMessage = $"Error: {ex.Message}";
|
||||
string errorLog = $"Error:{ex.Message} {Environment.NewLine} {exlog.Message}";
|
||||
Logger.WriteLog(errorLog);
|
||||
MsgBoxForm.Show(errorMessage, LocalizedStrings.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
RHLauncher.Helper/FormUtils.cs
Normal file
20
RHLauncher.Helper/FormUtils.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RHLauncher.Helper
|
||||
{
|
||||
public class FormUtils
|
||||
{
|
||||
public const int WM_NCLBUTTONDOWN = 0xA1;
|
||||
public const int HTCAPTION = 0x2;
|
||||
[DllImport("User32.dll")]
|
||||
private static extern bool ReleaseCapture();
|
||||
[DllImport("User32.dll")]
|
||||
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
|
||||
|
||||
public static void MoveForm(IntPtr handle)
|
||||
{
|
||||
ReleaseCapture();
|
||||
SendMessage(handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
42
RHLauncher.Helper/IniFile.cs
Normal file
42
RHLauncher.Helper/IniFile.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace RHLauncher.RHLauncher.Helper
|
||||
{
|
||||
public class IniFile
|
||||
{
|
||||
private readonly string _iniFilePath;
|
||||
|
||||
[DllImport("kernel32")]
|
||||
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
|
||||
|
||||
[DllImport("kernel32")]
|
||||
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
|
||||
|
||||
public IniFile(string iniFileName)
|
||||
{
|
||||
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
_iniFilePath = Path.Combine(appDirectory, iniFileName);
|
||||
|
||||
if (!File.Exists(_iniFilePath))
|
||||
{
|
||||
//Default api url
|
||||
WritePrivateProfileString("Info", "LoginURL", "http://localhost:3000", _iniFilePath);
|
||||
//Default client service
|
||||
WritePrivateProfileString("Info", "Service", "usa", _iniFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
public string ReadValue(string section, string key)
|
||||
{
|
||||
StringBuilder sb = new(255);
|
||||
GetPrivateProfileString(section, key, "", sb, 255, _iniFilePath);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public void WriteValue(string section, string key, string value)
|
||||
{
|
||||
WritePrivateProfileString(section, key, value, _iniFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
31
RHLauncher.Helper/Logger.cs
Normal file
31
RHLauncher.Helper/Logger.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
namespace RHLauncher.Helper;
|
||||
|
||||
public class Logger
|
||||
{
|
||||
public static void WriteLog(string message)
|
||||
{
|
||||
string appDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
|
||||
// Create log file directory if it doesn't exist
|
||||
string logFilePath = Path.Combine(appDirectory, "Logs");
|
||||
Directory.CreateDirectory(logFilePath);
|
||||
|
||||
// Create log file with today's date
|
||||
logFilePath = Path.Combine(logFilePath, "Log-" + DateTime.Today.ToString("MM-dd-yyyy") + ".txt");
|
||||
FileInfo logFileInfo = new(logFilePath);
|
||||
DirectoryInfo logDirInfo = new(logFileInfo.DirectoryName);
|
||||
if (!logDirInfo.Exists)
|
||||
{
|
||||
logDirInfo.Create();
|
||||
}
|
||||
|
||||
// Write log entry to file
|
||||
using FileStream fileStream = logFileInfo.Exists ? new FileStream(logFilePath, FileMode.Append) : logFileInfo.Create();
|
||||
using StreamWriter streamWriter = new(fileStream);
|
||||
streamWriter.WriteLine();
|
||||
streamWriter.WriteLine("Log Entry:");
|
||||
streamWriter.WriteLine("Date/Time: {0} {1}", DateTime.Now.ToLongDateString(), DateTime.Now.ToLongTimeString());
|
||||
streamWriter.WriteLine("Message: {0}", message);
|
||||
streamWriter.WriteLine("---------------------------");
|
||||
}
|
||||
}
|
||||
129
RHLauncher.Helper/RegistryHandler.cs
Normal file
129
RHLauncher.Helper/RegistryHandler.cs
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
using Microsoft.Win32;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace RHLauncher.Helper
|
||||
{
|
||||
public class RegistryHandler
|
||||
{
|
||||
private const string KEY_NAME = "RustyHearts\\UserInfo";
|
||||
private const string INSTALL_DIR_KEY = "InstallDirectory";
|
||||
private readonly RegistryKey key;
|
||||
|
||||
public RegistryHandler()
|
||||
{
|
||||
key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\" + KEY_NAME, true) ?? Registry.CurrentUser.CreateSubKey("SOFTWARE\\" + KEY_NAME);
|
||||
if (!KeyExist())
|
||||
{
|
||||
CreateKey();
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateKey()
|
||||
{
|
||||
string username = key.GetValue("Username")?.ToString() ?? string.Empty;
|
||||
string password = key.GetValue("Password")?.ToString() ?? string.Empty;
|
||||
string remember = (key.GetValue("Remember") as int?)?.ToString() ?? "0";
|
||||
string autoLogin = (key.GetValue("AutoLogin") as int?)?.ToString() ?? "0";
|
||||
|
||||
key.SetValue("Username", username);
|
||||
key.SetValue("Password", password);
|
||||
key.SetValue("Remember", remember);
|
||||
key.SetValue("AutoLogin", autoLogin);
|
||||
}
|
||||
|
||||
public bool KeyExist()
|
||||
{
|
||||
return key.GetValueNames().Length > 0;
|
||||
}
|
||||
|
||||
public void SaveValues(string username, string password, bool remember, bool autologin)
|
||||
{
|
||||
key.SetValue("Username", username ?? string.Empty);
|
||||
key.SetValue("Password", password != null ? Encrypt(password) : string.Empty);
|
||||
key.SetValue("Remember", remember ? 1 : 0, RegistryValueKind.DWord);
|
||||
key.SetValue("AutoLogin", autologin ? 1 : 0, RegistryValueKind.DWord);
|
||||
}
|
||||
|
||||
public void SaveUser(string username, bool remember)
|
||||
{
|
||||
key.SetValue("Username", username ?? string.Empty);
|
||||
key.SetValue("Remember", remember ? 1 : 0, RegistryValueKind.DWord);
|
||||
}
|
||||
|
||||
public void SaveInstallDirectory(string directory)
|
||||
{
|
||||
key.SetValue(INSTALL_DIR_KEY, directory ?? string.Empty);
|
||||
}
|
||||
|
||||
public string GetInstallDirectory()
|
||||
{
|
||||
return key.GetValue(INSTALL_DIR_KEY)?.ToString() ?? string.Empty;
|
||||
}
|
||||
|
||||
public void ClearInstallDirectory()
|
||||
{
|
||||
var value = key.GetValue(INSTALL_DIR_KEY)?.ToString();
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
key.DeleteValue(INSTALL_DIR_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteValues(string KEY_NAME)
|
||||
{
|
||||
var value = key.GetValue(KEY_NAME) as string ?? "";
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
key.DeleteValue(KEY_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearPassword()
|
||||
{
|
||||
key.SetValue("Password", string.Empty);
|
||||
}
|
||||
|
||||
public string?[] ReadValues()
|
||||
{
|
||||
if (KeyExist())
|
||||
{
|
||||
string?[] values = new string?[4];
|
||||
values[0] = (string?)key.GetValue("Username");
|
||||
if (!string.IsNullOrEmpty(values[0]))
|
||||
{
|
||||
string? encryptedPassword = (string?)key.GetValue("Password");
|
||||
if (!string.IsNullOrEmpty(encryptedPassword))
|
||||
{
|
||||
values[1] = Decrypt(encryptedPassword);
|
||||
}
|
||||
else
|
||||
{
|
||||
values[1] = string.Empty;
|
||||
}
|
||||
int? rememberValue = (int?)key.GetValue("Remember");
|
||||
values[2] = rememberValue?.ToString() ?? "0";
|
||||
int? autoLoginValue = (int?)key.GetValue("AutoLogin");
|
||||
values[3] = autoLoginValue?.ToString() ?? "0";
|
||||
return values;
|
||||
}
|
||||
}
|
||||
return new string?[] { string.Empty, string.Empty, "0", "0" };
|
||||
}
|
||||
|
||||
private static string Encrypt(string plainText)
|
||||
{
|
||||
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
|
||||
byte[] encryptedBytes = ProtectedData.Protect(plainTextBytes, null, DataProtectionScope.CurrentUser);
|
||||
return Convert.ToBase64String(encryptedBytes);
|
||||
}
|
||||
|
||||
private static string Decrypt(string encryptedText)
|
||||
{
|
||||
byte[] encryptedBytes = Convert.FromBase64String(encryptedText);
|
||||
byte[] plainTextBytes = ProtectedData.Unprotect(encryptedBytes, null, DataProtectionScope.CurrentUser);
|
||||
return Encoding.UTF8.GetString(plainTextBytes);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
41
RHLauncher.Helper/ServiceFileHandler.cs
Normal file
41
RHLauncher.Helper/ServiceFileHandler.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using System.Security.Cryptography;
|
||||
|
||||
namespace RHLauncher.RHLauncher.Helper
|
||||
{
|
||||
public class ServiceFileHandler
|
||||
{
|
||||
private readonly string _iniFilePath;
|
||||
private readonly string _installDirectory;
|
||||
|
||||
public ServiceFileHandler(string iniFileName, string installDirectory)
|
||||
{
|
||||
_iniFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, iniFileName);
|
||||
_installDirectory = installDirectory;
|
||||
}
|
||||
|
||||
public void UpdateService()
|
||||
{
|
||||
string service = new IniFile(_iniFilePath).ReadValue("Info", "Service");
|
||||
string md5 = CalculateMD5(service);
|
||||
|
||||
string serviceDatPath = Path.Combine(_installDirectory, "Service.dat");
|
||||
string[] lines = File.ReadAllLines(serviceDatPath);
|
||||
|
||||
string currentMd5 = lines[0];
|
||||
string currentService = string.Join(Environment.NewLine, lines, 1, lines.Length - 1);
|
||||
|
||||
if (currentMd5 != md5)
|
||||
{
|
||||
lines[0] = md5;
|
||||
File.WriteAllLines(serviceDatPath, lines);
|
||||
}
|
||||
}
|
||||
|
||||
private static string CalculateMD5(string input)
|
||||
{
|
||||
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
|
||||
byte[] hashBytes = MD5.HashData(inputBytes);
|
||||
return BitConverter.ToString(hashBytes).Replace("-", "").ToLower();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue