1
mirror of https://github.com/thepeacockproject/Peacock synced 2024-11-22 22:12:45 +01:00
Peacock/patcher/Settings.cs
Reece Dunham 6245e91624 Initial commit
Co-authored-by: Tino Roivanen <tino.roivanen98@gmail.com>
Co-authored-by: Govert de Gans <grappigegovert@hotmail.com>
Co-authored-by: Gray Olson <gray@grayolson.com>
Co-authored-by: Alexandre Sanchez <alex73630@gmail.com>
Co-authored-by: Anthony Fuller <24512050+anthonyfuller@users.noreply.github.com>
Co-authored-by: atampy25 <24306974+atampy25@users.noreply.github.com>
Co-authored-by: David <davidstulemeijer@gmail.com>
Co-authored-by: c0derMo <c0dermo@users.noreply.github.com>
Co-authored-by: Jeevat Singh <jeevatt.singh@gmail.com>
Signed-off-by: Reece Dunham <me@rdil.rocks>
2022-10-19 21:33:45 -04:00

123 lines
4.5 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
namespace HitmanPatcher
{
public class Settings
{
public MemoryPatcher.Options patchOptions;
public bool startInTray;
public bool minimizeToTray;
public bool darkModeEnabled;
public List<string> trayDomains;
public Settings()
{
// Default settings
patchOptions = new MemoryPatcher.Options
{
CustomConfigDomain = "127.0.0.1",
UseHttp = true,
DisableCertPinning = true,
AlwaysSendAuthHeader = true,
SetCustomConfigDomain = true,
DisableForceOfflineOnFailedDynamicResources = true,
};
darkModeEnabled = false;
startInTray = false;
minimizeToTray = false;
trayDomains = new List<string>();
}
private static string GetSavePath()
{
if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\PeacockProject"))
{
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\PeacockProject");
}
string appData = Environment.GetFolderPath(Environment
.SpecialFolder
.ApplicationData);
string folder = $@"{appData}\PeacockProject\";
string config1 = folder + "peacock_patcher.conf";
string config2 = folder + "peacock_patcher2.conf";
if (File.Exists(config1))
{
File.Delete(config1);
}
return config2;
}
public void SaveToFile()
{
List<string> lines = new List<string>();
lines.Add(string.Format("CustomConfigDomain={0}", patchOptions.CustomConfigDomain));
lines.Add(string.Format("UseHttp={0}", patchOptions.UseHttp));
lines.Add(string.Format("DisableForceDynamicResources={0}", patchOptions.DisableForceOfflineOnFailedDynamicResources));
lines.Add(string.Format("DarkModeEnabled={0}", darkModeEnabled));
lines.Add(string.Format("startInTray={0}", startInTray));
lines.Add(string.Format("minToTray={0}", minimizeToTray));
foreach (string domain in trayDomains)
{
lines.Add(string.Format("trayDomain={0}", domain));
}
File.WriteAllLines(GetSavePath(), lines);
}
public static Settings GetFromFile()
{
Settings result = new Settings();
if (File.Exists(GetSavePath()))
{
string[] lines = File.ReadAllLines(GetSavePath());
if (lines.Length == 1)
{
result.patchOptions.CustomConfigDomain = lines[0];
}
else
{
foreach (string line in lines)
{
if (line == "")
continue;
string[] linecontents = line.Split(new char[] { '=' }, 2);
switch (linecontents[0])
{
case "CustomConfigDomain":
result.patchOptions.CustomConfigDomain = linecontents[1];
break;
case "UseHttp":
result.patchOptions.UseHttp = bool.Parse(linecontents[1]);
break;
case "DisableForceDynamicResources":
result.patchOptions.DisableForceOfflineOnFailedDynamicResources = bool.Parse(linecontents[1]);
break;
case "DarkModeEnabled":
result.darkModeEnabled = bool.Parse(linecontents[1]);
break;
case "startInTray":
result.startInTray = bool.Parse(linecontents[1]);
break;
case "minToTray":
result.minimizeToTray = bool.Parse(linecontents[1]);
break;
case "trayDomain":
result.trayDomains.Add(linecontents[1]);
break;
}
}
}
}
return result;
}
}
}