Refactor movie code - a Loaded property, removed a lot of code that was a work around for this needed feature, movie can not write to disk unless this property is true
This commit is contained in:
parent
ccae3cc1c9
commit
60a4ea4426
|
@ -367,10 +367,9 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
private void LoadMoviesFromRecent(string movie)
|
private void LoadMoviesFromRecent(string movie)
|
||||||
{
|
{
|
||||||
bool r;
|
Movie m = new Movie(movie, MOVIEMODE.PLAY);
|
||||||
Movie m = new Movie(movie, MOVIEMODE.PLAY, out r);
|
|
||||||
|
|
||||||
if (!r)
|
if (!m.Loaded)
|
||||||
{
|
{
|
||||||
Global.Sound.StopSound();
|
Global.Sound.StopSound();
|
||||||
DialogResult result = MessageBox.Show("Could not open " + movie + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
|
DialogResult result = MessageBox.Show("Could not open " + movie + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace BizHawk.MultiClient
|
||||||
private byte[] SoundBuffer;
|
private byte[] SoundBuffer;
|
||||||
private const int BufferSize = 4410 * 2 * 2; // 1/10th of a second, 2 bytes per sample, 2 channels;
|
private const int BufferSize = 4410 * 2 * 2; // 1/10th of a second, 2 bytes per sample, 2 channels;
|
||||||
//private int SoundBufferPosition; //TODO: use this
|
//private int SoundBufferPosition; //TODO: use this
|
||||||
bool needDiscard;
|
public bool needDiscard;
|
||||||
|
|
||||||
private BufferedAsync semisync = new BufferedAsync();
|
private BufferedAsync semisync = new BufferedAsync();
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,6 @@ namespace BizHawk.MultiClient
|
||||||
public enum MOVIEMODE { INACTIVE, PLAY, RECORD, FINISHED };
|
public enum MOVIEMODE { INACTIVE, PLAY, RECORD, FINISHED };
|
||||||
public class Movie
|
public class Movie
|
||||||
{
|
{
|
||||||
//TODO: preloaded flag + use it to make checks before doing things that require the movie to be loaded
|
|
||||||
|
|
||||||
public MovieHeader Header = new MovieHeader();
|
public MovieHeader Header = new MovieHeader();
|
||||||
public SubtitleList Subtitles = new SubtitleList();
|
public SubtitleList Subtitles = new SubtitleList();
|
||||||
public bool MakeBackup = true; //make backup before altering movie
|
public bool MakeBackup = true; //make backup before altering movie
|
||||||
|
@ -20,39 +18,13 @@ namespace BizHawk.MultiClient
|
||||||
public string Filename { get; private set; }
|
public string Filename { get; private set; }
|
||||||
public MOVIEMODE Mode { get; private set; }
|
public MOVIEMODE Mode { get; private set; }
|
||||||
public int Rerecords { get; private set; }
|
public int Rerecords { get; private set; }
|
||||||
public int Frames { get; private set; } //Only used when a movie is preloaded
|
private int Frames;
|
||||||
|
|
||||||
private MovieLog Log = new MovieLog();
|
private MovieLog Log = new MovieLog();
|
||||||
private int lastLog;
|
private int lastLog;
|
||||||
|
|
||||||
public bool StartsFromSavestate { get; private set; }
|
public bool StartsFromSavestate { get; private set; }
|
||||||
|
public bool Loaded { get; private set; }
|
||||||
/// <summary>
|
|
||||||
/// Allows checking if file exists
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename"></param>
|
|
||||||
/// <param name="m"></param>
|
|
||||||
/// <param name="exists"></param>
|
|
||||||
public Movie(string filename, MOVIEMODE m, out bool exists)
|
|
||||||
{
|
|
||||||
FileInfo f = new FileInfo(filename);
|
|
||||||
if (!f.Exists)
|
|
||||||
{
|
|
||||||
filename = "";
|
|
||||||
exists = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Filename = filename;
|
|
||||||
exists = true;
|
|
||||||
}
|
|
||||||
Mode = m;
|
|
||||||
lastLog = 0;
|
|
||||||
Rerecords = 0;
|
|
||||||
IsText = true;
|
|
||||||
Frames = 0;
|
|
||||||
StartsFromSavestate = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Movie(string filename, MOVIEMODE m)
|
public Movie(string filename, MOVIEMODE m)
|
||||||
{
|
{
|
||||||
|
@ -63,15 +35,17 @@ namespace BizHawk.MultiClient
|
||||||
IsText = true;
|
IsText = true;
|
||||||
Frames = 0;
|
Frames = 0;
|
||||||
StartsFromSavestate = false;
|
StartsFromSavestate = false;
|
||||||
|
Loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Movie()
|
public Movie()
|
||||||
{
|
{
|
||||||
Filename = ""; //Note: note this must be populated before playing movie
|
Filename = "";
|
||||||
Mode = MOVIEMODE.INACTIVE;
|
Mode = MOVIEMODE.INACTIVE;
|
||||||
IsText = true;
|
IsText = true;
|
||||||
Frames = 0;
|
Frames = 0;
|
||||||
StartsFromSavestate = false;
|
StartsFromSavestate = false;
|
||||||
|
Loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetSysID()
|
public string GetSysID()
|
||||||
|
@ -85,7 +59,10 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
public int Length()
|
public int Length()
|
||||||
{
|
{
|
||||||
return Log.Length();
|
if (Loaded)
|
||||||
|
return Log.Length();
|
||||||
|
else
|
||||||
|
return Frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void StopMovie()
|
public void StopMovie()
|
||||||
|
@ -150,6 +127,7 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
public void WriteMovie()
|
public void WriteMovie()
|
||||||
{
|
{
|
||||||
|
if (!Loaded) return;
|
||||||
if (Filename == "") return;
|
if (Filename == "") return;
|
||||||
Directory.CreateDirectory(new FileInfo(Filename).Directory.FullName);
|
Directory.CreateDirectory(new FileInfo(Filename).Directory.FullName);
|
||||||
if (IsText)
|
if (IsText)
|
||||||
|
@ -160,6 +138,7 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
public void WriteBackup()
|
public void WriteBackup()
|
||||||
{
|
{
|
||||||
|
if (!Loaded) return;
|
||||||
if (Filename == "") return;
|
if (Filename == "") return;
|
||||||
Directory.CreateDirectory(new FileInfo(Filename).Directory.FullName);
|
Directory.CreateDirectory(new FileInfo(Filename).Directory.FullName);
|
||||||
string BackupName = Filename;
|
string BackupName = Filename;
|
||||||
|
@ -195,7 +174,10 @@ namespace BizHawk.MultiClient
|
||||||
var file = new FileInfo(Filename);
|
var file = new FileInfo(Filename);
|
||||||
|
|
||||||
if (file.Exists == false)
|
if (file.Exists == false)
|
||||||
|
{
|
||||||
|
Loaded = false;
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Header.Clear();
|
Header.Clear();
|
||||||
|
@ -212,30 +194,11 @@ namespace BizHawk.MultiClient
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (str.Contains(MovieHeader.EMULATIONVERSION))
|
|
||||||
{
|
|
||||||
str = ParseHeader(str, MovieHeader.EMULATIONVERSION);
|
if (str.Contains(MovieHeader.RERECORDS))
|
||||||
Header.AddHeaderLine(MovieHeader.EMULATIONVERSION, str);
|
|
||||||
}
|
|
||||||
else if (str.Contains(MovieHeader.MOVIEVERSION))
|
|
||||||
{
|
|
||||||
str = ParseHeader(str, MovieHeader.MOVIEVERSION);
|
|
||||||
Header.AddHeaderLine(MovieHeader.MOVIEVERSION, str);
|
|
||||||
}
|
|
||||||
else if (str.Contains(MovieHeader.PLATFORM))
|
|
||||||
{
|
|
||||||
str = ParseHeader(str, MovieHeader.PLATFORM);
|
|
||||||
Header.AddHeaderLine(MovieHeader.PLATFORM, str);
|
|
||||||
}
|
|
||||||
else if (str.Contains(MovieHeader.GAMENAME))
|
|
||||||
{
|
|
||||||
str = ParseHeader(str, MovieHeader.GAMENAME);
|
|
||||||
Header.AddHeaderLine(MovieHeader.GAMENAME, str);
|
|
||||||
}
|
|
||||||
else if (str.Contains(MovieHeader.RERECORDS))
|
|
||||||
{
|
{
|
||||||
str = ParseHeader(str, MovieHeader.RERECORDS);
|
str = ParseHeader(str, MovieHeader.RERECORDS);
|
||||||
Header.AddHeaderLine(MovieHeader.RERECORDS, str);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Rerecords = int.Parse(str);
|
Rerecords = int.Parse(str);
|
||||||
|
@ -245,32 +208,20 @@ namespace BizHawk.MultiClient
|
||||||
Rerecords = 0;
|
Rerecords = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (str.Contains(MovieHeader.AUTHOR))
|
|
||||||
{
|
|
||||||
str = ParseHeader(str, MovieHeader.AUTHOR);
|
|
||||||
Header.AddHeaderLine(MovieHeader.AUTHOR, str);
|
|
||||||
}
|
|
||||||
else if (str.ToUpper().Contains(MovieHeader.GUID))
|
|
||||||
{
|
|
||||||
str = ParseHeader(str, MovieHeader.GUID);
|
|
||||||
Header.AddHeaderLine(MovieHeader.GUID, str);
|
|
||||||
}
|
|
||||||
else if (str.Contains(MovieHeader.STARTSFROMSAVESTATE))
|
else if (str.Contains(MovieHeader.STARTSFROMSAVESTATE))
|
||||||
{
|
{
|
||||||
str = ParseHeader(str, MovieHeader.STARTSFROMSAVESTATE);
|
str = ParseHeader(str, MovieHeader.STARTSFROMSAVESTATE);
|
||||||
Header.AddHeaderLine(MovieHeader.STARTSFROMSAVESTATE, str);
|
|
||||||
//NOTE: This can't get removed in favor of the MovieHeader function! Must refactor
|
|
||||||
if (str == "1")
|
if (str == "1")
|
||||||
StartsFromSavestate = true;
|
StartsFromSavestate = true;
|
||||||
}
|
}
|
||||||
else if (str.StartsWith("subtitle") || str.StartsWith("sub"))
|
|
||||||
|
if (Header.AddHeaderFromLine(str))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (str.StartsWith("subtitle") || str.StartsWith("sub"))
|
||||||
{
|
{
|
||||||
Subtitles.AddSubtitle(str);
|
Subtitles.AddSubtitle(str);
|
||||||
}
|
}
|
||||||
else if (str.StartsWith("comment"))
|
|
||||||
{
|
|
||||||
Header.Comments.Add(str);
|
|
||||||
}
|
|
||||||
else if (str[0] == '|')
|
else if (str[0] == '|')
|
||||||
{
|
{
|
||||||
Log.AddFrame(str);
|
Log.AddFrame(str);
|
||||||
|
@ -281,7 +232,7 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loaded = true;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -292,6 +243,7 @@ namespace BizHawk.MultiClient
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool PreLoadText()
|
public bool PreLoadText()
|
||||||
{
|
{
|
||||||
|
Loaded = false;
|
||||||
var file = new FileInfo(Filename);
|
var file = new FileInfo(Filename);
|
||||||
|
|
||||||
if (file.Exists == false)
|
if (file.Exists == false)
|
||||||
|
@ -315,14 +267,11 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
else if (Header.AddHeaderFromLine(str))
|
else if (Header.AddHeaderFromLine(str))
|
||||||
continue;
|
continue;
|
||||||
else if (str.StartsWith("subtitle") || str.StartsWith("sub"))
|
|
||||||
|
if (str.StartsWith("subtitle") || str.StartsWith("sub"))
|
||||||
{
|
{
|
||||||
Subtitles.AddSubtitle(str);
|
Subtitles.AddSubtitle(str);
|
||||||
}
|
}
|
||||||
else if (str.StartsWith("comment"))
|
|
||||||
{
|
|
||||||
Header.Comments.Add(str.Substring(8, str.Length - 8));
|
|
||||||
}
|
|
||||||
else if (str[0] == '|')
|
else if (str[0] == '|')
|
||||||
{
|
{
|
||||||
int line = str.Length + 1;
|
int line = str.Length + 1;
|
||||||
|
@ -348,8 +297,12 @@ namespace BizHawk.MultiClient
|
||||||
public bool LoadMovie()
|
public bool LoadMovie()
|
||||||
{
|
{
|
||||||
var file = new FileInfo(Filename);
|
var file = new FileInfo(Filename);
|
||||||
if (file.Exists == false) return false; //TODO: methods like writemovie will fail, some internal flag needs to prevent this
|
if (file.Exists == false)
|
||||||
//TODO: must determine if file is text or binary
|
{
|
||||||
|
Loaded = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return LoadText();
|
return LoadText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,6 +474,7 @@ namespace BizHawk.MultiClient
|
||||||
return -1; //Hack
|
return -1; //Hack
|
||||||
//This function will compare the movie data to the savestate movie data to see if they match
|
//This function will compare the movie data to the savestate movie data to see if they match
|
||||||
//TODO: Will eventually check header data too such as GUI
|
//TODO: Will eventually check header data too such as GUI
|
||||||
|
/*
|
||||||
MovieLog l = new MovieLog();
|
MovieLog l = new MovieLog();
|
||||||
string line;
|
string line;
|
||||||
while (true)
|
while (true)
|
||||||
|
@ -542,6 +496,7 @@ namespace BizHawk.MultiClient
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CompareTo(Movie Other, string parameter)
|
public int CompareTo(Movie Other, string parameter)
|
||||||
|
@ -657,10 +612,6 @@ namespace BizHawk.MultiClient
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private string ParseHeader(string line, string headerName)
|
private string ParseHeader(string line, string headerName)
|
||||||
{
|
{
|
||||||
string str;
|
string str;
|
||||||
|
|
Loading…
Reference in New Issue