From 01c8b9149f139648ed53fe175bbc955443c2ef01 Mon Sep 17 00:00:00 2001 From: Alexey 'Cluster' Avdyukhin Date: Thu, 5 Oct 2017 07:05:16 +0300 Subject: Huge refactoring. Testing required. But need to sleep. --- GameGenieCodeAddModForm.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'GameGenieCodeAddModForm.cs') diff --git a/GameGenieCodeAddModForm.cs b/GameGenieCodeAddModForm.cs index 25e75736..99049933 100644 --- a/GameGenieCodeAddModForm.cs +++ b/GameGenieCodeAddModForm.cs @@ -1,15 +1,16 @@ using com.clusterrr.Famicom; using com.clusterrr.hakchi_gui.Properties; using System; +using System.IO; using System.Windows.Forms; namespace com.clusterrr.hakchi_gui { public partial class GameGenieCodeAddModForm : Form { - readonly NesGame FGame = null; + readonly NesMiniApplication FGame = null; - public GameGenieCodeAddModForm(NesGame game) + public GameGenieCodeAddModForm(NesMiniApplication game) { InitializeComponent(); FGame = game; @@ -47,10 +48,14 @@ namespace com.clusterrr.hakchi_gui if (FGame != null) { - NesFile lGame = new NesFile(FGame.NesPath); + var tmpPath = Path.Combine(Path.GetTempPath(), FGame.Code); try { - lGame.PRG = GameGeniePatcher.Patch(lGame.PRG, textBoxCode.Text); + FGame.CopyTo(tmpPath); + var lGame = NesMiniApplication.FromDirectory(tmpPath); + (lGame as ISupportsGameGenie).GameGenie = textBoxCode.Text; + lGame.Save(); + (lGame as ISupportsGameGenie).ApplyGameGenie(); } catch (GameGenieFormatException) { @@ -62,6 +67,11 @@ namespace com.clusterrr.hakchi_gui MessageBox.Show(this, string.Format(Resources.GameGenieNotFound, textBoxCode.Text, FGame.Name), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + finally + { + if (Directory.Exists(tmpPath)) + Directory.Delete(tmpPath, true); + } } if (string.IsNullOrEmpty(textBoxDescription.Text.Trim())) -- cgit v1.2.3