78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using Mono.Options;
|
|
using Newtonsoft.Json;
|
|
using Pilz.Configuration;
|
|
using Telerik.WinControls;
|
|
|
|
namespace ModpackUpdater;
|
|
|
|
public static class Program
|
|
{
|
|
private static readonly SettingsManager settingsManager;
|
|
|
|
public static ISettings Settings => settingsManager.Instance;
|
|
|
|
static Program()
|
|
{
|
|
settingsManager = new(GetSettingsPath(2), true);
|
|
MigrateLegacySettings(GetSettingsPath(null));
|
|
}
|
|
|
|
[STAThread]
|
|
internal static void Main(string[] args)
|
|
{
|
|
var options = new Options(args);
|
|
if (options.InstallWithoutUi)
|
|
InstallWithoutGui(options.ProfileFolder, options.ModpackConfig);
|
|
else
|
|
RunApp();
|
|
}
|
|
|
|
private static void RunApp()
|
|
{
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
|
|
|
|
if (ThemeResolutionService.LoadPackageResource("ModpackUpdater.CustomThemes.Office2019DarkBluePurple.tssp"))
|
|
ThemeResolutionService.ApplicationThemeName = "Office2019DarkBluePurple";
|
|
|
|
Application.Run(new Form1());
|
|
}
|
|
|
|
private static string GetSettingsPath(int? settingsVersion = 2)
|
|
{
|
|
const string AppDataDirectoryName = "MinecraftModpackUpdater";
|
|
var fileNamePostfix = settingsVersion == null ? string.Empty : $"V{settingsVersion}";
|
|
var SettingsFileName = $"Settings{fileNamePostfix}.json";
|
|
|
|
var settingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), AppDataDirectoryName);
|
|
Directory.CreateDirectory(settingsPath);
|
|
settingsPath = Path.Combine(settingsPath, SettingsFileName);
|
|
|
|
return settingsPath;
|
|
}
|
|
|
|
private static void MigrateLegacySettings(string settingsPath)
|
|
{
|
|
// Try load legacy config file
|
|
if (!File.Exists(settingsPath) || JsonConvert.DeserializeObject<AppConfig>(File.ReadAllText(settingsPath)) is not AppConfig legacyConfig)
|
|
return;
|
|
|
|
// Migrate
|
|
var newConfig = Settings.Get<AppConfig>();
|
|
newConfig.LastMinecraftProfilePath = legacyConfig.LastMinecraftProfilePath;
|
|
newConfig.LastConfigFilePath = legacyConfig.LastConfigFilePath;
|
|
|
|
// Ensure save settings
|
|
settingsManager.Save();
|
|
|
|
// Delete legacy config file
|
|
File.Delete(settingsPath);
|
|
}
|
|
|
|
private static void InstallWithoutGui(string profileFolder, string modpackConfig)
|
|
{
|
|
|
|
}
|
|
}
|