bk2 progress

This commit is contained in:
adelikat 2014-06-13 11:30:25 +00:00
parent b96ebaafeb
commit 032f8a9b21
4 changed files with 100 additions and 15 deletions

View File

@ -13,7 +13,11 @@ namespace BizHawk.Client.Common
Framebuffer, Framebuffer,
Input, Input,
CorestateText, CorestateText,
Movieheader
// Only for movies they probably shoudln't be leaching this stuff
Movieheader,
Comments,
Subtitles
} }
public class BinaryStateFileNames public class BinaryStateFileNames
@ -38,6 +42,10 @@ namespace BizHawk.Client.Common
LumpNames[BinaryStateLump.Input] = "Input Log"; LumpNames[BinaryStateLump.Input] = "Input Log";
LumpNames[BinaryStateLump.CorestateText] = "CoreText"; LumpNames[BinaryStateLump.CorestateText] = "CoreText";
LumpNames[BinaryStateLump.Movieheader] = "Header"; LumpNames[BinaryStateLump.Movieheader] = "Header";
// Only for movies they probably shoudln't be leaching this stuff
LumpNames[BinaryStateLump.Comments] = "Comments";
LumpNames[BinaryStateLump.Subtitles] = "Subtitles";
} }
public static string Get(BinaryStateLump lump) public static string Get(BinaryStateLump lump)

View File

@ -14,17 +14,8 @@ namespace BizHawk.Client.Common
get { return Header; } get { return Header; }
} }
public SubtitleList Subtitles public SubtitleList Subtitles { get; private set; }
{ public IList<string> Comments { get; private set; }
get;
private set;
}
public IList<string> Comments
{
get;
private set;
}
public string SyncSettingsJson public string SyncSettingsJson
{ {
@ -177,5 +168,17 @@ namespace BizHawk.Client.Common
get { return Header[HeaderKeys.FIRMWARESHA1]; } get { return Header[HeaderKeys.FIRMWARESHA1]; }
set { Header[HeaderKeys.FIRMWARESHA1] = value; } set { Header[HeaderKeys.FIRMWARESHA1] = value; }
} }
private string CommentsString()
{
StringBuilder sb = new StringBuilder();
foreach(var comment in Comments)
{
sb.AppendLine(comment);
}
return sb.ToString();
}
} }
} }

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -11,16 +12,50 @@ namespace BizHawk.Client.Common
{ {
public void Save() public void Save()
{ {
throw new NotImplementedException(); Write(Filename);
} }
public void SaveBackup() public void SaveBackup()
{ {
throw new NotImplementedException(); if (string.IsNullOrWhiteSpace(Filename))
{
return;
}
var backupName = Filename;
backupName = backupName.Insert(Filename.LastIndexOf("."), string.Format(".{0:yyyy-MM-dd HH.mm.ss}", DateTime.Now));
backupName = Path.Combine(Global.Config.PathEntries["Global", "Movie backups"].Path, Path.GetFileName(backupName));
var directory_info = new FileInfo(backupName).Directory;
if (directory_info != null)
{
Directory.CreateDirectory(directory_info.FullName);
}
Write(backupName);
} }
public bool Load() public bool Load()
{ {
var file = new FileInfo(Filename);
if (!file.Exists)
{
return false;
}
using (BinaryStateLoader bl = BinaryStateLoader.LoadAndDetect(Filename))
{
if (bl == null)
{
return false;
}
Header.Clear();
_log.Clear();
Subtitles.Clear();
Comments.Clear();
}
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -28,5 +63,27 @@ namespace BizHawk.Client.Common
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private void Write(string fn)
{
// Movies 2.0 TODO: Save and Load Movie version
// there's a lot of common code here with SavestateManager. refactor?
using (FileStream fs = new FileStream(Filename, FileMode.Create, FileAccess.Write))
using (BinaryStateSaver bs = new BinaryStateSaver(fs))
{
bs.PutLump(BinaryStateLump.Movieheader, (tw) => tw.WriteLine(Header.ToString()));
bs.PutLump(BinaryStateLump.Input, (tw) => tw.WriteLine(RawInputLog()));
bs.PutLump(BinaryStateLump.Comments, (tw) => tw.WriteLine(CommentsString()));
bs.PutLump(BinaryStateLump.Subtitles, (tw) => tw.WriteLine(Subtitles.ToString()));
if (StartsFromSavestate)
{
bs.PutLump(BinaryStateLump.CorestateText, (tw) => tw.WriteLine(SavestateBinaryBase64Blob));
}
}
Changes = false;
}
} }
} }

View File

@ -12,7 +12,13 @@ namespace BizHawk.Client.Common
public string GetInputLog() public string GetInputLog()
{ {
throw new NotImplementedException(); var sb = new StringBuilder();
sb.AppendLine("[Input]");
sb.Append(RawInputLog());
sb.AppendLine("[/Input]");
return sb.ToString();
} }
public bool ExtractInputLog(TextReader reader, out string errorMessage) public bool ExtractInputLog(TextReader reader, out string errorMessage)
@ -24,5 +30,16 @@ namespace BizHawk.Client.Common
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private StringBuilder RawInputLog()
{
var sb = new StringBuilder();
foreach (var record in _log)
{
sb.AppendLine(record);
}
return sb;
}
} }
} }