mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-20 23:07:51 +01:00
Move ConfigurationFile to Luna.
This commit is contained in:
parent
ff6f7a1c75
commit
5e3f001f18
5 changed files with 14 additions and 71 deletions
2
Luna
2
Luna
|
|
@ -1 +1 @@
|
|||
Subproject commit 1f00860cbb38fecacde99e55461dbc251cb40f24
|
||||
Subproject commit 3fa2195ba9b34c4ce21e3180bf238edb488a4d35
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
using Dalamud.Interface.ImGuiNotification;
|
||||
using Luna;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Penumbra.Services;
|
||||
|
||||
namespace Penumbra;
|
||||
|
||||
public abstract class ConfigurationFile(SaveService saveService, TimeSpan? saveDelay = null) : ISavable, IService
|
||||
{
|
||||
public abstract int CurrentVersion { get; }
|
||||
|
||||
[JsonIgnore]
|
||||
protected readonly SaveService SaveService = saveService;
|
||||
|
||||
public virtual void Save()
|
||||
=> SaveService.DelaySave(this, SaveDelay);
|
||||
|
||||
protected TimeSpan SaveDelay { get; set; } = saveDelay ?? TimeSpan.FromMinutes(1);
|
||||
|
||||
public virtual void Save(StreamWriter writer)
|
||||
{
|
||||
using var j = new JsonTextWriter(writer);
|
||||
j.Formatting = Formatting.Indented;
|
||||
j.WriteStartObject();
|
||||
j.WritePropertyName("Version");
|
||||
j.WriteValue(CurrentVersion);
|
||||
AddData(j);
|
||||
j.WriteEndObject();
|
||||
}
|
||||
|
||||
protected abstract void AddData(JsonTextWriter j);
|
||||
protected abstract void LoadData(JObject j);
|
||||
|
||||
public abstract string ToFilePath(FilenameService fileNames);
|
||||
|
||||
protected virtual void Load()
|
||||
{
|
||||
var fileName = ToFilePath(SaveService.FileNames);
|
||||
var logName = ((ISavable)this).LogName(fileName);
|
||||
if (!File.Exists(fileName))
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
Penumbra.Log.Debug($"Reading {logName}...");
|
||||
var text = File.ReadAllText(fileName);
|
||||
var jObj = JObject.Parse(text);
|
||||
if (jObj["Version"]?.Value<int>() != CurrentVersion)
|
||||
throw new Exception("Unsupported version.");
|
||||
|
||||
LoadData(jObj);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Penumbra.Messager.NotificationMessage(ex, $"Error reading {logName}, reverting to default.",
|
||||
$"Error reading {logName}", NotificationType.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
using Luna;
|
||||
using Luna.Generators;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
|
@ -6,16 +7,17 @@ using Penumbra.Services;
|
|||
using Penumbra.UI.Classes;
|
||||
using Penumbra.UI.ModsTab.Selector;
|
||||
using Penumbra.UI.ResourceWatcher;
|
||||
using MessageService = Penumbra.Services.MessageService;
|
||||
|
||||
namespace Penumbra;
|
||||
|
||||
public sealed partial class FilterConfig : ConfigurationFile
|
||||
public sealed partial class FilterConfig : ConfigurationFile<FilenameService>
|
||||
{
|
||||
public override int CurrentVersion
|
||||
=> 1;
|
||||
|
||||
public FilterConfig(SaveService saveService)
|
||||
: base(saveService)
|
||||
public FilterConfig(SaveService saveService, MessageService messager)
|
||||
: base(saveService, messager)
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
|
@ -323,7 +325,7 @@ public sealed partial class FilterConfig : ConfigurationFile
|
|||
#region
|
||||
|
||||
[ConfigProperty]
|
||||
private bool _resourceLoggerEnabled = false;
|
||||
private bool _resourceLoggerEnabled;
|
||||
|
||||
[ConfigProperty]
|
||||
private int _resourceLoggerMaxEntries = 500;
|
||||
|
|
@ -332,7 +334,7 @@ public sealed partial class FilterConfig : ConfigurationFile
|
|||
private bool _resourceLoggerStoreOnlyMatching = true;
|
||||
|
||||
[ConfigProperty]
|
||||
private bool _resourceLoggerWriteToLog = false;
|
||||
private bool _resourceLoggerWriteToLog;
|
||||
|
||||
[ConfigProperty]
|
||||
private string _resourceLoggerLogFilter = string.Empty;
|
||||
|
|
|
|||
|
|
@ -3,13 +3,14 @@ using Luna.Generators;
|
|||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Penumbra.Services;
|
||||
using MessageService = Penumbra.Services.MessageService;
|
||||
|
||||
namespace Penumbra;
|
||||
|
||||
public sealed partial class UiConfig : ConfigurationFile
|
||||
public sealed partial class UiConfig : ConfigurationFile<FilenameService>
|
||||
{
|
||||
public UiConfig(SaveService saveService)
|
||||
: base(saveService, TimeSpan.FromMinutes(5))
|
||||
public UiConfig(SaveService saveService, MessageService messager)
|
||||
: base(saveService, messager, TimeSpan.FromMinutes(5))
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,8 +65,8 @@ public class MultiModPanel(ModFileSystem fileSystem, ModDataEditor editor, Prede
|
|||
{
|
||||
using var id = Im.Id.Push(i++);
|
||||
var (icon, text) = node is IFileSystemData<Mod> l
|
||||
? (FontAwesomeIcon.FileCircleMinus.Icon(), l.Value.Name)
|
||||
: (FontAwesomeIcon.FolderMinus.Icon(), string.Empty);
|
||||
? (LunaStyle.RemoveFileIcon, l.Value.Name)
|
||||
: (LunaStyle.RemoveFolderIcon, string.Empty);
|
||||
table.NextColumn();
|
||||
if (ImEx.Icon.Button(icon, "Remove from selection."u8, false, sizeType))
|
||||
fileSystem.Selection.RemoveFromSelection(node);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue