mirror of
https://github.com/JuniorDark/RustyHearts-Launcher.git
synced 2026-05-07 05:21:44 -04:00
57 lines
2 KiB
C#
57 lines
2 KiB
C#
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");
|
|
|
|
try
|
|
{
|
|
if (File.Exists(serviceDatPath))
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MsgBoxForm.Show("Service.dat file does not exist. Please check if the Install Directory is correct.", LocalizedStrings.Error);
|
|
return;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MsgBoxForm.Show("An error occurred while updating service: " + ex.Message, LocalizedStrings.Error);
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|