movie: rework how sinksettings are saved/loaded

This commit is contained in:
goyuken 2014-05-18 17:15:51 +00:00
parent f69fd00458
commit 16a347565b
3 changed files with 36 additions and 14 deletions

View File

@ -63,5 +63,35 @@ namespace BizHawk.Client.Common
Serializer.Serialize(w, config); Serializer.Serialize(w, config);
} }
} }
// movie 1.0 header stuff
private class TypeNameEncapsulator
{
public object o;
}
public static object LoadWithType(string serialized)
{
using (TextReader tr = new StringReader(serialized))
using (JsonTextReader jr = new JsonTextReader(tr))
{
TypeNameEncapsulator tne = (TypeNameEncapsulator)Serializer.Deserialize(jr, typeof(TypeNameEncapsulator));
return tne.o;
}
}
public static string SaveWithType(object o)
{
using (StringWriter sw = new StringWriter())
using (JsonTextWriter jw = new JsonTextWriter(sw) { Formatting = Formatting.None })
{
TypeNameEncapsulator tne = new TypeNameEncapsulator { o = o };
Serializer.Serialize(jw, tne, typeof(TypeNameEncapsulator));
sw.Flush();
return sw.ToString();
}
}
} }
} }

View File

@ -49,25 +49,17 @@ namespace BizHawk.Client.EmuHawk
if (Global.MovieSession.Movie.Header[HeaderKeys.CORE] == quicknesName) if (Global.MovieSession.Movie.Header[HeaderKeys.CORE] == quicknesName)
{ {
Global.Config.NES_InQuickNES = true; Global.Config.NES_InQuickNES = true;
_syncSettingsHack = JsonConvert.DeserializeObject(
Global.MovieSession.Movie.Header.SyncSettingsJson,
typeof(QuickNES.QuickNESSyncSettings));
} }
else else
{ {
Global.Config.NES_InQuickNES = false; Global.Config.NES_InQuickNES = false;
_syncSettingsHack = JsonConvert.DeserializeObject(
Global.MovieSession.Movie.Header.SyncSettingsJson,
typeof(NES.NESSyncSettings));
} }
} }
string s = Global.MovieSession.Movie.Header.SyncSettingsJson;
_syncSettingsHack = JsonConvert.DeserializeObject( if (!string.IsNullOrWhiteSpace(s))
Global.MovieSession.Movie.Header.SyncSettingsJson, {
Global.Emulator.GetSyncSettings().GetType()); _syncSettingsHack = ConfigService.LoadWithType(Global.MovieSession.Movie.Header.SyncSettingsJson);
}
LoadRom(GlobalWin.MainForm.CurrentlyOpenRom, true, !record); LoadRom(GlobalWin.MainForm.CurrentlyOpenRom, true, !record);
} }
finally finally

View File

@ -103,7 +103,7 @@ namespace BizHawk.Client.EmuHawk
_movieToRecord.Header[HeaderKeys.PLATFORM] = Global.Game.System; _movieToRecord.Header[HeaderKeys.PLATFORM] = Global.Game.System;
// Sync Settings, for movies 1.0, just dump a json blob into a header line // Sync Settings, for movies 1.0, just dump a json blob into a header line
_movieToRecord.Header[HeaderKeys.SYNCSETTINGS] = JsonConvert.SerializeObject(Global.Emulator.GetSyncSettings()); _movieToRecord.Header[HeaderKeys.SYNCSETTINGS] = ConfigService.SaveWithType(Global.Emulator.GetSyncSettings());
if (Global.Game != null) if (Global.Game != null)
{ {