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-11-04 01:39:19 +00:00
|
|
|
|
using BizHawk.Emulation.Common;
|
2014-09-01 18:43:41 +00:00
|
|
|
|
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
|
|
|
|
|
|
|
|
|
using BizHawk.Client.Common;
|
2014-07-27 15:22:30 +00:00
|
|
|
|
using BizHawk.Client.EmuHawk.WinFormExtensions;
|
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
|
|
|
|
{
|
2015-09-06 01:39:57 +00:00
|
|
|
|
public static FileInfo OpenFileDialog(string currentFile, string path, string fileType, string fileExt)
|
2013-12-10 02:13:50 +00:00
|
|
|
|
{
|
2015-09-06 01:39:57 +00:00
|
|
|
|
if (!Directory.Exists(path))
|
2013-12-10 02:13:50 +00:00
|
|
|
|
{
|
2015-09-06 01:39:57 +00:00
|
|
|
|
Directory.CreateDirectory(path);
|
2013-12-10 02:13:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-06 00:53:02 +00:00
|
|
|
|
var ofd = new OpenFileDialog
|
2013-10-25 00:57:23 +00:00
|
|
|
|
{
|
2015-09-06 00:53:02 +00:00
|
|
|
|
FileName = !string.IsNullOrWhiteSpace(currentFile)
|
2015-09-06 01:39:57 +00:00
|
|
|
|
? Path.GetFileName(currentFile)
|
|
|
|
|
: PathManager.FilesystemSafeName(Global.Game) + "." + fileExt,
|
|
|
|
|
InitialDirectory = path,
|
|
|
|
|
Filter = string.Format("{0} (*.{1})|*.{1}|All Files|*.*", fileType, fileExt),
|
2015-09-06 00:53:02 +00:00
|
|
|
|
RestoreDirectory = true
|
|
|
|
|
};
|
2013-10-25 00:57:23 +00:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2015-09-06 01:39:57 +00:00
|
|
|
|
public static FileInfo SaveFileDialog(string currentFile, string path, string fileType, string fileExt)
|
2013-10-25 00:57:23 +00:00
|
|
|
|
{
|
2015-09-06 01:39:57 +00:00
|
|
|
|
if (!Directory.Exists(path))
|
2013-10-25 00:57:23 +00:00
|
|
|
|
{
|
2015-09-06 01:39:57 +00:00
|
|
|
|
Directory.CreateDirectory(path);
|
2013-10-25 00:57:23 +00:00
|
|
|
|
}
|
2013-11-28 22:06:38 +00:00
|
|
|
|
|
2015-09-06 00:53:02 +00:00
|
|
|
|
var sfd = new SaveFileDialog
|
|
|
|
|
{
|
|
|
|
|
FileName = !string.IsNullOrWhiteSpace(currentFile)
|
2015-09-06 01:39:57 +00:00
|
|
|
|
? Path.GetFileName(currentFile)
|
|
|
|
|
: PathManager.FilesystemSafeName(Global.Game) + "." + fileExt,
|
|
|
|
|
InitialDirectory = path,
|
|
|
|
|
Filter = string.Format("{0} (*.{1})|*.{1}|All Files|*.*", fileType, fileExt),
|
|
|
|
|
RestoreDirectory = true,
|
2015-09-06 00:53:02 +00:00
|
|
|
|
};
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-06 01:39:57 +00:00
|
|
|
|
public static FileInfo GetWatchFileFromUser(string currentFile)
|
2014-04-13 12:22:53 +00:00
|
|
|
|
{
|
2015-09-06 01:39:57 +00:00
|
|
|
|
return OpenFileDialog(currentFile, PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPathFragment, null), "Watch Files", "wch");
|
2014-04-13 12:22:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-06 01:39:57 +00:00
|
|
|
|
public static FileInfo GetWatchSaveFileFromUser(string currentFile)
|
2014-04-13 12:22:53 +00:00
|
|
|
|
{
|
2015-09-06 01:39:57 +00:00
|
|
|
|
return SaveFileDialog(currentFile, PathManager.MakeAbsolutePath(Global.Config.PathEntries.WatchPathFragment, null), "Watch Files", "wch");
|
|
|
|
|
}
|
2013-10-25 00:57:23 +00:00
|
|
|
|
|
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
|
|
|
|
{
|
2014-09-01 18:43:41 +00:00
|
|
|
|
if (Global.Emulator.HasMemoryDomains())
|
2013-11-07 20:33:29 +00:00
|
|
|
|
{
|
2014-09-01 18:43:41 +00:00
|
|
|
|
GlobalWin.Tools.UpdateValues<RamWatch>();
|
|
|
|
|
GlobalWin.Tools.UpdateValues<RamSearch>();
|
|
|
|
|
GlobalWin.Tools.UpdateValues<HexEditor>();
|
|
|
|
|
|
|
|
|
|
if (GlobalWin.Tools.Has<Cheats>())
|
|
|
|
|
{
|
|
|
|
|
GlobalWin.Tools.Cheats.UpdateDialog();
|
|
|
|
|
}
|
2013-11-07 20:33:29 +00:00
|
|
|
|
|
2014-09-01 18:43:41 +00:00
|
|
|
|
GlobalWin.MainForm.UpdateCheatStatus();
|
|
|
|
|
}
|
2013-10-14 01:37:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-01-18 18:01:27 +00:00
|
|
|
|
public static void ViewInHexEditor(MemoryDomain domain, IEnumerable<long> addresses, Watch.WatchSize size)
|
2013-09-29 16:09:48 +00:00
|
|
|
|
{
|
2013-11-03 16:07:58 +00:00
|
|
|
|
GlobalWin.Tools.Load<HexEditor>();
|
2014-07-28 01:24:57 +00:00
|
|
|
|
GlobalWin.Tools.HexEditor.SetToAddresses(addresses, domain, size);
|
2013-09-29 16:09:48 +00:00
|
|
|
|
}
|
2013-09-07 05:17:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|