SHA256
104 lines
3.2 KiB
C#
104 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using MelonLoader;
|
|
using MelonLoader.Utils;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace ADOFAIRenderer.Data
|
|
{
|
|
public class RenderPreset
|
|
{
|
|
public string Name { get; set; } = string.Empty;
|
|
public RenderConfig Config { get; set; } = null!;
|
|
}
|
|
|
|
public static class PresetManager
|
|
{
|
|
private static string GetPresetsDirectory()
|
|
{
|
|
return Path.Combine(MelonEnvironment.GameRootDirectory, "UserData", "ADOFAIRenderer", "Presets");
|
|
}
|
|
|
|
private static string GetSafeFileName(string name)
|
|
{
|
|
return Path.GetInvalidFileNameChars().Aggregate(name, (current, c) => current.Replace(c, '_'));
|
|
}
|
|
|
|
public static void SavePreset(string name, RenderConfig config)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
{
|
|
throw new ArgumentException("프리셋 이름은 비어 있을 수 없습니다.");
|
|
}
|
|
|
|
string dir = GetPresetsDirectory();
|
|
if (!Directory.Exists(dir))
|
|
{
|
|
Directory.CreateDirectory(dir);
|
|
}
|
|
|
|
var preset = new RenderPreset
|
|
{
|
|
Name = name,
|
|
Config = config
|
|
};
|
|
|
|
string json = JsonConvert.SerializeObject(preset, Formatting.Indented);
|
|
string safeName = GetSafeFileName(name);
|
|
string filePath = Path.Combine(dir, safeName + ".json");
|
|
File.WriteAllText(filePath, json);
|
|
}
|
|
|
|
public static List<RenderPreset> GetPresets()
|
|
{
|
|
var presets = new List<RenderPreset>();
|
|
string dir = GetPresetsDirectory();
|
|
if (!Directory.Exists(dir))
|
|
{
|
|
return presets;
|
|
}
|
|
|
|
try
|
|
{
|
|
string[] files = Directory.GetFiles(dir, "*.json");
|
|
foreach (string file in files)
|
|
{
|
|
try
|
|
{
|
|
string json = File.ReadAllText(file);
|
|
var preset = JsonConvert.DeserializeObject<RenderPreset>(json);
|
|
if (preset != null && !string.IsNullOrEmpty(preset.Name) && preset.Config != null)
|
|
{
|
|
presets.Add(preset);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MelonLogger.Warning($"프리셋 파일 '{Path.GetFileName(file)}' 로드 중 오류 발생: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MelonLogger.Error($"프리셋 목록을 불러오는 중 오류 발생: {ex.Message}");
|
|
}
|
|
|
|
return presets;
|
|
}
|
|
|
|
public static void DeletePreset(string name)
|
|
{
|
|
string dir = GetPresetsDirectory();
|
|
string safeName = GetSafeFileName(name);
|
|
string filePath = Path.Combine(dir, safeName + ".json");
|
|
|
|
if (File.Exists(filePath))
|
|
{
|
|
File.Delete(filePath);
|
|
}
|
|
}
|
|
}
|
|
}
|