Ejemplo n.º 1
0
        public void LoadGames()
        {
            var selected = Settings.Default.SelectedGames.Split(';');

            Directory.CreateDirectory(GamesDir);
            var gameDirs = Directory.GetDirectories(GamesDir);
            var games    = new List <NesGame>();

            foreach (var gameDir in gameDirs)
            {
                try
                {
                    var game = new NesGame(gameDir);
                    games.Add(game);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }
            }

            var gamesSorted = games.OrderBy(o => o.Name);

            checkedListBoxGames.Items.Clear();
            checkedListBoxGames.Items.Add(Resources.Default30games, selected.Contains("default"));
            foreach (var game in gamesSorted)
            {
                checkedListBoxGames.Items.Add(game, selected.Contains(game.Code));
            }
            RecalculateSelectedGames();
            ShowSelected();
        }
Ejemplo n.º 2
0
 private void buttonAddGames_Click(object sender, EventArgs e)
 {
     if (openFileDialogNes.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         SaveConfig();
         NesGame nesGame = null;
         foreach (var file in openFileDialogNes.FileNames)
         {
             try
             {
                 nesGame = new NesGame(GamesDir, file);
                 Settings.Default.SelectedGames += ";" + nesGame.Code;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 continue;
             }
         }
         LoadGames();
         if (openFileDialogNes.FileNames.Length == 1)
         {
             for (int i = 1; i < checkedListBoxGames.Items.Count; i++)
             {
                 if ((checkedListBoxGames.Items[i] as NesGame).Code == nesGame.Code)
                 {
                     checkedListBoxGames.SelectedIndex = i;
                     break;
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 public GameGenieCodeForm(NesGame AGame)
 {
     InitializeComponent();
     FGame = AGame;
     FGameGenieDataBase = new GameGenieDataBase(FGame);
     this.Text         += string.Format(": {0}", FGame.Name);
     LoadGameGenieCodes();
 }
Ejemplo n.º 4
0
        private void ShowSelected()
        {
            var node = treeView.SelectedNode;

            listViewContent.Clear();
            if (node != null && (node.Nodes.Count > 0 || node.Tag is NesMenuFolder)) // Folder or root
            {
                pictureBoxArt.Image        = (node.Tag is NesMenuFolder) ? (node.Tag as NesMenuFolder).Image : null;
                groupBoxArt.Enabled        = (node.Tag is NesMenuFolder);
                groupBoxSplitModes.Enabled = true;
                pictureBoxArt.Cursor       = Cursors.Hand;
                listViewContent.Enabled    = true;
                foreach (TreeNode n in node.Nodes)
                {
                    var element = (INesMenuElement)n.Tag;
                    var item    = new ListViewItem();
                    item.Text = element.Name;
                    var transparency = cuttedNodes.Contains(n) ? 1 : 0;
                    if (element is NesMenuFolder)
                    {
                        item.ImageIndex = 0 + transparency;
                    }
                    else if (element is NesGame)
                    {
                        item.ImageIndex = 2 + transparency;
                    }
                    else if (element is NesDefaultGame)
                    {
                        item.ImageIndex = 4 + transparency;
                    }
                    item.Tag = n;
                    listViewContent.Items.Add(item);
                }
            }
            else
            {
                if (node != null && node.Tag is NesGame)
                {
                    var game = node.Tag as NesGame;
                    pictureBoxArt.Image     = NesGame.LoadBitmap(game.IconPath);
                    groupBoxArt.Enabled     = true;
                    listViewContent.Enabled = false;
                }
                else //if (e.Node.Tag is NesDefaultGame)
                {
                    pictureBoxArt.Image = null;
                    groupBoxArt.Enabled = false;
                }
                listViewContent.Enabled    = false;
                groupBoxSplitModes.Enabled = false;
                pictureBoxArt.Cursor       = Cursors.Default;
            }
            ShowFolderStats();
        }
Ejemplo n.º 5
0
 public GameGenieDataBase(NesGame AGame)
 {
     DataBasePath = Path.Combine(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "data"), "GameGenieDB.xml");
     FGame        = AGame;
     FDBName      = DataBasePath;
     if (File.Exists(FDBName))
     {
         FXml.Load(FDBName);
     }
     else
     {
         FXml.AppendChild(FXml.CreateElement("database"));
     }
 }
Ejemplo n.º 6
0
 private void buttonAddGames_Click(object sender, EventArgs e)
 {
     if (openFileDialogNes.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         SaveConfig();
         NesGame nesGame = null;
         foreach (var file in openFileDialogNes.FileNames)
         {
             try
             {
                 try
                 {
                     nesGame = new NesGame(GamesDir, file);
                 }
                 catch (UnsupportedMapperException ex)
                 {
                     if (MessageBox.Show(this, string.Format(Resources.MapperNotSupported, Path.GetFileName(file), ex.ROM.Mapper), Resources.AreYouSure, MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
                         == System.Windows.Forms.DialogResult.Yes)
                     {
                         nesGame = new NesGame(GamesDir, file, true);
                     }
                     else
                     {
                         continue;
                     }
                 }
                 Settings.Default.SelectedGames += ";" + nesGame.Code;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(this, ex.Message, Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                 continue;
             }
         }
         LoadGames();
         if (openFileDialogNes.FileNames.Length == 1)
         {
             for (int i = 1; i < checkedListBoxGames.Items.Count; i++)
             {
                 if ((checkedListBoxGames.Items[i] as NesGame).Code == nesGame.Code)
                 {
                     checkedListBoxGames.SelectedIndex = i;
                     break;
                 }
             }
         }
     }
 }
Ejemplo n.º 7
0
        public static NesMiniApplication ImportNes(string nesFileName, bool?ignoreMapper, ref bool?needPatch, NeedPatchDelegate needPatchCallback = null, Form parentForm = null, byte[] rawRomData = null)
        {
            NesFile nesFile;

            try
            {
                if (rawRomData != null)
                {
                    nesFile = new NesFile(rawRomData);
                }
                else
                {
                    nesFile = new NesFile(nesFileName);
                }
            }
            catch
            {
                return(NesMiniApplication.Import(nesFileName, rawRomData));
            }
            nesFile.CorrectRom();
            var crc32            = nesFile.CRC32;
            var code             = GenerateCode(crc32, Prefix);
            var gamePath         = Path.Combine(GamesDirectory, code);
            var nesPath          = Path.Combine(gamePath, code + ".nes");
            var patchesDirectory = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "patches");

            Directory.CreateDirectory(patchesDirectory);
            Directory.CreateDirectory(gamePath);
            var patches = Directory.GetFiles(patchesDirectory, string.Format("{0:X8}*.ips", crc32), SearchOption.AllDirectories);

            if (patches.Length > 0 && needPatch != false)
            {
                if (needPatch == true || ((needPatchCallback != null) && needPatchCallback(parentForm, Path.GetFileName(nesFileName))))
                {
                    needPatch = true;
                    var patch = patches[0];
                    if (rawRomData == null)
                    {
                        rawRomData = File.ReadAllBytes(nesFileName);
                    }
                    Debug.WriteLine(string.Format("Patching {0}", nesFileName));
                    IpsPatcher.Patch(patch, ref rawRomData);
                    nesFile = new NesFile(rawRomData);
                }
                else
                {
                    needPatch = false;
                }
            }

            if (nesFile.Mapper == 71)
            {
                nesFile.Mapper = 2;                       // games by Codemasters/Camerica - this is UNROM clone. One exception - Fire Hawk
            }
            if (nesFile.Mapper == 88)
            {
                nesFile.Mapper = 4;                       // Compatible with MMC3... sometimes
            }
            if (nesFile.Mapper == 95)
            {
                nesFile.Mapper = 4;                       // Compatible with MMC3
            }
            if (nesFile.Mapper == 206)
            {
                nesFile.Mapper = 4;                        // Compatible with MMC3
            }
            if (!supportedMappers.Contains(nesFile.Mapper) && (ignoreMapper != true))
            {
                Directory.Delete(gamePath, true);
                if (ignoreMapper != false)
                {
                    throw new UnsupportedMapperException(nesFile);
                }
                else
                {
                    Debug.WriteLine(string.Format("Game {0} has mapper #{1}, skipped", nesFileName, nesFile.Mapper));
                    return(null);
                }
            }
            if ((nesFile.Mirroring == NesFile.MirroringType.FourScreenVram) && (ignoreMapper != true))
            {
                Directory.Delete(gamePath, true);
                if (ignoreMapper != false)
                {
                    throw new UnsupportedFourScreenException(nesFile);
                }
                else
                {
                    Debug.WriteLine(string.Format("Game {0} has four-screen mirroring, skipped", nesFileName, nesFile.Mapper));
                    return(null);
                }
            }
            // TODO: Make trainer check. I think that the NES Mini doesn't support it.

            nesFile.Save(nesPath);
            var game = new NesGame(gamePath, true);

            game.Name = Path.GetFileNameWithoutExtension(nesFileName);
            if (game.Name.Contains("(J)"))
            {
                game.region = "Japan";
            }
            game.TryAutofill(crc32);
            game.Name = Regex.Replace(game.Name, @" ?\(.*?\)", string.Empty).Trim();
            game.Name = Regex.Replace(game.Name, @" ?\[.*?\]", string.Empty).Trim();
            game.Name = game.Name.Replace("_", " ").Replace("  ", " ");
            game.FindCover(nesFileName, (game.region == "Japan") ? Resources.blank_jp : Resources.blank_nes, crc32);
            game.Args = DefaultArgs;
            game.Save();
            return(game);
        }
Ejemplo n.º 8
0
        public static NesGame Import(string nesFileName, bool?ignoreMapper, ref bool?needPatch, NeedPatchDelegate needPatchCallback, Form parentForm = null, byte[] rawRomData = null)
        {
            NesFile nesFile;

            if (rawRomData != null)
            {
                nesFile = new NesFile(rawRomData);
            }
            else
            {
                nesFile = new NesFile(nesFileName);
            }
            nesFile.CorrectRom();
            var crc32            = nesFile.CRC32;
            var code             = GenerateCode(crc32, prefixCode);
            var gamePath         = Path.Combine(GamesDirectory, code);
            var nesPath          = Path.Combine(gamePath, code + ".nes");
            var patchesDirectory = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "patches");

            Directory.CreateDirectory(patchesDirectory);
            Directory.CreateDirectory(gamePath);
            var patches = Directory.GetFiles(patchesDirectory, string.Format("{0:X8}*.ips", crc32), SearchOption.AllDirectories);

            if (patches.Length > 0 && needPatch != false)
            {
                if (needPatch == true || ((needPatchCallback != null) && needPatchCallback(parentForm, Path.GetFileName(nesFileName)))) /*MessageBox.Show(parentForm, string.Format(Resources.PatchQ, Path.GetFileName(nesFileName)), Resources.PatchAvailable, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes*/
                {
                    needPatch = true;
                    var patch = patches[0];
                    if (rawRomData == null)
                    {
                        rawRomData = File.ReadAllBytes(nesFileName);
                    }
                    Debug.WriteLine(string.Format("Patching {0}", nesFileName));
                    IpsPatcher.Patch(patch, ref rawRomData);
                    nesFile = new NesFile(rawRomData);
                }
                else
                {
                    needPatch = false;
                }
            }

            if (nesFile.Mapper == 71)
            {
                nesFile.Mapper = 2;                       // games by Codemasters/Camerica - this is UNROM clone. One exception - Fire Hawk
            }
            if (nesFile.Mapper == 88)
            {
                nesFile.Mapper = 4;                       // Compatible with MMC3... sometimes
            }
            if (nesFile.Mapper == 95)
            {
                nesFile.Mapper = 4;                       // Compatible with MMC3
            }
            if (nesFile.Mapper == 206)
            {
                nesFile.Mapper = 4;                        // Compatible with MMC3
            }
            if (!supportedMappers.Contains(nesFile.Mapper) && (ignoreMapper != true))
            {
                Directory.Delete(gamePath, true);
                if (ignoreMapper != false)
                {
                    throw new UnsupportedMapperException(nesFile);
                }
                else
                {
                    Debug.WriteLine(string.Format("Game {0} has mapper #{1}, skipped", nesFileName, nesFile.Mapper));
                    return(null);
                }
            }
            if ((nesFile.Mirroring == NesFile.MirroringType.FourScreenVram) && (ignoreMapper != true))
            {
                Directory.Delete(gamePath, true);
                if (ignoreMapper != false)
                {
                    throw new UnsupportedFourScreenException(nesFile);
                }
                else
                {
                    Debug.WriteLine(string.Format("Game {0} has four-screen mirroring, skipped", nesFileName, nesFile.Mapper));
                    return(null);
                }
            }
            // TODO: Make trainer check. I think that NES Mini doesn't support it.

            nesFile.Save(nesPath);
            var game = new NesGame(gamePath, true);

            game.Name = Path.GetFileNameWithoutExtension(nesFileName);
            if (game.Name.Contains("(J)"))
            {
                game.region = "Japan";
            }
            game.TryAutofill(crc32);
            game.Name = Regex.Replace(game.Name, @" ?\(.*?\)", string.Empty).Trim();
            game.Name = Regex.Replace(game.Name, @" ?\[.*?\]", string.Empty).Trim();
            game.Name = game.Name.Replace("_", " ").Replace("  ", " ") /*.Replace(", The", "")*/.Trim();

            // Trying to find cover file
            Image cover = null;

            if (!string.IsNullOrEmpty(nesFileName))
            {
                var imagePath = Path.Combine(Path.GetDirectoryName(nesFileName), Path.GetFileNameWithoutExtension(nesFileName) + ".png");
                if (File.Exists(imagePath))
                {
                    cover = LoadBitmap(imagePath);
                }
                imagePath = Path.Combine(Path.GetDirectoryName(nesFileName), Path.GetFileNameWithoutExtension(nesFileName) + ".jpg");
                if (File.Exists(imagePath))
                {
                    cover = LoadBitmap(imagePath);
                }
                var artDirectory = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "art");
                Directory.CreateDirectory(artDirectory);
                imagePath = Path.Combine(artDirectory, Path.GetFileNameWithoutExtension(nesFileName) + ".png");
                if (File.Exists(imagePath))
                {
                    cover = LoadBitmap(imagePath);
                }
                imagePath = Path.Combine(artDirectory, Path.GetFileNameWithoutExtension(nesFileName) + ".jpg");
                if (File.Exists(imagePath))
                {
                    cover = LoadBitmap(imagePath);
                }
                var covers = Directory.GetFiles(artDirectory, string.Format("{0:X8}*.*", crc32), SearchOption.AllDirectories);
                if (covers.Length > 0)
                {
                    cover = LoadBitmap(covers[0]);
                }
            }
            if (cover == null)
            {
                if (game.region == "Japan")
                {
                    cover = Resources.blank_jp;
                }
                else
                {
                    cover = Resources.blank;
                }
            }
            game.Image = cover;
            game.Args  = DefaultArgs;
            game.Save();
            return(game);
        }
Ejemplo n.º 9
0
 public GameGenieCodeAddModForm(NesGame game)
 {
     InitializeComponent();
     FGame = game;
 }
Ejemplo n.º 10
0
        public ICollection <NesMiniApplication> AddGames(string[] files, Form parentForm = null)
        {
            var apps = new List <NesMiniApplication>();

            addedApplications = null;
            //bool NoForAllUnsupportedMappers = false;
            bool YesForAllUnsupportedMappers = false;

            YesForAllPatches = false;
            int count = 0;

            SetStatus(Resources.AddingGames);
            foreach (var file in files)
            {
                NesMiniApplication app = null;
                try
                {
                    var    fileName  = file;
                    var    ext       = Path.GetExtension(file).ToLower();
                    bool?  needPatch = YesForAllPatches ? (bool?)true : null;
                    byte[] rawData   = null;
                    if (ext == ".7z" || ext == ".zip" || ext == ".rar")
                    {
                        SevenZipExtractor.SetLibraryPath(Path.Combine(baseDirectory, IntPtr.Size == 8 ? @"tools\7z64.dll" : @"tools\7z.dll"));
                        using (var szExtractor = new SevenZipExtractor(file))
                        {
                            var filesInArchive    = new List <string>();
                            var nesFilesInArchive = new List <string>();
                            foreach (var f in szExtractor.ArchiveFileNames)
                            {
                                var e = Path.GetExtension(f).ToLower();
                                if (e == ".nes" || e == ".fds" || e == ".unf" || e == ".unif")
                                {
                                    nesFilesInArchive.Add(f);
                                }
                                filesInArchive.Add(f);
                            }
                            if (nesFilesInArchive.Count == 1) // Only one NES file
                            {
                                fileName = nesFilesInArchive[0];
                            }
                            else if (nesFilesInArchive.Count > 1) // Many NES files, need to select
                            {
                                if (SelectFileFromThread(nesFilesInArchive.ToArray()) == DialogResult.OK)
                                {
                                    fileName = selectedFile;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            else if (filesInArchive.Count == 1) // No NES files but only one another file
                            {
                                fileName = filesInArchive[0];
                            }
                            else // Need to select
                            {
                                if (SelectFileFromThread(filesInArchive.ToArray()) == DialogResult.OK)
                                {
                                    fileName = selectedFile;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            var o = new MemoryStream();
                            szExtractor.ExtractFile(fileName, o);
                            rawData = new byte[o.Length];
                            o.Seek(0, SeekOrigin.Begin);
                            o.Read(rawData, 0, (int)o.Length);
                        }
                    }
                    if (Path.GetExtension(fileName).ToLower() == ".nes")
                    {
                        try
                        {
                            app = NesGame.Import(fileName, YesForAllUnsupportedMappers ? (bool?)true : null, ref needPatch, needPatchCallback, this, rawData);

                            // Trying to import Game Genie codes
                            var lGameGeniePath = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".xml");
                            if (File.Exists(lGameGeniePath))
                            {
                                GameGenieDataBase lGameGenieDataBase = new GameGenieDataBase(app);
                                lGameGenieDataBase.ImportCodes(lGameGeniePath, true);
                                lGameGenieDataBase.Save();
                            }
                        }
                        catch (Exception ex)
                        {
                            if (ex is UnsupportedMapperException || ex is UnsupportedFourScreenException)
                            {
                                var r = MessageBoxFromThread(this,
                                                             (ex is UnsupportedMapperException)
                                       ? string.Format(Resources.MapperNotSupported, Path.GetFileName(fileName), (ex as UnsupportedMapperException).ROM.Mapper)
                                       : string.Format(Resources.FourScreenNotSupported, Path.GetFileName(fileName)),
                                                             Resources.AreYouSure,
                                                             files.Length <= 1 ? MessageBoxButtons.YesNo : MessageBoxButtons.AbortRetryIgnore,
                                                             MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, true);
                                while (r == DialogResult.None)
                                {
                                    Thread.Sleep(100);
                                }
                                if (r == DialogResult.Yes || r == DialogResult.Abort || r == DialogResult.Retry)
                                {
                                    app = NesGame.Import(fileName, true, ref needPatch, needPatchCallback, this, rawData);
                                }
                                if (r == DialogResult.Abort)
                                {
                                    YesForAllUnsupportedMappers = true;
                                }
                            }
                            else
                            {
                                throw ex;
                            }
                        }
                    }
                    else
                    {
                        app = NesMiniApplication.Import(fileName, rawData);
                    }
                    ConfigIni.SelectedGames += ";" + app.Code;
                }
                catch (Exception ex)
                {
                    if (ex is ThreadAbortException)
                    {
                        return(null);
                    }
                    Debug.WriteLine(ex.Message + ex.StackTrace);
                    ShowError(ex, true);
                }
                if (app != null)
                {
                    apps.Add(app);
                }
                SetProgress(++count, files.Length);
            }
            return(apps); // Added games/apps
        }