Cheats: Automatically use current game when adding a new cheat

This commit is contained in:
Souryo 2016-06-03 21:15:34 -04:00
parent 3630395d6e
commit 33c201984c

View file

@ -28,7 +28,11 @@ namespace Mesen.GUI.Forms.Cheats
Entity = cheat; Entity = cheat;
_gameHash = cheat.GameHash; _gameHash = cheat.GameHash;
if(string.IsNullOrWhiteSpace(cheat.GameName)) {
LoadGame(InteropEmu.GetROMPath());
}
radGameGenie.Tag = CheatType.GameGenie; radGameGenie.Tag = CheatType.GameGenie;
radProActionRocky.Tag = CheatType.ProActionRocky; radProActionRocky.Tag = CheatType.ProActionRocky;
radCustom.Tag = CheatType.Custom; radCustom.Tag = CheatType.Custom;
@ -64,15 +68,21 @@ namespace Mesen.GUI.Forms.Cheats
((CheatInfo)Entity).GameHash = _gameHash; ((CheatInfo)Entity).GameHash = _gameHash;
} }
private void LoadGame(string romPath)
{
_gameHash = MD5Helper.GetMD5Hash(romPath);
if(_gameHash != null) {
((CheatInfo)Entity).GameName = Path.GetFileNameWithoutExtension(romPath);
txtGameName.Text = ((CheatInfo)Entity).GameName;
}
}
private void btnBrowse_Click(object sender, EventArgs e) private void btnBrowse_Click(object sender, EventArgs e)
{ {
OpenFileDialog ofd = new OpenFileDialog(); OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = ResourceHelper.GetMessage("FilterRom"); ofd.Filter = ResourceHelper.GetMessage("FilterRom");
if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
_gameHash = MD5Helper.GetMD5Hash(ofd.FileName); LoadGame(ofd.FileName);
if(_gameHash != null) {
txtGameName.Text = Path.GetFileNameWithoutExtension(ofd.FileName);
}
} }
} }