2011-02-11 02:30:45 +00:00
|
|
|
|
using System;
|
2011-05-16 00:56:16 +00:00
|
|
|
|
using System.IO;
|
2013-12-22 19:06:57 +00:00
|
|
|
|
using System.Windows.Forms;
|
2014-11-30 04:02:31 +00:00
|
|
|
|
using System.Linq;
|
2013-10-25 00:57:23 +00:00
|
|
|
|
|
2013-11-04 01:39:19 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
2014-07-08 13:46:59 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
|
|
|
|
using BizHawk.Client.Common.MovieConversionExtensions;
|
2020-03-15 20:45:11 +00:00
|
|
|
|
using BizHawk.Common.PathExtensions;
|
2012-09-16 15:38:33 +00:00
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2011-02-11 02:30:45 +00:00
|
|
|
|
{
|
2019-12-17 17:24:34 +00:00
|
|
|
|
// TODO - Allow relative paths in record TextBox
|
2011-06-19 14:28:13 +00:00
|
|
|
|
public partial class RecordMovie : Form
|
|
|
|
|
{
|
2019-12-17 17:24:34 +00:00
|
|
|
|
private readonly MainForm _mainForm;
|
2019-12-22 20:18:17 +00:00
|
|
|
|
private readonly Config _config;
|
|
|
|
|
private readonly GameInfo _game;
|
2019-11-02 16:05:01 +00:00
|
|
|
|
private readonly IEmulator _emulator;
|
2019-12-22 20:18:17 +00:00
|
|
|
|
private readonly IMovieSession _movieSession;
|
|
|
|
|
|
|
|
|
|
public RecordMovie(
|
|
|
|
|
MainForm mainForm,
|
|
|
|
|
Config config,
|
|
|
|
|
GameInfo game,
|
|
|
|
|
IEmulator core,
|
|
|
|
|
IMovieSession movieSession)
|
2011-06-19 14:28:13 +00:00
|
|
|
|
{
|
2019-12-17 17:24:34 +00:00
|
|
|
|
_mainForm = mainForm;
|
2019-12-22 20:18:17 +00:00
|
|
|
|
_config = config;
|
|
|
|
|
_game = game;
|
2019-11-02 16:05:01 +00:00
|
|
|
|
_emulator = core;
|
2019-12-22 20:18:17 +00:00
|
|
|
|
_movieSession = movieSession;
|
2019-12-17 17:24:34 +00:00
|
|
|
|
InitializeComponent();
|
2016-12-04 18:51:48 +00:00
|
|
|
|
|
2019-11-02 16:05:01 +00:00
|
|
|
|
if (!_emulator.HasSavestates())
|
2014-11-30 17:37:22 +00:00
|
|
|
|
{
|
|
|
|
|
StartFromCombo.Items.Remove(
|
|
|
|
|
StartFromCombo.Items
|
|
|
|
|
.OfType<object>()
|
|
|
|
|
.First(i => i.ToString()
|
|
|
|
|
.ToLower() == "now"));
|
|
|
|
|
}
|
2015-07-26 19:41:22 +00:00
|
|
|
|
|
2019-11-02 16:05:01 +00:00
|
|
|
|
if (!_emulator.HasSaveRam())
|
2015-07-26 19:41:22 +00:00
|
|
|
|
{
|
|
|
|
|
StartFromCombo.Items.Remove(
|
|
|
|
|
StartFromCombo.Items
|
|
|
|
|
.OfType<object>()
|
|
|
|
|
.First(i => i.ToString()
|
|
|
|
|
.ToLower() == "saveram"));
|
|
|
|
|
}
|
2011-06-19 14:28:13 +00:00
|
|
|
|
}
|
2011-05-16 00:56:16 +00:00
|
|
|
|
|
2011-06-19 14:28:13 +00:00
|
|
|
|
private string MakePath()
|
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var path = RecordBox.Text;
|
2014-07-21 18:14:27 +00:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(path))
|
2011-06-19 14:28:13 +00:00
|
|
|
|
{
|
2014-07-21 18:14:27 +00:00
|
|
|
|
if (path.LastIndexOf(Path.DirectorySeparatorChar) == -1)
|
2013-11-28 01:33:38 +00:00
|
|
|
|
{
|
2014-07-21 18:14:27 +00:00
|
|
|
|
if (path[0] != Path.DirectorySeparatorChar)
|
|
|
|
|
{
|
|
|
|
|
path = path.Insert(0, Path.DirectorySeparatorChar.ToString());
|
|
|
|
|
}
|
2013-12-22 19:06:57 +00:00
|
|
|
|
|
2020-03-15 20:12:36 +00:00
|
|
|
|
path = _config.PathEntries.MovieAbsolutePath() + path;
|
2011-05-16 00:56:16 +00:00
|
|
|
|
|
2014-11-30 04:02:31 +00:00
|
|
|
|
if (!MovieService.MovieExtensions.Contains(Path.GetExtension(path)))
|
2014-07-21 18:14:27 +00:00
|
|
|
|
{
|
2014-11-30 04:02:31 +00:00
|
|
|
|
// If no valid movie extension, add movie extension
|
2019-03-18 14:06:37 +00:00
|
|
|
|
path += $".{MovieService.DefaultExtension}";
|
2014-07-21 18:14:27 +00:00
|
|
|
|
}
|
2013-11-28 01:33:38 +00:00
|
|
|
|
}
|
2011-06-19 14:28:13 +00:00
|
|
|
|
}
|
2014-11-30 04:02:31 +00:00
|
|
|
|
|
2014-06-13 16:45:33 +00:00
|
|
|
|
return path;
|
2011-06-19 14:28:13 +00:00
|
|
|
|
}
|
2011-05-18 01:49:20 +00:00
|
|
|
|
|
2013-12-22 19:06:57 +00:00
|
|
|
|
private void Ok_Click(object sender, EventArgs e)
|
2011-06-19 14:28:13 +00:00
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var path = MakePath();
|
2014-06-13 16:47:57 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(path))
|
2011-06-19 14:28:13 +00:00
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var test = new FileInfo(path);
|
2012-03-30 00:32:45 +00:00
|
|
|
|
if (test.Exists)
|
|
|
|
|
{
|
2019-03-18 14:06:37 +00:00
|
|
|
|
var result = MessageBox.Show($"{path} already exists, overwrite?", "Confirm overwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
|
2013-04-15 02:14:14 +00:00
|
|
|
|
if (result == DialogResult.Cancel)
|
2013-11-28 01:33:38 +00:00
|
|
|
|
{
|
2012-03-30 00:32:45 +00:00
|
|
|
|
return;
|
2013-11-28 01:33:38 +00:00
|
|
|
|
}
|
2012-03-30 00:32:45 +00:00
|
|
|
|
}
|
2012-10-05 21:04:46 +00:00
|
|
|
|
|
2014-06-14 00:46:41 +00:00
|
|
|
|
var movieToRecord = MovieService.Get(path);
|
2013-11-29 19:55:05 +00:00
|
|
|
|
|
2014-08-16 15:01:53 +00:00
|
|
|
|
var fileInfo = new FileInfo(path);
|
|
|
|
|
if (!fileInfo.Exists)
|
2013-11-29 19:55:05 +00:00
|
|
|
|
{
|
2014-08-16 15:01:53 +00:00
|
|
|
|
Directory.CreateDirectory(fileInfo.DirectoryName);
|
|
|
|
|
}
|
2013-12-22 19:06:57 +00:00
|
|
|
|
|
2019-11-02 16:05:01 +00:00
|
|
|
|
if (StartFromCombo.SelectedItem.ToString() == "Now" && _emulator.HasSavestates())
|
2014-08-16 15:01:53 +00:00
|
|
|
|
{
|
2019-11-02 16:05:01 +00:00
|
|
|
|
var core = _emulator.AsStatable();
|
2014-11-30 16:42:58 +00:00
|
|
|
|
|
2014-06-13 16:45:33 +00:00
|
|
|
|
movieToRecord.StartsFromSavestate = true;
|
2015-07-26 19:41:22 +00:00
|
|
|
|
movieToRecord.StartsFromSaveRam = false;
|
2014-06-12 20:42:46 +00:00
|
|
|
|
|
2020-02-15 16:22:26 +00:00
|
|
|
|
if (_config.SaveStateType == SaveStateTypeE.Binary)
|
2014-06-20 00:39:46 +00:00
|
|
|
|
{
|
2014-11-30 16:42:58 +00:00
|
|
|
|
movieToRecord.BinarySavestate = (byte[])core.SaveStateBinary().Clone();
|
2014-06-20 00:39:46 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-11-02 16:05:01 +00:00
|
|
|
|
using var sw = new StringWriter();
|
|
|
|
|
core.SaveStateText(sw);
|
|
|
|
|
movieToRecord.TextSavestate = sw.ToString();
|
2014-06-20 00:39:46 +00:00
|
|
|
|
}
|
2017-04-17 19:57:01 +00:00
|
|
|
|
|
2014-10-27 01:14:47 +00:00
|
|
|
|
// TODO: do we want to support optionally not saving this?
|
2019-11-02 16:05:01 +00:00
|
|
|
|
movieToRecord.SavestateFramebuffer = new int[0];
|
|
|
|
|
if (_emulator.HasVideoProvider())
|
2014-10-27 01:14:47 +00:00
|
|
|
|
{
|
2019-11-02 16:05:01 +00:00
|
|
|
|
movieToRecord.SavestateFramebuffer = (int[])_emulator.AsVideoProvider().GetVideoBuffer().Clone();
|
2014-10-27 01:14:47 +00:00
|
|
|
|
}
|
2013-11-29 19:55:05 +00:00
|
|
|
|
}
|
2019-11-02 16:05:01 +00:00
|
|
|
|
else if (StartFromCombo.SelectedItem.ToString() == "SaveRam" && _emulator.HasSaveRam())
|
2015-07-26 19:41:22 +00:00
|
|
|
|
{
|
2019-11-02 16:05:01 +00:00
|
|
|
|
var core = _emulator.AsSaveRam();
|
2015-07-26 19:41:22 +00:00
|
|
|
|
movieToRecord.StartsFromSavestate = false;
|
|
|
|
|
movieToRecord.StartsFromSaveRam = true;
|
|
|
|
|
movieToRecord.SaveRam = core.CloneSaveRam();
|
|
|
|
|
}
|
2011-05-16 00:56:16 +00:00
|
|
|
|
|
2014-07-08 13:46:59 +00:00
|
|
|
|
movieToRecord.PopulateWithDefaultHeaderValues(AuthorBox.Text);
|
2014-06-29 20:07:21 +00:00
|
|
|
|
movieToRecord.Save();
|
2019-12-17 17:24:34 +00:00
|
|
|
|
_mainForm.StartNewMovie(movieToRecord, true);
|
2011-06-30 01:37:54 +00:00
|
|
|
|
|
2019-12-22 20:18:17 +00:00
|
|
|
|
_config.UseDefaultAuthor = DefaultAuthorCheckBox.Checked;
|
2011-06-30 01:37:54 +00:00
|
|
|
|
if (DefaultAuthorCheckBox.Checked)
|
2012-10-20 13:30:32 +00:00
|
|
|
|
{
|
2019-12-22 20:18:17 +00:00
|
|
|
|
_config.DefaultAuthor = AuthorBox.Text;
|
2012-10-20 13:30:32 +00:00
|
|
|
|
}
|
2013-12-22 19:06:57 +00:00
|
|
|
|
|
2013-04-15 02:14:14 +00:00
|
|
|
|
Close();
|
2011-06-19 14:28:13 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2012-10-20 13:30:32 +00:00
|
|
|
|
{
|
2011-06-19 14:28:13 +00:00
|
|
|
|
MessageBox.Show("Please select a movie to record", "File selection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
2012-10-20 13:30:32 +00:00
|
|
|
|
}
|
2011-06-19 14:28:13 +00:00
|
|
|
|
}
|
2011-05-16 00:56:16 +00:00
|
|
|
|
|
2011-06-19 14:28:13 +00:00
|
|
|
|
private void Cancel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-04-15 02:14:14 +00:00
|
|
|
|
Close();
|
2011-06-19 14:28:13 +00:00
|
|
|
|
}
|
2011-05-22 02:12:36 +00:00
|
|
|
|
|
2013-12-22 19:06:57 +00:00
|
|
|
|
private void BrowseBtn_Click(object sender, EventArgs e)
|
2019-11-02 16:05:01 +00:00
|
|
|
|
{
|
2020-03-15 20:12:36 +00:00
|
|
|
|
string movieFolderPath = _config.PathEntries.MovieAbsolutePath();
|
2016-01-16 03:14:59 +00:00
|
|
|
|
|
|
|
|
|
// Create movie folder if it doesn't already exist
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!Directory.Exists(movieFolderPath))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(movieFolderPath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception movieDirException)
|
2016-01-22 03:22:26 +00:00
|
|
|
|
{
|
2019-11-02 16:05:01 +00:00
|
|
|
|
if (movieDirException is IOException
|
|
|
|
|
|| movieDirException is UnauthorizedAccessException)
|
2016-01-22 03:22:26 +00:00
|
|
|
|
{
|
|
|
|
|
//TO DO : Pass error to user?
|
|
|
|
|
}
|
|
|
|
|
else throw;
|
2016-01-16 03:14:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-02 04:29:09 +00:00
|
|
|
|
using var sfd = new SaveFileDialog
|
2014-06-13 16:58:05 +00:00
|
|
|
|
{
|
2016-01-16 03:14:59 +00:00
|
|
|
|
InitialDirectory = movieFolderPath,
|
2019-12-22 20:18:17 +00:00
|
|
|
|
DefaultExt = $".{_movieSession.Movie.PreferredExtension}",
|
2014-06-13 16:58:05 +00:00
|
|
|
|
FileName = RecordBox.Text,
|
|
|
|
|
OverwritePrompt = false,
|
2020-02-20 21:04:30 +00:00
|
|
|
|
Filter = new FilesystemFilterSet(new FilesystemFilter("Movie Files", new[] { _movieSession.Movie.PreferredExtension })).ToString()
|
2014-06-13 16:58:05 +00:00
|
|
|
|
};
|
2012-06-25 00:06:07 +00:00
|
|
|
|
|
2013-11-28 22:39:00 +00:00
|
|
|
|
var result = sfd.ShowHawkDialog();
|
2013-12-24 23:32:43 +00:00
|
|
|
|
if (result == DialogResult.OK
|
2014-06-13 16:45:33 +00:00
|
|
|
|
&& !string.IsNullOrWhiteSpace(sfd.FileName))
|
2011-06-19 14:28:13 +00:00
|
|
|
|
{
|
2014-03-23 16:53:49 +00:00
|
|
|
|
RecordBox.Text = sfd.FileName;
|
2011-06-19 14:28:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RecordMovie_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
2020-03-20 03:51:59 +00:00
|
|
|
|
RecordBox.Text = _game.FilesystemSafeName();
|
2011-06-19 14:28:13 +00:00
|
|
|
|
StartFromCombo.SelectedIndex = 0;
|
2019-12-22 20:18:17 +00:00
|
|
|
|
DefaultAuthorCheckBox.Checked = _config.UseDefaultAuthor;
|
|
|
|
|
if (_config.UseDefaultAuthor)
|
2013-11-28 01:33:38 +00:00
|
|
|
|
{
|
2019-12-22 20:18:17 +00:00
|
|
|
|
AuthorBox.Text = _config.DefaultAuthor;
|
2013-11-28 01:33:38 +00:00
|
|
|
|
}
|
2011-06-19 14:28:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RecordBox_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
2020-02-03 18:42:28 +00:00
|
|
|
|
e.Set(DragDropEffects.Copy);
|
2011-06-19 14:28:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RecordBox_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var filePaths = (string[])e.Data.GetData(DataFormats.FileDrop);
|
2011-06-19 14:28:13 +00:00
|
|
|
|
RecordBox.Text = filePaths[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-02-11 02:30:45 +00:00
|
|
|
|
}
|