2011-02-11 02:30:45 +00:00
|
|
|
|
using System;
|
2011-05-16 00:56:16 +00:00
|
|
|
|
using System.IO;
|
2014-05-18 01:20:56 +00:00
|
|
|
|
using System.Linq;
|
2013-12-22 19:06:57 +00:00
|
|
|
|
using System.Windows.Forms;
|
2013-10-25 00:57:23 +00:00
|
|
|
|
|
2013-12-22 19:06:57 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
2013-11-04 01:39:19 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
2013-11-13 03:32:25 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.ColecoVision;
|
2013-12-22 19:06:57 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
|
|
|
|
|
using BizHawk.Emulation.Cores.Nintendo.N64;
|
2013-11-14 13:15:41 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.Nintendo.NES;
|
2013-11-13 23:36:21 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.Nintendo.SNES;
|
2013-12-22 19:06:57 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.Sega.MasterSystem;
|
2014-02-21 00:30:52 +00:00
|
|
|
|
using BizHawk.Emulation.Cores.Consoles.Sega.gpgx;
|
2012-09-16 15:38:33 +00:00
|
|
|
|
|
2014-04-22 00:38:59 +00:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
2014-05-18 15:07:50 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
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
|
|
|
|
{
|
2012-03-31 00:38:39 +00:00
|
|
|
|
path += "." + Global.Config.MovieExtension;
|
2013-11-28 01:33:38 +00:00
|
|
|
|
}
|
2013-12-22 19:06:57 +00:00
|
|
|
|
|
2011-06-19 14:28:13 +00:00
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
else
|
2013-11-28 01:33:38 +00:00
|
|
|
|
{
|
2011-06-19 14:28:13 +00:00
|
|
|
|
return path;
|
2013-11-28 01:33:38 +00:00
|
|
|
|
}
|
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();
|
|
|
|
|
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
|
|
|
|
|
2013-11-29 19:55:05 +00:00
|
|
|
|
Movie _movieToRecord;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-29 19:55:05 +00:00
|
|
|
|
_movieToRecord = new Movie(path, startsFromSavestate: true);
|
2014-04-25 02:19:46 +00:00
|
|
|
|
//TODO - some emulators (c++ cores) are just returning a hex string already
|
|
|
|
|
//theres no sense hexifying those again. we need to record that fact in the IEmulator somehow
|
|
|
|
|
var bytestate = Global.Emulator.SaveStateBinary();
|
|
|
|
|
string stringstate = Convert.ToBase64String(bytestate);
|
|
|
|
|
_movieToRecord.Header.SavestateBinaryBase64Blob = stringstate;
|
2013-11-29 19:55:05 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_movieToRecord = new Movie(path);
|
|
|
|
|
}
|
2011-05-16 00:56:16 +00:00
|
|
|
|
|
2013-12-22 19:06:57 +00:00
|
|
|
|
// Header
|
2014-05-18 15:07:50 +00:00
|
|
|
|
|
2013-11-30 02:20:34 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.AUTHOR] = AuthorBox.Text;
|
|
|
|
|
_movieToRecord.Header[HeaderKeys.EMULATIONVERSION] = VersionInfo.GetEmuVersion();
|
2013-12-10 01:45:45 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.MOVIEVERSION] = HeaderKeys.MovieVersion1;
|
2013-11-30 02:20:34 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.PLATFORM] = Global.Game.System;
|
2014-05-18 15:07:50 +00:00
|
|
|
|
|
|
|
|
|
// Sync Settings, for movies 1.0, just dump a json blob into a header line
|
2014-05-18 17:15:51 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.SYNCSETTINGS] = ConfigService.SaveWithType(Global.Emulator.GetSyncSettings());
|
2014-05-18 15:07:50 +00:00
|
|
|
|
|
2011-06-19 14:28:13 +00:00
|
|
|
|
if (Global.Game != null)
|
2012-04-15 03:02:07 +00:00
|
|
|
|
{
|
2013-11-30 02:20:34 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.GAMENAME] = PathManager.FilesystemSafeName(Global.Game);
|
|
|
|
|
_movieToRecord.Header[HeaderKeys.SHA1] = Global.Game.Hash;
|
2012-10-05 21:04:46 +00:00
|
|
|
|
if (Global.Game.FirmwareHash != null)
|
2013-11-28 01:33:38 +00:00
|
|
|
|
{
|
2013-11-30 02:20:34 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.FIRMWARESHA1] = Global.Game.FirmwareHash;
|
2013-11-28 01:33:38 +00:00
|
|
|
|
}
|
2012-04-15 03:02:07 +00:00
|
|
|
|
}
|
2011-06-19 14:28:13 +00:00
|
|
|
|
else
|
2012-09-16 15:38:33 +00:00
|
|
|
|
{
|
2013-11-30 02:20:34 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.GAMENAME] = "NULL";
|
2012-09-16 15:38:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-20 18:02:43 +00:00
|
|
|
|
if (Global.Emulator.BoardName != null)
|
2013-08-24 20:11:41 +00:00
|
|
|
|
{
|
2013-11-30 02:20:34 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.BOARDNAME] = Global.Emulator.BoardName;
|
2013-08-24 20:11:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-20 18:02:43 +00:00
|
|
|
|
if (Global.Emulator is LibsnesCore)
|
2012-10-05 18:20:27 +00:00
|
|
|
|
{
|
2013-12-22 19:06:57 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.SGB] = (Global.Emulator as LibsnesCore).IsSGB.ToString();
|
2013-10-20 18:02:43 +00:00
|
|
|
|
if ((Global.Emulator as LibsnesCore).DisplayType == DisplayType.PAL)
|
2012-10-06 17:22:32 +00:00
|
|
|
|
{
|
2013-11-30 02:20:34 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.PAL] = "1";
|
2012-10-06 17:22:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-20 18:02:43 +00:00
|
|
|
|
else if (Global.Emulator is SMS)
|
2012-10-06 17:22:32 +00:00
|
|
|
|
{
|
2013-10-20 18:02:43 +00:00
|
|
|
|
if ((Global.Emulator as SMS).DisplayType == DisplayType.PAL)
|
2012-10-06 17:22:32 +00:00
|
|
|
|
{
|
2013-11-30 02:20:34 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.PAL] = "1";
|
2012-10-06 17:22:32 +00:00
|
|
|
|
}
|
2012-10-05 18:20:27 +00:00
|
|
|
|
}
|
2013-10-20 18:02:43 +00:00
|
|
|
|
else if (Global.Emulator is NES)
|
2012-10-06 17:22:32 +00:00
|
|
|
|
{
|
2013-10-20 18:02:43 +00:00
|
|
|
|
if ((Global.Emulator as NES).DisplayType == DisplayType.PAL)
|
2012-10-06 17:22:32 +00:00
|
|
|
|
{
|
2013-11-30 02:20:34 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.PAL] = "1";
|
2012-10-06 17:22:32 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-20 18:02:43 +00:00
|
|
|
|
else if (Global.Emulator is N64)
|
2013-05-23 01:11:30 +00:00
|
|
|
|
{
|
2013-11-16 21:29:42 +00:00
|
|
|
|
if ((Global.Emulator as N64).DisplayType == DisplayType.PAL)
|
|
|
|
|
{
|
2013-11-30 02:20:34 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.PAL] = "1";
|
2014-02-21 00:30:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (Global.Emulator is GPGX)
|
|
|
|
|
{
|
|
|
|
|
if ((Global.Emulator as GPGX).DisplayType == DisplayType.PAL)
|
|
|
|
|
{
|
|
|
|
|
_movieToRecord.Header[HeaderKeys.PAL] = "1";
|
2013-11-16 21:29:42 +00:00
|
|
|
|
}
|
2013-05-23 01:11:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-22 00:38:59 +00:00
|
|
|
|
_movieToRecord.Header[HeaderKeys.CORE] = ((CoreAttributes)Attribute
|
|
|
|
|
.GetCustomAttribute(Global.Emulator.GetType(), typeof(CoreAttributes)))
|
|
|
|
|
.CoreName;
|
|
|
|
|
|
2013-11-28 01:33:38 +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 filename = String.Empty;
|
|
|
|
|
var sfd = new SaveFileDialog
|
2013-04-15 02:14:14 +00:00
|
|
|
|
{
|
2013-12-13 05:20:50 +00:00
|
|
|
|
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null),
|
2013-04-15 02:14:14 +00:00
|
|
|
|
DefaultExt = "." + Global.Config.MovieExtension,
|
|
|
|
|
FileName = RecordBox.Text,
|
|
|
|
|
OverwritePrompt = false
|
|
|
|
|
};
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var filter = "Movie Files (*." + Global.Config.MovieExtension + ")|*." + Global.Config.MovieExtension + "|Savestates|*.state|All Files|*.*";
|
2012-11-17 22:16:23 +00:00
|
|
|
|
sfd.Filter = filter;
|
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
|
2013-11-28 01:33:38 +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)
|
|
|
|
|
{
|
2013-11-28 01:33:38 +00:00
|
|
|
|
var name = PathManager.FilesystemSafeName(Global.Game);
|
2014-05-18 01:20:56 +00:00
|
|
|
|
if (string.IsNullOrEmpty(name))
|
|
|
|
|
{
|
|
|
|
|
name = Path.GetFileNameWithoutExtension(GlobalWin.MainForm.CurrentlyOpenRom.Split('|').Last());
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-22 03:55:51 +00:00
|
|
|
|
RecordBox.Text = name;
|
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
|
|
|
|
}
|