SHA256
Add Output Path Config Prototype
This commit is contained in:
1 parent
4097e14e7a
commit
43763b0b35
5 files changed
+478
-12
No files matched your search
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using MelonLoader;
|
||||
using MelonLoader.Utils;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ADOFAIRenderer.Data;
|
||||
|
||||
public class GlobalConfig
|
||||
{
|
||||
public string? OutputDirectory { get; set; }
|
||||
}
|
||||
|
||||
public static class GlobalSettings
|
||||
{
|
||||
private static string SettingsFilePath =>
|
||||
Path.Combine(MelonEnvironment.GameRootDirectory, "UserData", "ADOFAIRenderer", "global_settings.json");
|
||||
|
||||
public static GlobalConfig Current { get; set; } = new();
|
||||
|
||||
public static string DefaultOutputDirectory =>
|
||||
Path.Combine(MelonEnvironment.GameRootDirectory, "Render");
|
||||
|
||||
public static string EffectiveOutputDirectory
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(Current.OutputDirectory) && Directory.Exists(Current.OutputDirectory))
|
||||
{
|
||||
return Current.OutputDirectory;
|
||||
}
|
||||
|
||||
return DefaultOutputDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
static GlobalSettings()
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
||||
public static void Load()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(SettingsFilePath))
|
||||
{
|
||||
var json = File.ReadAllText(SettingsFilePath);
|
||||
Current = JsonConvert.DeserializeObject<GlobalConfig>(json) ?? new GlobalConfig();
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MelonLogger.Warning($"[GlobalSettings] Failed to load global settings: {ex.Message}");
|
||||
}
|
||||
|
||||
Current = new GlobalConfig();
|
||||
}
|
||||
|
||||
public static void Save()
|
||||
{
|
||||
try
|
||||
{
|
||||
var dir = Path.GetDirectoryName(SettingsFilePath);
|
||||
if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
var json = JsonConvert.SerializeObject(Current, Formatting.Indented);
|
||||
File.WriteAllText(SettingsFilePath, json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MelonLogger.Warning($"[GlobalSettings] Failed to save global settings: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user