Ejemplo n.º 1
0
        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(Program.BaseDirectoryExternal, "games"), FGame.Code), FGame.Code + ".nes");
                foreach (XmlNode lCurCode in lCodes)
                {
                    NesFile lGame = new NesFile(lGameFileName);
                    try
                    {
                        lGame.PRG = GameGeniePatcherNes.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)
                        {
                            Tasks.MessageForm.Show(Resources.Error, string.Format(Resources.GameGenieFormatError, lCurCode["genie"].InnerText, FGame.Name), Resources.sign_error);
                        }
                    }
                    catch (GameGenieNotFoundException)
                    {
                        if (!AQuiet)
                        {
                            Tasks.MessageForm.Show(Resources.Error, string.Format(Resources.GameGenieNotFound, lCurCode["genie"].InnerText, FGame.Name), Resources.sign_error);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void ApplyGameGenie()
        {
            if (!string.IsNullOrEmpty(GameGenie))
            {
                bool wasCompressed = DecompressPossible().Length > 0;
                if (wasCompressed)
                {
                    Decompress();
                }

                var codes    = GameGenie.Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
                var nesFiles = Directory.GetFiles(this.basePath, "*.nes", SearchOption.TopDirectoryOnly);
                foreach (var f in nesFiles)
                {
                    var nesFile = new NesFile(f);
                    foreach (var code in codes)
                    {
                        nesFile.PRG = GameGeniePatcherNes.Patch(nesFile.PRG, code.Trim());
                    }
                    nesFile.Save(f);
                }

                if (wasCompressed)
                {
                    Compress();
                }
            }
        }
Ejemplo n.º 3
0
 public void ApplyGameGenie()
 {
     if (!string.IsNullOrEmpty(GameGenie))
     {
         var codes    = GameGenie.Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
         var nesFiles = Directory.GetFiles(this.GamePath, "*.nes", SearchOption.TopDirectoryOnly);
         foreach (var f in nesFiles)
         {
             var nesFile = new NesFile(f);
             foreach (var code in codes)
             {
                 nesFile.PRG = GameGeniePatcherNes.Patch(nesFile.PRG, code.Trim());
             }
             nesFile.Save(f);
         }
     }
 }
Ejemplo n.º 4
0
 public bool ApplyGameGenie(out byte[] gameFileData)
 {
     gameFileData = null;
     if (!string.IsNullOrEmpty(GameGenie))
     {
         var    codes        = GameGenie.Split(new char[] { ',', '\t', ' ', ';' }, StringSplitOptions.RemoveEmptyEntries);
         string gameFilePath = GameFilePath;
         if (gameFilePath != null)
         {
             byte[] data = GameFileData;
             if (data != null)
             {
                 var nesFile = new NesFile(data);
                 foreach (var code in codes)
                 {
                     nesFile.PRG = GameGeniePatcherNes.Patch(nesFile.PRG, code.Trim());
                 }
                 gameFileData = nesFile.GetRaw();
                 return(true);
             }
         }
     }
     return(false);
 }