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;
|
WriteEquipment = oldEquip;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Load(string base64)
|
public void Load(string base64, out bool oldVersion)
|
||||||
{
|
{
|
||||||
var bytes = Convert.FromBase64String(base64);
|
var bytes = Convert.FromBase64String(base64);
|
||||||
switch (bytes[0])
|
switch (bytes[0])
|
||||||
|
|
@ -352,10 +352,12 @@ public class CharacterSave
|
||||||
CheckRange(2, bytes[1], 0, 1);
|
CheckRange(2, bytes[1], 0, 1);
|
||||||
Alpha = 1.0f;
|
Alpha = 1.0f;
|
||||||
bytes[0] = CurrentVersion;
|
bytes[0] = CurrentVersion;
|
||||||
|
oldVersion = true;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
CheckSize(bytes.Length, TotalSizeVersion2);
|
CheckSize(bytes.Length, TotalSizeVersion2);
|
||||||
CheckRange(2, bytes[1], 0, 0x3F);
|
CheckRange(2, bytes[1], 0, 0x3F);
|
||||||
|
oldVersion = false;
|
||||||
break;
|
break;
|
||||||
default: throw new Exception($"Can not parse Base64 string into CharacterSave:\n\tInvalid Version {bytes[0]}.");
|
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);
|
bytes.CopyTo(_bytes, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CharacterSave FromString(string base64)
|
public static CharacterSave FromString(string base64, out bool oldVersion)
|
||||||
{
|
{
|
||||||
var ret = new CharacterSave();
|
var ret = new CharacterSave();
|
||||||
ret.Load(base64);
|
ret.Load(base64, out oldVersion);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CharacterSave FromString(string base64)
|
||||||
|
=> FromString(base64, out _);
|
||||||
|
|
||||||
public unsafe ref CharacterCustomization Customizations
|
public unsafe ref CharacterCustomization Customizations
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,12 @@ using System.Linq;
|
||||||
using Dalamud.Logging;
|
using Dalamud.Logging;
|
||||||
using Glamourer.FileSystem;
|
using Glamourer.FileSystem;
|
||||||
using Newtonsoft.Json;
|
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";
|
public const string FileName = "Designs.json";
|
||||||
private readonly FileInfo _saveFile;
|
private readonly FileInfo _saveFile;
|
||||||
|
|
||||||
|
|
@ -131,29 +132,45 @@ namespace Glamourer.Designs
|
||||||
public void LoadFromFile()
|
public void LoadFromFile()
|
||||||
{
|
{
|
||||||
_saveFile.Refresh();
|
_saveFile.Refresh();
|
||||||
SortedList<string, CharacterSave>? designs = null;
|
Designs = new SortedList<string, CharacterSave>();
|
||||||
|
var changes = false;
|
||||||
if (_saveFile.Exists)
|
if (_saveFile.Exists)
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var data = File.ReadAllText(_saveFile.FullName);
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
PluginLog.Error($"Could not load save file {_saveFile.FullName}:\n{e}");
|
PluginLog.Error($"Could not load save file {_saveFile.FullName}:\n{e}");
|
||||||
}
|
changes = true;
|
||||||
|
|
||||||
if (designs == null)
|
|
||||||
{
|
|
||||||
Designs = new SortedList<string, CharacterSave>();
|
|
||||||
SaveToFile();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
changes = true;
|
||||||
Designs = designs;
|
|
||||||
}
|
if (changes)
|
||||||
|
SaveToFile();
|
||||||
|
|
||||||
BuildStructure();
|
BuildStructure();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ namespace Glamourer.Gui
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_selection!.Data = CharacterSave.FromString(text);
|
_selection!.Data.Load(text, out _);
|
||||||
_designs.SaveToFile();
|
_designs.SaveToFile();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue