Made saving a little more convenient by putting it in its own thread. Might be very buggy still.
Also temporarily disabled reading TAStudio settings in PlaybackBox because of a NullReferenceException
This commit is contained in:
parent
c10682b147
commit
c3f51f8b39
|
@ -7,6 +7,8 @@ using System.Text;
|
|||
using BizHawk.Common;
|
||||
using BizHawk.Common.CollectionExtensions;
|
||||
using BizHawk.Common.IOExtensions;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
|
@ -15,8 +17,25 @@ namespace BizHawk.Client.Common
|
|||
public Func<string> ClientSettingsForSave { get; set; }
|
||||
public Action<string> GetClientSettingsOnLoad { get; set; }
|
||||
|
||||
private const double PROGRESS_STEP = 100 / 12; // TODO hardcoded for now, there might be a better way of doing this
|
||||
|
||||
private double _totalProgress = 0;
|
||||
|
||||
private void ReportProgress(double percent)
|
||||
{
|
||||
if (_progressReportWorker != null)
|
||||
{
|
||||
_totalProgress += percent;
|
||||
_progressReportWorker.ReportProgress((int)_totalProgress);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Write(string fn)
|
||||
{
|
||||
|
||||
|
||||
_totalProgress = 0;
|
||||
|
||||
var file = new FileInfo(fn);
|
||||
if (!file.Directory.Exists)
|
||||
{
|
||||
|
@ -26,22 +45,29 @@ namespace BizHawk.Client.Common
|
|||
using (var bs = new BinaryStateSaver(fn, false))
|
||||
{
|
||||
bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString()));
|
||||
ReportProgress(PROGRESS_STEP);
|
||||
bs.PutLump(BinaryStateLump.Comments, tw => tw.WriteLine(CommentsString()));
|
||||
ReportProgress(PROGRESS_STEP);
|
||||
bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString()));
|
||||
ReportProgress(PROGRESS_STEP);
|
||||
bs.PutLump(BinaryStateLump.SyncSettings, tw => tw.WriteLine(SyncSettingsJson));
|
||||
|
||||
ReportProgress(PROGRESS_STEP);
|
||||
bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog()));
|
||||
ReportProgress(PROGRESS_STEP);
|
||||
|
||||
// TasProj extras
|
||||
|
||||
bs.PutLump(BinaryStateLump.GreenzoneSettings, tw => tw.WriteLine(StateManager.Settings.ToString()));
|
||||
ReportProgress(PROGRESS_STEP);
|
||||
if (StateManager.Settings.SaveGreenzone)
|
||||
{
|
||||
bs.PutLump(BinaryStateLump.Greenzone, (BinaryWriter bw) => StateManager.Save(bw));
|
||||
}
|
||||
ReportProgress(PROGRESS_STEP);
|
||||
|
||||
bs.PutLump(BinaryStateLump.LagLog, (BinaryWriter bw) => LagLog.Save(bw));
|
||||
ReportProgress(PROGRESS_STEP);
|
||||
bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString()));
|
||||
ReportProgress(PROGRESS_STEP);
|
||||
|
||||
if (StartsFromSavestate)
|
||||
{
|
||||
|
@ -54,17 +80,19 @@ namespace BizHawk.Client.Common
|
|||
bs.PutLump(BinaryStateLump.Corestate, (BinaryWriter bw) => bw.Write(BinarySavestate));
|
||||
}
|
||||
}
|
||||
|
||||
ReportProgress(PROGRESS_STEP);
|
||||
if (ClientSettingsForSave != null)
|
||||
{
|
||||
var clientSettingsJson = ClientSettingsForSave();
|
||||
bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(clientSettingsJson));
|
||||
}
|
||||
ReportProgress(PROGRESS_STEP);
|
||||
|
||||
if (VerificationLog.Any())
|
||||
{
|
||||
bs.PutLump(BinaryStateLump.VerificationLog, tw => tw.WriteLine(InputLogToString(VerificationLog)));
|
||||
}
|
||||
ReportProgress(PROGRESS_STEP);
|
||||
}
|
||||
|
||||
Changes = false;
|
||||
|
|
|
@ -22,10 +22,12 @@ namespace BizHawk.Client.Common
|
|||
private readonly Dictionary<int, IController> InputStateCache = new Dictionary<int, IController>();
|
||||
private readonly List<string> VerificationLog = new List<string>(); // For movies that do not begin with power-on, this is the input required to get into the initial state
|
||||
|
||||
public TasMovie(string path, bool startsFromSavestate = false) : base(path)
|
||||
private BackgroundWorker _progressReportWorker = null;
|
||||
|
||||
public TasMovie(string path, bool startsFromSavestate = false, BackgroundWorker progressReportWorker = null) : base(path)
|
||||
{
|
||||
// TODO: how to call the default constructor AND the base(path) constructor? And is base(path) calling base() ?
|
||||
|
||||
_progressReportWorker = progressReportWorker;
|
||||
if (!Global.Emulator.HasSavestates())
|
||||
{
|
||||
throw new InvalidOperationException("Cannot create a TasMovie against a core that does not implement IStatable");
|
||||
|
@ -38,9 +40,10 @@ namespace BizHawk.Client.Common
|
|||
Markers.Add(0, startsFromSavestate ? "Savestate" : "Power on");
|
||||
}
|
||||
|
||||
public TasMovie(bool startsFromSavestate = false)
|
||||
public TasMovie(bool startsFromSavestate = false, BackgroundWorker progressReportWorker = null)
|
||||
: base()
|
||||
{
|
||||
_progressReportWorker = progressReportWorker;
|
||||
if (!Global.Emulator.HasSavestates())
|
||||
{
|
||||
throw new InvalidOperationException("Cannot create a TasMovie against a core that does not implement IStatable");
|
||||
|
|
|
@ -53,12 +53,15 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
get
|
||||
{
|
||||
return Tastudio.Settings.FollowCursor;
|
||||
return false;
|
||||
// FIXME
|
||||
//return Tastudio.Settings.FollowCursor;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
FollowCursorCheckbox.Checked = Tastudio.Settings.FollowCursor = value;
|
||||
// FIXME
|
||||
//FollowCursorCheckbox.Checked = Tastudio.Settings.FollowCursor = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,8 +83,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
if (Tastudio != null) // For the designer
|
||||
{
|
||||
AutoRestoreCheckbox.Checked = Tastudio.Settings.AutoRestoreLastPosition;
|
||||
FollowCursorCheckbox.Checked = Tastudio.Settings.FollowCursor;
|
||||
// FIXME
|
||||
//AutoRestoreCheckbox.Checked = Tastudio.Settings.AutoRestoreLastPosition;
|
||||
//FollowCursorCheckbox.Checked = Tastudio.Settings.FollowCursor;
|
||||
}
|
||||
|
||||
_programmaticallyChangingValue = false;
|
||||
|
|
|
@ -131,6 +131,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
this.StartFromNowSeparator = new System.Windows.Forms.ToolStripSeparator();
|
||||
this.StartNewProjectFromNowMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.SavingProgressBar = new System.Windows.Forms.ToolStripProgressBar();
|
||||
this.toolStripStatusLabel2 = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.TASMenu.SuspendLayout();
|
||||
this.TasStatusStrip.SuspendLayout();
|
||||
this.MarkerContextMenu.SuspendLayout();
|
||||
|
@ -650,7 +652,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
// RotateMenuItem
|
||||
//
|
||||
this.RotateMenuItem.Name = "RotateMenuItem";
|
||||
this.RotateMenuItem.Size = new System.Drawing.Size(152, 22);
|
||||
this.RotateMenuItem.Size = new System.Drawing.Size(108, 22);
|
||||
this.RotateMenuItem.Text = "Rotate";
|
||||
this.RotateMenuItem.Click += new System.EventHandler(this.RotateMenuItem_Click);
|
||||
//
|
||||
|
@ -731,6 +733,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
this.TasStatusStrip.ClickThrough = true;
|
||||
this.TasStatusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.MessageStatusLabel,
|
||||
this.SavingProgressBar,
|
||||
this.toolStripStatusLabel2,
|
||||
this.SplicerStatusLabel});
|
||||
this.TasStatusStrip.Location = new System.Drawing.Point(0, 497);
|
||||
this.TasStatusStrip.Name = "TasStatusStrip";
|
||||
|
@ -965,6 +969,17 @@ namespace BizHawk.Client.EmuHawk
|
|||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Markers";
|
||||
//
|
||||
// SavingProgressBar
|
||||
//
|
||||
this.SavingProgressBar.Name = "SavingProgressBar";
|
||||
this.SavingProgressBar.Size = new System.Drawing.Size(100, 16);
|
||||
//
|
||||
// toolStripStatusLabel2
|
||||
//
|
||||
this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
|
||||
this.toolStripStatusLabel2.Size = new System.Drawing.Size(109, 17);
|
||||
this.toolStripStatusLabel2.Spring = true;
|
||||
//
|
||||
// TAStudio
|
||||
//
|
||||
this.AllowDrop = true;
|
||||
|
@ -1100,5 +1115,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
private System.Windows.Forms.ToolStripSeparator StartFromNowSeparator;
|
||||
private System.Windows.Forms.ToolStripMenuItem StartNewProjectFromNowMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem RotateMenuItem;
|
||||
private System.Windows.Forms.ToolStripProgressBar SavingProgressBar;
|
||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel2;
|
||||
}
|
||||
}
|
|
@ -77,8 +77,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
}
|
||||
else
|
||||
{
|
||||
CurrentTasMovie.Save();
|
||||
MessageStatusLabel.Text = Path.GetFileName(CurrentTasMovie.Filename) + " saved.";
|
||||
//CurrentTasMovie.Save();
|
||||
//MessageStatusLabel.Text = Path.GetFileName(CurrentTasMovie.Filename) + " saved.";
|
||||
_saveBackgroundWorker.RunWorkerAsync();
|
||||
Settings.RecentTas.Add(CurrentTasMovie.Filename);
|
||||
}
|
||||
}
|
||||
|
@ -95,9 +96,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
if (file != null)
|
||||
{
|
||||
CurrentTasMovie.Filename = file.FullName;
|
||||
CurrentTasMovie.Save();
|
||||
|
||||
//CurrentTasMovie.Save();
|
||||
_saveBackgroundWorker.RunWorkerAsync();
|
||||
Settings.RecentTas.Add(CurrentTasMovie.Filename);
|
||||
MessageStatusLabel.Text = Path.GetFileName(CurrentTasMovie.Filename) + " saved.";
|
||||
//MessageStatusLabel.Text = Path.GetFileName(CurrentTasMovie.Filename) + " saved.";
|
||||
SetTextProperty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private readonly List<TasClipboardEntry> _tasClipboard = new List<TasClipboardEntry>();
|
||||
|
||||
private BackgroundWorker _saveBackgroundWorker;
|
||||
|
||||
private MovieEndAction _originalEndAction; // The movie end behavior selected by the user (that is overridden by TAStudio)
|
||||
private Dictionary<string, string> GenerateColumnNames()
|
||||
{
|
||||
|
@ -65,6 +67,39 @@ namespace BizHawk.Client.EmuHawk
|
|||
InitializeComponent();
|
||||
Settings = new TAStudioSettings();
|
||||
|
||||
// TODO: show this at all times or hide it when saving is done?
|
||||
this.SavingProgressBar.Visible = false;
|
||||
|
||||
_saveBackgroundWorker = new BackgroundWorker();
|
||||
_saveBackgroundWorker.WorkerReportsProgress = true;
|
||||
_saveBackgroundWorker.DoWork += (s, e) =>
|
||||
{
|
||||
this.Invoke(() => this.MessageStatusLabel.Text = "Saving " + Path.GetFileName(CurrentTasMovie.Filename) + "...");
|
||||
this.Invoke(() => this.SavingProgressBar.Visible = true);
|
||||
CurrentTasMovie.Save();
|
||||
};
|
||||
|
||||
_saveBackgroundWorker.ProgressChanged += (s, e) =>
|
||||
{
|
||||
SavingProgressBar.Value = e.ProgressPercentage;
|
||||
};
|
||||
|
||||
_saveBackgroundWorker.RunWorkerCompleted += (s, e) =>
|
||||
{
|
||||
this.Invoke(() => this.MessageStatusLabel.Text = Path.GetFileName(CurrentTasMovie.Filename) + " saved.");
|
||||
this.Invoke(() => this.SavingProgressBar.Visible = false);
|
||||
|
||||
// SUPER HACKY, and i'm not even sure it's necessary
|
||||
Timer t = new Timer();
|
||||
t.Tick += (a, b) =>
|
||||
{
|
||||
this.Invoke(() => this.MessageStatusLabel.Text = "TAStudio engaged.");
|
||||
t.Stop();
|
||||
};
|
||||
t.Interval = 5000;
|
||||
t.Start();
|
||||
};
|
||||
|
||||
WantsToControlStopMovie = true;
|
||||
TasPlaybackBox.Tastudio = this;
|
||||
MarkerControl.Tastudio = this;
|
||||
|
@ -77,6 +112,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
TasView.MultiSelect = true;
|
||||
TasView.MaxCharactersInHorizontal = 1;
|
||||
WantsToControlRestartMovie = true;
|
||||
|
||||
}
|
||||
|
||||
private void TastudioToStopMovie()
|
||||
|
@ -120,7 +156,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void NewTasMovie()
|
||||
{
|
||||
Global.MovieSession.Movie = new TasMovie();
|
||||
Global.MovieSession.Movie = new TasMovie(false, _saveBackgroundWorker);
|
||||
SetTasMovieCallbacks();
|
||||
CurrentTasMovie.PropertyChanged += new PropertyChangedEventHandler(this.TasMovie_OnPropertyChanged);
|
||||
CurrentTasMovie.Filename = DefaultTasProjName(); // TODO don't do this, take over any mainform actions that can crash without a filename
|
||||
|
@ -194,6 +230,9 @@ namespace BizHawk.Client.EmuHawk
|
|||
text += " - " + CurrentTasMovie.Name + (CurrentTasMovie.Changes ? "*" : "");
|
||||
}
|
||||
|
||||
if (this.InvokeRequired)
|
||||
this.Invoke(() => Text = text);
|
||||
else
|
||||
Text = text;
|
||||
}
|
||||
|
||||
|
@ -201,7 +240,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
if (AskSaveChanges())
|
||||
{
|
||||
var movie = new TasMovie
|
||||
var movie = new TasMovie(false, _saveBackgroundWorker)
|
||||
{
|
||||
Filename = path,
|
||||
ClientSettingsForSave = ClientSettingsForSave,
|
||||
|
|
Loading…
Reference in New Issue