Skip to content

Commit 7fdc3f9

Browse files
committed
Propagate success through to caller for movie load/restart
1 parent 0076c88 commit 7fdc3f9

8 files changed

+53
-66
lines changed

src/BizHawk.Client.EmuHawk/IControlMainform.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ public interface IControlMainform
5555

5656
bool WantsToControlRestartMovie { get; }
5757

58-
void RestartMovie();
58+
bool RestartMovie();
5959
}
6060
}

src/BizHawk.Client.EmuHawk/MainForm.Events.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,7 @@ private void StopMovieMenuItem_Click(object sender, EventArgs e)
484484
}
485485

486486
private void PlayFromBeginningMenuItem_Click(object sender, EventArgs e)
487-
{
488-
RestartMovie();
489-
}
487+
=> _ = RestartMovie();
490488

491489
private void ImportMovieMenuItem_Click(object sender, EventArgs e)
492490
{

src/BizHawk.Client.EmuHawk/MainForm.FileLoader.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,16 @@ private void LoadLuaSession(string filename, string archive = null)
8787
}
8888
}
8989

90-
private void LoadMovie(string filename, string archive = null)
90+
private bool LoadMovie(string filename, string archive = null)
9191
{
9292
if (Emulator.IsNull())
9393
{
9494
OpenRom();
95-
if (Emulator.IsNull())
96-
{
97-
return;
98-
}
99-
}
100-
101-
if (Tools.IsLoaded<TAStudio>())
102-
{
103-
Tools.TAStudio.LoadMovieFile(filename);
104-
}
105-
else
106-
{
107-
StartNewMovie(MovieSession.Get(filename), false);
95+
if (Emulator.IsNull()) return false;
10896
}
97+
return Tools.IsLoaded<TAStudio>()
98+
? Tools.TAStudio.LoadMovieFile(filename)
99+
: StartNewMovie(MovieSession.Get(filename), false);
109100
}
110101

111102
private void LoadRom(string filename, string archive = null)
@@ -299,10 +290,8 @@ private void FormDragDrop_internal()
299290
if (sortedFiles[LoadOrdering.MovieFile].Count + sortedFiles[LoadOrdering.LegacyMovieFile].Count > 1)
300291
break;
301292

302-
if (value == LoadOrdering.MovieFile)
303-
LoadMovie(filename, fileInformation.ArchiveName);
304-
else
305-
LoadLegacyMovie(filename, fileInformation.ArchiveName);
293+
if (value == LoadOrdering.MovieFile) _ = LoadMovie(filename, fileInformation.ArchiveName);
294+
else LoadLegacyMovie(filename, fileInformation.ArchiveName);
306295
break;
307296
}
308297
break;

src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void ToggleGambatteSyncSetting(
278278
StopMovie();
279279
break;
280280
case "Play from beginning":
281-
RestartMovie();
281+
_ = RestartMovie();
282282
break;
283283
case "Save Movie":
284284
SaveMovie();

src/BizHawk.Client.EmuHawk/MainForm.Movie.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,13 @@ public void StopMovie(bool saveChanges = true)
9999
}
100100
}
101101

102-
private void RestartMovie()
102+
private bool RestartMovie()
103103
{
104-
if (IsSlave && Master.WantsToControlRestartMovie)
105-
{
106-
Master.RestartMovie();
107-
}
108-
else if (MovieSession.Movie.IsActive())
109-
{
110-
StartNewMovie(MovieSession.Movie, false);
111-
AddOnScreenMessage("Replaying movie file in read-only mode");
112-
}
104+
if (IsSlave && Master.WantsToControlRestartMovie) return Master.RestartMovie();
105+
if (!MovieSession.Movie.IsActive()) return false;
106+
var success = StartNewMovie(MovieSession.Movie, false);
107+
if (success) AddOnScreenMessage("Replaying movie file in read-only mode");
108+
return success;
113109
}
114110

115111
private void ToggleReadOnly()

src/BizHawk.Client.EmuHawk/tools/Debugger/GenericDebugger.IControlMainform.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public void CaptureRewind() { }
3232
public bool Rewind() => false;
3333

3434
public bool WantsToControlRestartMovie => false;
35-
public void RestartMovie() { }
35+
36+
public bool RestartMovie()
37+
=> false;
3638

3739
// TODO: We want to prevent movies and probably other things
3840
}

src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.IControlMainForm.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,14 @@ public bool Rewind()
120120

121121
public bool WantsToControlRestartMovie { get; }
122122

123-
public void RestartMovie()
123+
public bool RestartMovie()
124124
{
125-
if (AskSaveChanges())
126-
{
127-
WantsToControlStopMovie = false;
128-
StartNewMovieWrapper(CurrentTasMovie);
129-
WantsToControlStopMovie = true;
130-
RefreshDialog();
131-
}
125+
if (!AskSaveChanges()) return false;
126+
WantsToControlStopMovie = false;
127+
var success = StartNewMovieWrapper(CurrentTasMovie);
128+
WantsToControlStopMovie = true;
129+
RefreshDialog();
130+
return success;
132131
}
133132

134133
public bool WantsToControlReboot { get; private set; } = true;

src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -95,39 +95,42 @@ private void OpenTasMenuItem_Click(object sender, EventArgs e)
9595
/// <summary>
9696
/// Load the movie with the given filename within TAStudio.
9797
/// </summary>
98-
public void LoadMovieFile(string filename, bool askToSave = true)
98+
public bool LoadMovieFile(string filename, bool askToSave = true)
9999
{
100-
if (askToSave && !AskSaveChanges())
101-
{
102-
return;
103-
}
104-
100+
if (askToSave && !AskSaveChanges()) return false;
105101
if (filename.EndsWith(MovieService.TasMovieExtension))
106102
{
107103
LoadFileWithFallback(filename);
104+
return true; //TODO should this return false if it fell back to a new project?
108105
}
109-
else if (filename.EndsWith(MovieService.StandardMovieExtension))
106+
if (filename.EndsWith(MovieService.StandardMovieExtension))
110107
{
111-
var result1 = DialogController.ShowMessageBox2("This is a regular movie, a new project must be created from it to use in TAStudio\nProceed?", "Convert movie", EMsgBoxIcon.Question, useOKCancel: true);
112-
if (result1)
108+
if (!DialogController.ShowMessageBox2(
109+
caption: "Convert movie",
110+
icon: EMsgBoxIcon.Question,
111+
text: "This is a regular movie, a new project must be created from it to use in TAStudio\nProceed?",
112+
useOKCancel: true))
113113
{
114-
_initializing = true; // Starting a new movie causes a core reboot
115-
WantsToControlReboot = false;
116-
_engaged = false;
117-
MainForm.StartNewMovie(MovieSession.Get(filename), false);
118-
ConvertCurrentMovieToTasproj();
119-
_initializing = false;
120-
StartNewMovieWrapper(CurrentTasMovie);
121-
_engaged = true;
122-
WantsToControlReboot = true;
123-
SetUpColumns();
124-
UpdateWindowTitle();
114+
return false;
125115
}
116+
_initializing = true; // Starting a new movie causes a core reboot
117+
WantsToControlReboot = false;
118+
_engaged = false;
119+
MainForm.StartNewMovie(MovieSession.Get(filename), false);
120+
ConvertCurrentMovieToTasproj();
121+
_initializing = false;
122+
var success = StartNewMovieWrapper(CurrentTasMovie);
123+
_engaged = true;
124+
WantsToControlReboot = true;
125+
SetUpColumns();
126+
UpdateWindowTitle();
127+
return success; //TODO is this correct?
126128
}
127-
else
128-
{
129-
DialogController.ShowMessageBox("This is not a BizHawk movie!", "Movie load error", EMsgBoxIcon.Error);
130-
}
129+
DialogController.ShowMessageBox(
130+
caption: "Movie load error",
131+
icon: EMsgBoxIcon.Error,
132+
text: "This is not a BizHawk movie!");
133+
return false;
131134
}
132135

133136
private void SaveTasMenuItem_Click(object sender, EventArgs e)

0 commit comments

Comments
 (0)