Remove the hacky Cheats_Restart() method and move the logic into the Restart method of ToolManager, also move over the generateDefaultCheatName to that object and make it static

This commit is contained in:
adelikat 2013-12-23 03:07:06 +00:00
parent d37796ab1c
commit 70078b24f2
3 changed files with 31 additions and 33 deletions

View File

@ -639,25 +639,7 @@ namespace BizHawk.Client.EmuHawk
SetPauseStatusbarIcon();
}
public string GenerateDefaultCheatFilename()
{
var pathEntry = Global.Config.PathEntries[Global.Game.System, "Cheats"];
if (pathEntry == null)
{
pathEntry = Global.Config.PathEntries[Global.Game.System, "Base"];
}
var path = PathManager.MakeAbsolutePath(pathEntry.Path, Global.Game.System);
var f = new FileInfo(path);
if (f.Directory != null && f.Directory.Exists == false)
{
f.Directory.Create();
}
return Path.Combine(path, PathManager.FilesystemSafeName(Global.Game) + ".cht");
}
public void TakeScreenshotToClipboard()
{
@ -1673,15 +1655,6 @@ namespace BizHawk.Client.EmuHawk
}
}
private void Cheats_Restart()
{
// If Cheat tool is loaded, restarting will restart the list too anyway
if (!GlobalWin.Tools.Has<Cheats>())
{
Global.CheatList.NewList(GenerateDefaultCheatFilename());
}
}
// Contains a mapping: profilename->exepath ; or null if the exe wasnt available
private string SNES_Prepare(string profile)
{
@ -3523,7 +3496,6 @@ namespace BizHawk.Client.EmuHawk
}
GlobalWin.Tools.Restart();
Cheats_Restart();
if (Global.Config.LoadCheatFileByGame)
{
@ -3703,7 +3675,6 @@ namespace BizHawk.Client.EmuHawk
RewireSound();
ResetRewindBuffer();
Cheats_Restart();
Text = "BizHawk" + (VersionInfo.INTERIM ? " (interim) " : String.Empty);
HandlePlatformMenus();
_stateSlots.Clear();

View File

@ -494,7 +494,7 @@ namespace BizHawk.Client.EmuHawk
private void StartNewList()
{
Global.CheatList.NewList(GlobalWin.MainForm.GenerateDefaultCheatFilename());
Global.CheatList.NewList(ToolManager.GenerateDefaultCheatFilename());
UpdateDialog();
UpdateMessageLabel();
ToggleGameGenieButton();

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using BizHawk.Client.Common;
@ -117,6 +118,12 @@ namespace BizHawk.Client.EmuHawk
public void Restart()
{
// If Cheat tool is loaded, restarting will restart the list too anyway
if (!GlobalWin.Tools.Has<Cheats>())
{
Global.CheatList.NewList(GenerateDefaultCheatFilename());
}
_tools.ForEach(x => x.Restart());
}
@ -195,7 +202,7 @@ namespace BizHawk.Client.EmuHawk
{
var tool = Activator.CreateInstance(typeof(T));
//Add to the list and extract it, so it will be strongly typed as T
// Add to the list and extract it, so it will be strongly typed as T
_tools.Add(tool as IToolForm);
return _tools.FirstOrDefault(x => x is T);
}
@ -242,7 +249,7 @@ namespace BizHawk.Client.EmuHawk
}
}
//Note: Referencing these properties creates an instance of the tool and persists it. They should be referenced by type if this is not desired
// Note: Referencing these properties creates an instance of the tool and persists it. They should be referenced by type if this is not desired
#region Tools
public RamWatch RamWatch
@ -452,5 +459,25 @@ namespace BizHawk.Client.EmuHawk
}
#endregion
public static string GenerateDefaultCheatFilename()
{
var pathEntry = Global.Config.PathEntries[Global.Game.System, "Cheats"];
if (pathEntry == null)
{
pathEntry = Global.Config.PathEntries[Global.Game.System, "Base"];
}
var path = PathManager.MakeAbsolutePath(pathEntry.Path, Global.Game.System);
var f = new FileInfo(path);
if (f.Directory != null && f.Directory.Exists == false)
{
f.Directory.Create();
}
return Path.Combine(path, PathManager.FilesystemSafeName(Global.Game) + ".cht");
}
}
}