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;
|
2013-10-25 00:57:23 +00:00
|
|
|
|
|
2014-05-20 15:39:43 +00:00
|
|
|
|
using BizHawk.Common.ReflectionExtensions;
|
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;
|
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
|
|
|
|
{
|
2011-06-19 14:28:13 +00:00
|
|
|
|
public partial class RecordMovie : Form
|
|
|
|
|
{
|
2013-12-22 19:06:57 +00:00
|
|
|
|
// TODO
|
|
|
|
|
// Allow relative paths in record textbox
|
2011-06-19 14:28:13 +00:00
|
|
|
|
public RecordMovie()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2011-05-16 00:56:16 +00:00
|
|
|
|
|
2011-06-19 14:28:13 +00:00
|
|
|
|
private string MakePath()
|
|
|
|
|
{
|
|
|
|
|
if (RecordBox.Text.Length == 0)
|
2013-11-28 01:33:38 +00:00
|
|
|
|
{
|
2014-05-18 01:20:56 +00:00
|
|
|
|
return string.Empty;
|
2013-11-28 01:33:38 +00:00
|
|
|
|
}
|
2013-12-22 19:06:57 +00:00
|
|
|
|
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var path = RecordBox.Text;
|
2013-11-27 21:45:50 +00:00
|
|
|
|
if (path.LastIndexOf(Path.DirectorySeparatorChar) == -1)
|
2011-06-19 14:28:13 +00:00
|
|
|
|
{
|
2013-11-27 21:45:50 +00:00
|
|
|
|
if (path[0] != Path.DirectorySeparatorChar)
|
2013-11-28 01:33:38 +00:00
|
|
|
|
{
|
2013-11-27 21:45:50 +00:00
|
|
|
|
path = path.Insert(0, Path.DirectorySeparatorChar.ToString());
|
2013-11-28 01:33:38 +00:00
|
|
|
|
}
|
2013-12-22 19:06:57 +00:00
|
|
|
|
|
2013-12-13 05:20:50 +00:00
|
|
|
|
path = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null) + path;
|
2011-05-16 00:56:16 +00:00
|
|
|
|
|
2013-12-22 19:06:57 +00:00
|
|
|
|
if (path[path.Length - 4] != '.') // If no file extension, add movie extension
|
2013-11-28 01:33:38 +00:00
|
|
|
|
{
|
2014-06-08 19:36:33 +00:00
|
|
|
|
path += "." + Global.MovieSession.Movie.PreferredExtension;
|
2013-11-28 01:33:38 +00:00
|
|
|
|
}
|
2011-06-19 14:28:13 +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)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
if (StartFromCombo.SelectedItem.ToString() == "Now")
|
|
|
|
|
{
|
2013-12-22 19:06:57 +00:00
|
|
|
|
var fileInfo = new FileInfo(path);
|
|
|
|
|
if (!fileInfo.Exists)
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(fileInfo.DirectoryName);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-13 16:45:33 +00:00
|
|
|
|
movieToRecord.StartsFromSavestate = true;
|
2014-06-12 20:42:46 +00:00
|
|
|
|
|
2014-06-20 00:39:46 +00:00
|
|
|
|
if (Global.Emulator.BinarySaveStatesPreferred)
|
|
|
|
|
{
|
|
|
|
|
movieToRecord.BinarySavestate = (byte[])Global.Emulator.SaveStateBinary().Clone();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
using (var sw = new StringWriter())
|
|
|
|
|
{
|
|
|
|
|
Global.Emulator.SaveStateText(sw);
|
|
|
|
|
movieToRecord.TextSavestate = sw.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-29 19:55:05 +00:00
|
|
|
|
}
|
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();
|
2014-06-13 16:45:33 +00:00
|
|
|
|
GlobalWin.MainForm.StartNewMovie(movieToRecord, true);
|
2011-06-30 01:37:54 +00:00
|
|
|
|
|
|
|
|
|
Global.Config.UseDefaultAuthor = DefaultAuthorCheckBox.Checked;
|
|
|
|
|
if (DefaultAuthorCheckBox.Checked)
|
2012-10-20 13:30:32 +00:00
|
|
|
|
{
|
2011-06-30 01:37:54 +00:00
|
|
|
|
Global.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)
|
2011-06-19 14:28:13 +00:00
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var sfd = new SaveFileDialog
|
2014-06-13 16:58:05 +00:00
|
|
|
|
{
|
|
|
|
|
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null),
|
|
|
|
|
DefaultExt = "." + Global.MovieSession.Movie.PreferredExtension,
|
|
|
|
|
FileName = RecordBox.Text,
|
|
|
|
|
OverwritePrompt = false,
|
|
|
|
|
Filter = "Movie Files (*." + Global.MovieSession.Movie.PreferredExtension + ")|*." + Global.MovieSession.Movie.PreferredExtension + "|All Files|*.*"
|
|
|
|
|
};
|
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)
|
|
|
|
|
{
|
2014-05-23 16:22:24 +00:00
|
|
|
|
RecordBox.Text = PathManager.FilesystemSafeName(Global.Game);
|
2011-06-19 14:28:13 +00:00
|
|
|
|
StartFromCombo.SelectedIndex = 0;
|
2011-06-30 01:37:54 +00:00
|
|
|
|
DefaultAuthorCheckBox.Checked = Global.Config.UseDefaultAuthor;
|
|
|
|
|
if (Global.Config.UseDefaultAuthor)
|
2013-11-28 01:33:38 +00:00
|
|
|
|
{
|
2011-06-30 01:37:54 +00:00
|
|
|
|
AuthorBox.Text = Global.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)
|
|
|
|
|
{
|
2013-04-15 02:14:14 +00:00
|
|
|
|
e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None;
|
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
|
|
|
|
}
|