.tasproj - convert Session saving/loading to json. This is a breaking change, and older versions will silently fallback to defaults

This commit is contained in:
adelikat 2019-11-23 21:55:29 -06:00
parent b4c4c3b870
commit 289971c9e9
3 changed files with 11 additions and 33 deletions

View File

@ -66,7 +66,7 @@ namespace BizHawk.Client.Common
Branches.Save(bs);
}
bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(Session.ToString()));
bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(JsonConvert.SerializeObject(Session)));
if (_stateManager.Settings.SaveStateHistory && !backup)
{
@ -253,7 +253,15 @@ namespace BizHawk.Client.Common
bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr)
{
Session.PopulateFromString(tr.ReadToEnd());
var json = tr.ReadToEnd();
try
{
Session = JsonConvert.DeserializeObject<TasSession>(json);
}
catch
{
// Do nothing, and use default settings instead
}
});
if (!preload)

View File

@ -20,7 +20,7 @@ namespace BizHawk.Client.Common
public readonly IStringLog VerificationLog = StringLogUtil.MakeStringLog(); // For movies that do not begin with power-on, this is the input required to get into the initial state
public readonly TasBranchCollection Branches = new TasBranchCollection();
public readonly TasSession Session;
public TasSession Session { get; private set; }
public new const string Extension = "tasproj";
public const string DefaultProjectName = "default";

View File

@ -21,35 +21,5 @@ namespace BizHawk.Client.Common
CurrentFrame = Global.Emulator.Frame;
CurrentBranch = _movie.CurrentBranch;
}
public override string ToString()
{
UpdateValues();
var sb = new StringBuilder();
sb.AppendLine(CurrentFrame.ToString());
sb.AppendLine(CurrentBranch.ToString());
return sb.ToString();
}
public void PopulateFromString(string session)
{
if (!string.IsNullOrWhiteSpace(session))
{
string[] lines = session.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
CurrentFrame = lines.Length > 0 ? int.Parse(lines[0]) : 0;
if (lines.Length > 1)
{
CurrentBranch = int.Parse(lines[1]);
}
else
{
CurrentBranch = -1;
}
}
}
}
}