mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-15 05:04:16 +01:00
Fix saving issue.
This commit is contained in:
parent
e65b7454fe
commit
4ecad9a5d2
3 changed files with 156 additions and 134 deletions
|
|
@ -342,7 +342,7 @@ public class CharacterSave
|
|||
WriteEquipment = oldEquip;
|
||||
}
|
||||
|
||||
public void Load(string base64)
|
||||
public void Load(string base64, out bool oldVersion)
|
||||
{
|
||||
var bytes = Convert.FromBase64String(base64);
|
||||
switch (bytes[0])
|
||||
|
|
@ -352,10 +352,12 @@ public class CharacterSave
|
|||
CheckRange(2, bytes[1], 0, 1);
|
||||
Alpha = 1.0f;
|
||||
bytes[0] = CurrentVersion;
|
||||
oldVersion = true;
|
||||
break;
|
||||
case 2:
|
||||
CheckSize(bytes.Length, TotalSizeVersion2);
|
||||
CheckRange(2, bytes[1], 0, 0x3F);
|
||||
oldVersion = false;
|
||||
break;
|
||||
default: throw new Exception($"Can not parse Base64 string into CharacterSave:\n\tInvalid Version {bytes[0]}.");
|
||||
}
|
||||
|
|
@ -364,13 +366,16 @@ public class CharacterSave
|
|||
bytes.CopyTo(_bytes, 0);
|
||||
}
|
||||
|
||||
public static CharacterSave FromString(string base64)
|
||||
public static CharacterSave FromString(string base64, out bool oldVersion)
|
||||
{
|
||||
var ret = new CharacterSave();
|
||||
ret.Load(base64);
|
||||
ret.Load(base64, out oldVersion);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static CharacterSave FromString(string base64)
|
||||
=> FromString(base64, out _);
|
||||
|
||||
public unsafe ref CharacterCustomization Customizations
|
||||
{
|
||||
get
|
||||
|
|
|
|||
|
|
@ -5,11 +5,12 @@ using System.Linq;
|
|||
using Dalamud.Logging;
|
||||
using Glamourer.FileSystem;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Glamourer.Designs
|
||||
namespace Glamourer.Designs;
|
||||
|
||||
public class DesignManager
|
||||
{
|
||||
public class DesignManager
|
||||
{
|
||||
public const string FileName = "Designs.json";
|
||||
private readonly FileInfo _saveFile;
|
||||
|
||||
|
|
@ -131,29 +132,45 @@ namespace Glamourer.Designs
|
|||
public void LoadFromFile()
|
||||
{
|
||||
_saveFile.Refresh();
|
||||
SortedList<string, CharacterSave>? designs = null;
|
||||
Designs = new SortedList<string, CharacterSave>();
|
||||
var changes = false;
|
||||
if (_saveFile.Exists)
|
||||
try
|
||||
{
|
||||
var data = File.ReadAllText(_saveFile.FullName);
|
||||
designs = JsonConvert.DeserializeObject<SortedList<string, CharacterSave>>(data);
|
||||
var json = JsonConvert.DeserializeObject<Dictionary<string, string>>(data);
|
||||
if (json == null)
|
||||
{
|
||||
PluginLog.Error($"Save file {_saveFile.FullName} corrupted.");
|
||||
json = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
foreach (var (name, saveString) in json)
|
||||
{
|
||||
try
|
||||
{
|
||||
var save = CharacterSave.FromString(saveString, out var oldVersion);
|
||||
changes |= oldVersion;
|
||||
changes |= !Designs.TryAdd(name, save);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PluginLog.Error($"Character Save for {name} is invalid:\n{e}");
|
||||
changes = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PluginLog.Error($"Could not load save file {_saveFile.FullName}:\n{e}");
|
||||
}
|
||||
|
||||
if (designs == null)
|
||||
{
|
||||
Designs = new SortedList<string, CharacterSave>();
|
||||
SaveToFile();
|
||||
changes = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Designs = designs;
|
||||
}
|
||||
changes = true;
|
||||
|
||||
if (changes)
|
||||
SaveToFile();
|
||||
|
||||
BuildStructure();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace Glamourer.Gui
|
|||
|
||||
try
|
||||
{
|
||||
_selection!.Data = CharacterSave.FromString(text);
|
||||
_selection!.Data.Load(text, out _);
|
||||
_designs.SaveToFile();
|
||||
}
|
||||
catch (Exception e)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue