2013-09-07 05:17:29 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2013-10-25 00:57:23 +00:00
|
|
|
|
using System.IO;
|
2013-09-07 05:17:29 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2013-10-25 00:57:23 +00:00
|
|
|
|
using BizHawk.Client.Common;
|
2013-11-04 01:39:19 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
2013-10-25 00:57:23 +00:00
|
|
|
|
|
2013-11-03 03:54:37 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
2013-09-07 05:17:29 +00:00
|
|
|
|
{
|
2013-11-28 22:06:38 +00:00
|
|
|
|
public static class ToolHelpers
|
2013-09-07 05:17:29 +00:00
|
|
|
|
{
|
2013-12-10 02:13:50 +00:00
|
|
|
|
public static FileInfo GetTasProjFileFromUser(string currentFile)
|
|
|
|
|
{
|
|
|
|
|
var ofd = new OpenFileDialog();
|
2014-03-01 16:30:06 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(currentFile))
|
2013-12-10 02:13:50 +00:00
|
|
|
|
{
|
|
|
|
|
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 05:20:50 +00:00
|
|
|
|
ofd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null);
|
2013-12-10 02:13:50 +00:00
|
|
|
|
ofd.Filter = "Tas Project Files (*.tasproj)|*.tasproj|All Files|*.*";
|
|
|
|
|
ofd.RestoreDirectory = true;
|
|
|
|
|
|
|
|
|
|
var result = ofd.ShowHawkDialog();
|
|
|
|
|
if (result != DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new FileInfo(ofd.FileName);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-10 01:45:45 +00:00
|
|
|
|
public static FileInfo GetTasProjSaveFileFromUser(string currentFile)
|
|
|
|
|
{
|
|
|
|
|
var sfd = new SaveFileDialog();
|
2014-03-01 16:30:06 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(currentFile))
|
2013-12-10 01:45:45 +00:00
|
|
|
|
{
|
|
|
|
|
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
|
|
|
|
sfd.InitialDirectory = Path.GetDirectoryName(currentFile);
|
|
|
|
|
}
|
|
|
|
|
else if (!(Global.Emulator is NullEmulator))
|
|
|
|
|
{
|
|
|
|
|
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
|
2013-12-13 05:20:50 +00:00
|
|
|
|
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null);
|
2013-12-10 01:45:45 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sfd.FileName = "NULL";
|
2013-12-13 05:20:50 +00:00
|
|
|
|
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.MoviesPathFragment, null);
|
2013-12-10 01:45:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sfd.Filter = "Tas Project Files (*.tasproj)|*.tasproj|All Files|*.*";
|
|
|
|
|
sfd.RestoreDirectory = true;
|
|
|
|
|
var result = sfd.ShowHawkDialog();
|
|
|
|
|
if (result != DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new FileInfo(sfd.FileName);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-27 07:54:00 +00:00
|
|
|
|
public static FileInfo GetWatchFileFromUser(string currentFile)
|
|
|
|
|
{
|
|
|
|
|
var ofd = new OpenFileDialog();
|
2014-03-01 16:30:06 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(currentFile))
|
2013-10-27 07:54:00 +00:00
|
|
|
|
{
|
|
|
|
|
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
|
|
|
|
}
|
2013-11-28 22:06:38 +00:00
|
|
|
|
|
2013-12-13 05:20:50 +00:00
|
|
|
|
ofd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPathFragment, null);
|
2013-10-27 07:54:00 +00:00
|
|
|
|
ofd.Filter = "Watch Files (*.wch)|*.wch|All Files|*.*";
|
|
|
|
|
ofd.RestoreDirectory = true;
|
|
|
|
|
|
2013-11-28 22:39:00 +00:00
|
|
|
|
var result = ofd.ShowHawkDialog();
|
2013-10-27 07:54:00 +00:00
|
|
|
|
if (result != DialogResult.OK)
|
2013-11-28 22:06:38 +00:00
|
|
|
|
{
|
2013-10-27 07:54:00 +00:00
|
|
|
|
return null;
|
2013-11-28 22:06:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new FileInfo(ofd.FileName);
|
2013-10-27 07:54:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static FileInfo GetWatchSaveFileFromUser(string currentFile)
|
|
|
|
|
{
|
|
|
|
|
var sfd = new SaveFileDialog();
|
2014-03-01 16:30:06 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(currentFile))
|
2013-10-27 07:54:00 +00:00
|
|
|
|
{
|
|
|
|
|
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
|
|
|
|
sfd.InitialDirectory = Path.GetDirectoryName(currentFile);
|
|
|
|
|
}
|
|
|
|
|
else if (!(Global.Emulator is NullEmulator))
|
|
|
|
|
{
|
|
|
|
|
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
|
2013-12-13 05:20:50 +00:00
|
|
|
|
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPathFragment, null);
|
2013-10-27 07:54:00 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sfd.FileName = "NULL";
|
2013-12-13 05:20:50 +00:00
|
|
|
|
sfd.InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPathFragment, null);
|
2013-10-27 07:54:00 +00:00
|
|
|
|
}
|
2013-11-28 22:06:38 +00:00
|
|
|
|
|
2013-10-27 07:54:00 +00:00
|
|
|
|
sfd.Filter = "Watch Files (*.wch)|*.wch|All Files|*.*";
|
|
|
|
|
sfd.RestoreDirectory = true;
|
2013-11-28 22:39:00 +00:00
|
|
|
|
var result = sfd.ShowHawkDialog();
|
2013-10-27 07:54:00 +00:00
|
|
|
|
if (result != DialogResult.OK)
|
2013-11-28 22:06:38 +00:00
|
|
|
|
{
|
2013-10-27 07:54:00 +00:00
|
|
|
|
return null;
|
2013-11-28 22:06:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new FileInfo(sfd.FileName);
|
2013-10-27 07:54:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-25 00:57:23 +00:00
|
|
|
|
public static FileInfo GetCheatFileFromUser(string currentFile)
|
|
|
|
|
{
|
|
|
|
|
var ofd = new OpenFileDialog();
|
2014-03-01 16:30:06 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(currentFile))
|
2013-10-25 00:57:23 +00:00
|
|
|
|
{
|
|
|
|
|
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
|
|
|
|
}
|
2013-11-28 22:06:38 +00:00
|
|
|
|
|
2013-10-25 00:57:23 +00:00
|
|
|
|
ofd.InitialDirectory = PathManager.GetCheatsPath(Global.Game);
|
|
|
|
|
ofd.Filter = "Cheat Files (*.cht)|*.cht|All Files|*.*";
|
|
|
|
|
ofd.RestoreDirectory = true;
|
|
|
|
|
|
2013-11-28 22:39:00 +00:00
|
|
|
|
var result = ofd.ShowHawkDialog();
|
2013-10-25 00:57:23 +00:00
|
|
|
|
if (result != DialogResult.OK)
|
2013-11-28 22:06:38 +00:00
|
|
|
|
{
|
2013-10-25 00:57:23 +00:00
|
|
|
|
return null;
|
2013-11-28 22:06:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new FileInfo(ofd.FileName);
|
2013-10-25 00:57:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static FileInfo GetCheatSaveFileFromUser(string currentFile)
|
|
|
|
|
{
|
|
|
|
|
var sfd = new SaveFileDialog();
|
2014-03-01 16:30:06 +00:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(currentFile))
|
2013-10-25 00:57:23 +00:00
|
|
|
|
{
|
|
|
|
|
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
|
|
|
|
}
|
|
|
|
|
else if (!(Global.Emulator is NullEmulator))
|
|
|
|
|
{
|
|
|
|
|
sfd.FileName = PathManager.FilesystemSafeName(Global.Game);
|
|
|
|
|
}
|
2013-11-28 22:06:38 +00:00
|
|
|
|
|
2013-10-25 00:57:23 +00:00
|
|
|
|
sfd.InitialDirectory = PathManager.GetCheatsPath(Global.Game);
|
|
|
|
|
sfd.Filter = "Cheat Files (*.cht)|*.cht|All Files|*.*";
|
|
|
|
|
sfd.RestoreDirectory = true;
|
2013-11-28 22:39:00 +00:00
|
|
|
|
var result = sfd.ShowHawkDialog();
|
2013-10-25 00:57:23 +00:00
|
|
|
|
if (result != DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-13 12:22:53 +00:00
|
|
|
|
return new FileInfo(sfd.FileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static FileInfo GetCdlFileFromUser(string currentFile)
|
|
|
|
|
{
|
|
|
|
|
var ofd = new OpenFileDialog
|
|
|
|
|
{
|
|
|
|
|
Filter = "Code Data Logger Files (*.cdl)|*.cdl|All Files|*.*",
|
|
|
|
|
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.LogPathFragment, null),
|
|
|
|
|
RestoreDirectory = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(currentFile))
|
|
|
|
|
{
|
|
|
|
|
ofd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = ofd.ShowHawkDialog();
|
|
|
|
|
if (result != DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new FileInfo(ofd.FileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static FileInfo GetCdlSaveFileFromUser(string currentFile)
|
|
|
|
|
{
|
|
|
|
|
var sfd = new SaveFileDialog
|
|
|
|
|
{
|
|
|
|
|
Filter = "Code Data Logger Files (*.cdl)|*.cdl|All Files|*.*",
|
|
|
|
|
InitialDirectory = PathManager.MakeAbsolutePath(Global.Config.PathEntries.LogPathFragment, null),
|
|
|
|
|
RestoreDirectory = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(currentFile))
|
|
|
|
|
{
|
|
|
|
|
sfd.FileName = Path.GetFileNameWithoutExtension(currentFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = sfd.ShowHawkDialog();
|
|
|
|
|
if (result != DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new FileInfo(sfd.FileName);
|
2013-10-25 00:57:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-10-17 00:21:45 +00:00
|
|
|
|
public static ToolStripMenuItem GenerateAutoLoadItem(RecentFiles recent)
|
|
|
|
|
{
|
2013-11-07 16:11:21 +00:00
|
|
|
|
var auto = new ToolStripMenuItem { Text = "&Autoload", Checked = recent.AutoLoad };
|
2013-10-17 00:21:45 +00:00
|
|
|
|
auto.Click += (o, ev) => recent.ToggleAutoLoad();
|
|
|
|
|
return auto;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ToolStripItem[] GenerateRecentMenu(RecentFiles recent, Action<string> loadFileCallback)
|
|
|
|
|
{
|
|
|
|
|
var items = new List<ToolStripItem>();
|
|
|
|
|
|
|
|
|
|
if (recent.Empty)
|
|
|
|
|
{
|
|
|
|
|
var none = new ToolStripMenuItem { Enabled = false, Text = "None" };
|
|
|
|
|
items.Add(none);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-11-25 02:08:45 +00:00
|
|
|
|
foreach (var filename in recent)
|
2013-10-17 00:21:45 +00:00
|
|
|
|
{
|
2013-11-25 02:08:45 +00:00
|
|
|
|
var temp = filename;
|
2013-10-17 00:21:45 +00:00
|
|
|
|
var item = new ToolStripMenuItem { Text = temp };
|
|
|
|
|
item.Click += (o, ev) => loadFileCallback(temp);
|
|
|
|
|
items.Add(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
items.Add(new ToolStripSeparator());
|
|
|
|
|
|
|
|
|
|
var clearitem = new ToolStripMenuItem { Text = "&Clear" };
|
|
|
|
|
clearitem.Click += (o, ev) => recent.Clear();
|
|
|
|
|
items.Add(clearitem);
|
|
|
|
|
|
|
|
|
|
return items.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void HandleLoadError(RecentFiles recent, string path)
|
|
|
|
|
{
|
2013-11-03 16:07:58 +00:00
|
|
|
|
GlobalWin.Sound.StopSound();
|
2013-11-25 02:08:45 +00:00
|
|
|
|
var result = MessageBox.Show("Could not open " + path + "\nRemove from list?", "File not found", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
|
2013-10-17 00:21:45 +00:00
|
|
|
|
if (result == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
recent.Remove(path);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 16:07:58 +00:00
|
|
|
|
GlobalWin.Sound.StartSound();
|
2013-10-17 00:21:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-28 22:06:38 +00:00
|
|
|
|
public static IEnumerable<ToolStripItem> GenerateMemoryDomainMenuItems(Action<string> setCallback, string selectedDomain = "", int? maxSize = null)
|
2013-09-07 05:17:29 +00:00
|
|
|
|
{
|
|
|
|
|
var items = new List<ToolStripMenuItem>();
|
|
|
|
|
|
2013-11-20 01:17:01 +00:00
|
|
|
|
foreach (var domain in Global.Emulator.MemoryDomains)
|
2013-09-07 05:17:29 +00:00
|
|
|
|
{
|
2013-11-25 02:08:45 +00:00
|
|
|
|
var name = domain.Name;
|
2013-11-20 01:17:01 +00:00
|
|
|
|
var item = new ToolStripMenuItem { Text = name };
|
|
|
|
|
item.Click += (o, ev) => setCallback(name);
|
|
|
|
|
item.Checked = name == selectedDomain;
|
|
|
|
|
item.Enabled = !(maxSize.HasValue && domain.Size > maxSize.Value);
|
|
|
|
|
items.Add(item);
|
2013-09-07 05:17:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-20 01:17:01 +00:00
|
|
|
|
return items;
|
2013-09-07 05:17:29 +00:00
|
|
|
|
}
|
2013-09-08 04:13:31 +00:00
|
|
|
|
|
2013-10-05 15:45:39 +00:00
|
|
|
|
public static void PopulateMemoryDomainDropdown(ref ComboBox dropdown, MemoryDomain startDomain)
|
|
|
|
|
{
|
|
|
|
|
dropdown.Items.Clear();
|
2013-10-20 18:02:43 +00:00
|
|
|
|
if (Global.Emulator.MemoryDomains.Count > 0)
|
2013-10-05 15:45:39 +00:00
|
|
|
|
{
|
2013-10-20 18:02:43 +00:00
|
|
|
|
foreach (var domain in Global.Emulator.MemoryDomains)
|
2013-10-05 15:45:39 +00:00
|
|
|
|
{
|
|
|
|
|
var result = dropdown.Items.Add(domain.ToString());
|
|
|
|
|
if (domain.Name == startDomain.Name)
|
|
|
|
|
{
|
|
|
|
|
dropdown.SelectedIndex = result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-16 16:30:20 +00:00
|
|
|
|
public static void UpdateCheatRelatedTools(object sender, CheatCollection.CheatListEventArgs e)
|
2013-09-23 16:01:19 +00:00
|
|
|
|
{
|
2013-11-03 16:07:58 +00:00
|
|
|
|
GlobalWin.Tools.UpdateValues<RamWatch>();
|
|
|
|
|
GlobalWin.Tools.UpdateValues<RamSearch>();
|
|
|
|
|
GlobalWin.Tools.UpdateValues<HexEditor>();
|
2013-11-07 20:33:29 +00:00
|
|
|
|
|
|
|
|
|
if (GlobalWin.Tools.Has<Cheats>())
|
|
|
|
|
{
|
|
|
|
|
GlobalWin.Tools.Cheats.UpdateDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-03 16:07:58 +00:00
|
|
|
|
GlobalWin.MainForm.UpdateCheatStatus();
|
2013-10-14 01:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-25 02:08:45 +00:00
|
|
|
|
public static void FreezeAddress(IEnumerable<Watch> watches)
|
2013-09-08 04:13:31 +00:00
|
|
|
|
{
|
2014-03-01 16:30:06 +00:00
|
|
|
|
Global.CheatList.AddRange(
|
|
|
|
|
watches
|
|
|
|
|
.Where(w => !w.IsSeparator)
|
|
|
|
|
.Select(w => new Cheat(w, w.Value ?? 0)));
|
|
|
|
|
|
|
|
|
|
//foreach (var watch in watches.Where(watch => !watch.IsSeparator))
|
|
|
|
|
//{
|
|
|
|
|
// Global.CheatList.Add(new Cheat(watch, watch.Value ?? 0));
|
|
|
|
|
//}
|
2013-10-14 01:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-25 02:08:45 +00:00
|
|
|
|
public static void UnfreezeAddress(IEnumerable<Watch> watches)
|
2013-10-14 01:37:09 +00:00
|
|
|
|
{
|
2014-03-01 16:30:06 +00:00
|
|
|
|
Global.CheatList.RemoveRange(watches.Where(watch => !watch.IsSeparator));
|
2013-09-08 04:13:31 +00:00
|
|
|
|
}
|
2013-09-29 16:09:48 +00:00
|
|
|
|
|
|
|
|
|
public static void ViewInHexEditor(MemoryDomain domain, IEnumerable<int> addresses)
|
|
|
|
|
{
|
2013-11-03 16:07:58 +00:00
|
|
|
|
GlobalWin.Tools.Load<HexEditor>();
|
2013-11-28 20:02:32 +00:00
|
|
|
|
GlobalWin.Tools.HexEditor.SetToAddresses(addresses, domain);
|
2013-09-29 16:09:48 +00:00
|
|
|
|
}
|
2013-10-03 23:58:56 +00:00
|
|
|
|
|
2013-10-04 16:06:08 +00:00
|
|
|
|
public static void AddColumn(ListView listView, string columnName, bool enabled, int columnWidth)
|
|
|
|
|
{
|
|
|
|
|
if (enabled)
|
|
|
|
|
{
|
|
|
|
|
if (listView.Columns[columnName] == null)
|
|
|
|
|
{
|
2013-11-25 02:08:45 +00:00
|
|
|
|
var column = new ColumnHeader
|
2013-10-04 16:06:08 +00:00
|
|
|
|
{
|
|
|
|
|
Name = columnName,
|
2014-03-01 16:30:06 +00:00
|
|
|
|
Text = columnName.Replace("Column", string.Empty),
|
2013-10-04 16:06:08 +00:00
|
|
|
|
Width = columnWidth,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
listView.Columns.Add(column);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-07 05:17:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|