mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 18:27:24 +01:00
Add automatic restore from backup for sort_order and active_collections for now.
This commit is contained in:
parent
5a24d9155b
commit
40b6c6022a
4 changed files with 36 additions and 15 deletions
2
OtterGui
2
OtterGui
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6eb6ab156c1bc1cb61700f19768f3fa6c11e1e04
|
Subproject commit 0f8a866491b246e819e0618a43078170686780ab
|
||||||
|
|
@ -408,21 +408,17 @@ public class ActiveCollections : ISavable, IDisposable
|
||||||
public static bool Load(FilenameService fileNames, out JObject ret)
|
public static bool Load(FilenameService fileNames, out JObject ret)
|
||||||
{
|
{
|
||||||
var file = fileNames.ActiveCollectionsFile;
|
var file = fileNames.ActiveCollectionsFile;
|
||||||
if (File.Exists(file))
|
var jObj = BackupService.GetJObjectForFile(fileNames, file);
|
||||||
try
|
if (jObj == null)
|
||||||
{
|
{
|
||||||
ret = JObject.Parse(File.ReadAllText(file));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Penumbra.Log.Error($"Could not read active collections from file {file}:\n{e}");
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = new JObject();
|
ret = new JObject();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = jObj;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public string RedundancyCheck(CollectionType type, ActorIdentifier id)
|
public string RedundancyCheck(CollectionType type, ActorIdentifier id)
|
||||||
{
|
{
|
||||||
var checkAssignment = ByType(type, id);
|
var checkAssignment = ByType(type, id);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using OtterGui.Classes;
|
||||||
using OtterGui.Filesystem;
|
using OtterGui.Filesystem;
|
||||||
using Penumbra.Communication;
|
using Penumbra.Communication;
|
||||||
using Penumbra.Services;
|
using Penumbra.Services;
|
||||||
|
|
@ -60,8 +62,8 @@ public sealed class ModFileSystem : FileSystem<Mod>, IDisposable, ISavable
|
||||||
// Used on construction and on mod rediscoveries.
|
// Used on construction and on mod rediscoveries.
|
||||||
private void Reload()
|
private void Reload()
|
||||||
{
|
{
|
||||||
// TODO
|
var jObj = BackupService.GetJObjectForFile(_saveService.FileNames, _saveService.FileNames.FilesystemFile);
|
||||||
if (Load(new FileInfo(_saveService.FileNames.FilesystemFile), _modManager, ModToIdentifier, ModToName))
|
if (Load(jObj, _modManager, ModToIdentifier, ModToName))
|
||||||
_saveService.ImmediateSave(this);
|
_saveService.ImmediateSave(this);
|
||||||
|
|
||||||
Penumbra.Log.Debug("Reloaded mod filesystem.");
|
Penumbra.Log.Debug("Reloaded mod filesystem.");
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using OtterGui.Classes;
|
using OtterGui.Classes;
|
||||||
using OtterGui.Log;
|
using OtterGui.Log;
|
||||||
using Penumbra.Util;
|
using Penumbra.Util;
|
||||||
|
|
@ -23,4 +24,26 @@ public class BackupService
|
||||||
list.Add(new FileInfo(fileNames.ActiveCollectionsFile));
|
list.Add(new FileInfo(fileNames.ActiveCollectionsFile));
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Try to parse a file to JObject and check backups if this does not succeed. </summary>
|
||||||
|
public static JObject? GetJObjectForFile(FilenameService fileNames, string fileName)
|
||||||
|
{
|
||||||
|
JObject? ret = null;
|
||||||
|
if (!File.Exists(fileName))
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var text = File.ReadAllText(fileName);
|
||||||
|
ret = JObject.Parse(text);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Penumbra.Log.Error($"Failed to load {fileName}, trying to restore from backup:\n{ex}");
|
||||||
|
Backup.TryGetFile(new DirectoryInfo(fileNames.ConfigDirectory), fileName, out ret, out var messages, JObject.Parse);
|
||||||
|
Penumbra.Chat.NotificationMessage(messages);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue