mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-12 10:17:22 +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,19 +408,15 @@ public class ActiveCollections : ISavable, IDisposable
|
|||
public static bool Load(FilenameService fileNames, out JObject ret)
|
||||
{
|
||||
var file = fileNames.ActiveCollectionsFile;
|
||||
if (File.Exists(file))
|
||||
try
|
||||
{
|
||||
ret = JObject.Parse(File.ReadAllText(file));
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Penumbra.Log.Error($"Could not read active collections from file {file}:\n{e}");
|
||||
}
|
||||
var jObj = BackupService.GetJObjectForFile(fileNames, file);
|
||||
if (jObj == null)
|
||||
{
|
||||
ret = new JObject();
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = new JObject();
|
||||
return false;
|
||||
ret = jObj;
|
||||
return true;
|
||||
}
|
||||
|
||||
public string RedundancyCheck(CollectionType type, ActorIdentifier id)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OtterGui.Classes;
|
||||
using OtterGui.Filesystem;
|
||||
using Penumbra.Communication;
|
||||
using Penumbra.Services;
|
||||
|
|
@ -60,8 +62,8 @@ public sealed class ModFileSystem : FileSystem<Mod>, IDisposable, ISavable
|
|||
// Used on construction and on mod rediscoveries.
|
||||
private void Reload()
|
||||
{
|
||||
// TODO
|
||||
if (Load(new FileInfo(_saveService.FileNames.FilesystemFile), _modManager, ModToIdentifier, ModToName))
|
||||
var jObj = BackupService.GetJObjectForFile(_saveService.FileNames, _saveService.FileNames.FilesystemFile);
|
||||
if (Load(jObj, _modManager, ModToIdentifier, ModToName))
|
||||
_saveService.ImmediateSave(this);
|
||||
|
||||
Penumbra.Log.Debug("Reloaded mod filesystem.");
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using Newtonsoft.Json.Linq;
|
||||
using OtterGui.Classes;
|
||||
using OtterGui.Log;
|
||||
using Penumbra.Util;
|
||||
|
|
@ -23,4 +24,26 @@ public class BackupService
|
|||
list.Add(new FileInfo(fileNames.ActiveCollectionsFile));
|
||||
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