From bef10dc175cee671fa9b91e3c22bc74c7a0a53c7 Mon Sep 17 00:00:00 2001 From: adelikat Date: Mon, 28 Oct 2013 01:04:38 +0000 Subject: [PATCH] clean up movie saving, dont' pass around a streamwriter --- BizHawk.Client.Common/movie/Movie.cs | 16 +++++++++----- BizHawk.Client.Common/movie/MovieHeader.cs | 23 +++++++++++++++++---- BizHawk.Client.Common/movie/MovieLog.cs | 8 ------- BizHawk.Client.Common/movie/SubtitleList.cs | 8 ------- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/BizHawk.Client.Common/movie/Movie.cs b/BizHawk.Client.Common/movie/Movie.cs index 8924cab359..689ad3953c 100644 --- a/BizHawk.Client.Common/movie/Movie.cs +++ b/BizHawk.Client.Common/movie/Movie.cs @@ -780,21 +780,27 @@ namespace BizHawk.Client.Common WriteBinary(fs); } - private void WriteText(Stream stream) { using (StreamWriter sw = new StreamWriter(stream)) { - Header.WriteText(sw); + sw.Write(Header.ToString()); //TODO: clean this up - if (_loopOffset >= 0) + if (_loopOffset.HasValue) { sw.WriteLine("LoopOffset " + _loopOffset.ToString()); } - Subtitles.WriteText(sw); - _log.WriteText(sw); + foreach (var subtitle in Subtitles) + { + sw.WriteLine(subtitle.ToString()); + } + + for (int i = 0; i < _log.Length; i++) + { + sw.WriteLine(_log[i]); + } } } diff --git a/BizHawk.Client.Common/movie/MovieHeader.cs b/BizHawk.Client.Common/movie/MovieHeader.cs index ef8e7b3cd5..ac424678be 100644 --- a/BizHawk.Client.Common/movie/MovieHeader.cs +++ b/BizHawk.Client.Common/movie/MovieHeader.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO; +using System.Text; namespace BizHawk.Client.Common { @@ -104,22 +105,36 @@ namespace BizHawk.Client.Common HeaderParams[key] = value; } - public void WriteText(StreamWriter sw) + public override string ToString() { + StringBuilder sb = new StringBuilder(); + foreach (KeyValuePair kvp in HeaderParams) { - sw.WriteLine(kvp.Key + " " + kvp.Value); + sb + .Append(kvp.Key) + .Append(' ') + .Append(kvp.Value) + .AppendLine(); } foreach (KeyValuePair kvp in BoardProperties) { - sw.WriteLine(BOARDPROPERTIES + " " + kvp.Key + " " + kvp.Value); + sb + .Append(BOARDPROPERTIES) + .Append(' ') + .Append(kvp.Key) + .Append(' ') + .Append(kvp.Value) + .AppendLine(); } foreach (string t in Comments) { - sw.WriteLine(t); + sb.AppendLine(t); } + + return sb.ToString(); } private string ParseHeader(string line, string headerName) diff --git a/BizHawk.Client.Common/movie/MovieLog.cs b/BizHawk.Client.Common/movie/MovieLog.cs index 1d1796a4e7..c5654cdf46 100644 --- a/BizHawk.Client.Common/movie/MovieLog.cs +++ b/BizHawk.Client.Common/movie/MovieLog.cs @@ -177,14 +177,6 @@ namespace BizHawk.Client.Common } } - public void WriteText(StreamWriter sw) - { - foreach (var record in _movie_records) - { - sw.WriteLine(record); - } - } - public void TruncateMovie(int frame) { if (frame < _movie_records.Count) diff --git a/BizHawk.Client.Common/movie/SubtitleList.cs b/BizHawk.Client.Common/movie/SubtitleList.cs index b9ee196541..83aa8e6d07 100644 --- a/BizHawk.Client.Common/movie/SubtitleList.cs +++ b/BizHawk.Client.Common/movie/SubtitleList.cs @@ -109,13 +109,5 @@ namespace BizHawk.Client.Common _subtitles.RemoveAt(index); } - - public void WriteText(StreamWriter sw) - { - foreach(var subtitle in _subtitles) - { - sw.WriteLine(subtitle.ToString()); - } - } } } \ No newline at end of file