private void buttonOk_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxCode.Text.Trim())) { MessageBox.Show(this, Resources.GGCodeEmpty, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (FGame != null) { NesFile lGame = new NesFile(FGame.NesPath); try { lGame.PRG = GameGenie.Patch(lGame.PRG, textBoxCode.Text); } catch (GameGenieFormatException) { MessageBox.Show(this, string.Format(Resources.GameGenieFormatError, textBoxCode.Text, FGame.Name), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } catch (GameGenieNotFoundException) { MessageBox.Show(this, string.Format(Resources.GameGenieNotFound, textBoxCode.Text, FGame.Name), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (string.IsNullOrEmpty(textBoxDescription.Text.Trim())) { MessageBox.Show(this, Resources.GGDescriptionEmpty, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } textBoxCode.Text = textBoxCode.Text.ToUpper().Trim(); DialogResult = System.Windows.Forms.DialogResult.OK; }
public void ImportCodes(string AFileName, bool AQuiet = false) { if (File.Exists(AFileName)) { XmlDocument lXml = new XmlDocument(); XmlNodeList lCodes = null; XmlNode lCodeNode = null; XmlAttribute lAttribute = null; lXml.Load(AFileName); lCodes = lXml.SelectNodes("//genie/.."); FModified = true; XmlNode lDeleteNode = GameNode.FirstChild; while (lDeleteNode != null) { GameNode.RemoveChild(GameNode.FirstChild); lDeleteNode = GameNode.FirstChild; } GameCodes.Clear(); string lGameFileName = Path.Combine(Path.Combine(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "games"), FGame.Code), FGame.Code + ".nes"); foreach (XmlNode lCurCode in lCodes) { NesFile lGame = new NesFile(lGameFileName); try { lGame.PRG = GameGenie.Patch(lGame.PRG, lCurCode["genie"].InnerText); lCodeNode = FXml.CreateElement("gamegenie"); GameNode.AppendChild(lCodeNode); lAttribute = FXml.CreateAttribute("code"); lAttribute.Value = lCurCode["genie"].InnerText.ToUpper().Trim(); lCodeNode.Attributes.Append(lAttribute); lAttribute = FXml.CreateAttribute("description"); lAttribute.Value = lCurCode["description"].InnerText; lCodeNode.Attributes.Append(lAttribute); GameCodes.Add(new GameGenieCode(lCurCode["genie"].InnerText.ToUpper().Trim(), lCurCode["description"].InnerText)); } catch (GameGenieFormatException) { if (!AQuiet) { MessageBox.Show(string.Format(Resources.GameGenieFormatError, lCurCode["genie"].InnerText, FGame.Name), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (GameGenieNotFoundException) { if (!AQuiet) { MessageBox.Show(string.Format(Resources.GameGenieNotFound, lCurCode["genie"].InnerText, FGame.Name), Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
private void AddMenu(NesMenuCollection menuCollection, List <NesMenuCollection> allMenus = null) { if (allMenus == null) { allMenus = new List <NesMenuCollection>(); } if (!allMenus.Contains(menuCollection)) { allMenus.Add(menuCollection); } int menuIndex = allMenus.IndexOf(menuCollection); string targetDirectory; if (menuIndex == 0) { targetDirectory = gamesDirectory; } else { targetDirectory = Path.Combine(gamesDirectory, string.Format("sub{0:D3}", menuIndex)); } if (Directory.Exists(targetDirectory)) { return; } foreach (var element in menuCollection) { if (element is NesGame) { var game = element as NesGame; var gameDir = Path.Combine(targetDirectory, game.Code); Debug.WriteLine(string.Format("Processing {0}/{1}", game.Code, game.Name)); DirectoryCopy(game.GamePath, gameDir, true); if (!string.IsNullOrEmpty(game.GameGenie)) { var codes = game.GameGenie.Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries); var newNesFilePath = Path.Combine(gameDir, game.Code + ".nes"); try { var nesFile = new NesFile(newNesFilePath); foreach (var code in codes) { try { nesFile.PRG = GameGenie.Patch(nesFile.PRG, code.Trim()); } catch (GameGenieFormatException) { ShowError(new GameGenieFormatException(string.Format(Resources.GameGenieFormatError, code, game)), dontStop: true); } catch (GameGenieNotFoundException) { ShowError(new GameGenieNotFoundException(string.Format(Resources.GameGenieNotFound, code, game.Name)), dontStop: true); } } nesFile.Save(newNesFilePath); var ggFilePath = Path.Combine(gameDir, NesGame.GameGenieFileName); if (File.Exists(ggFilePath)) { File.Delete(ggFilePath); } } catch // in case of FDS game... just ignore { } } } if (element is NesMenuFolder) { var folder = element as NesMenuFolder; if (!allMenus.Contains(folder.Child)) { allMenus.Add(folder.Child); } int childIndex = allMenus.IndexOf(folder.Child); var folderDir = Path.Combine(targetDirectory, folder.Code); folder.Save(folderDir, childIndex); AddMenu(folder.Child, allMenus); } if (element is NesDefaultGame) { var game = element as NesDefaultGame; var gfilePath = Path.Combine(gamesDirectory, string.Format("gpath-{0}-{1}", game.Code, menuIndex)); Directory.CreateDirectory(Path.GetDirectoryName(gfilePath)); File.WriteAllText(gfilePath, menuIndex == 0 ? "." : string.Format("sub{0:D3}", menuIndex)); } } }