Exemple #1
0
        private void dgRoms_SelectionChanged(object sender, EventArgs e)
        {
            if (dgRoms.CurrentRow != null)
            {
                currentRom = (RomInfo)dgRoms.CurrentRow.DataBoundItem;
                var local = Path.Combine(_ngmhFolder, "local");
                currentExtendedInfo = GetExtendedRomInfo(currentRom);
                if (currentExtendedInfo != null)
                {
                    //populate controls
                    tbName.Text = currentExtendedInfo.Name;
                    tbDir.Text  = currentExtendedInfo.Dir;

                    if (_ASPMode)
                    {
                        using (var bmpTemp = new Bitmap(currentExtendedInfo.CoverImage)) {
                            pbCover.Image = new Bitmap(bmpTemp);
                        }
                    }
                    else
                    {
                        using (var bmpTemp = new Bitmap(currentExtendedInfo.LCDImage)) {
                            pbLCD.Image = new Bitmap(bmpTemp);
                        }
                        using (var bmpTemp = new Bitmap(currentExtendedInfo.TVImage)) {
                            pbTV.Image = new Bitmap(bmpTemp);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void LoadAll()
        {
            var romInfoData = File.ReadAllLines(_romInfoPath);
            var currRom     = new RomInfo();

            foreach (var dataLine in romInfoData)
            {
                //format (line by line) is ID, EMU, PATH, BLANK
                if (dataLine.StartsWith("ID"))
                {
                    if (currRom != null && !String.IsNullOrWhiteSpace(currRom.ID))
                    {
                        romInfos.Add(currRom);
                        EmuLists[currRom.EMU].Add(currRom);
                        currRom = null;
                    }
                    currRom    = new RomInfo();
                    currRom.ID = dataLine.Substring(3);
                }
                else if (dataLine.StartsWith("EMU"))
                {
                    currRom.EMU = (EmulatorType)Enum.Parse(typeof(EmulatorType), dataLine.Substring(4));
                    if (!FoundEmus.Contains(dataLine.Substring(4)))
                    {
                        FoundEmus.Add(dataLine.Substring(4));
                        if (currRom.EMU != EmulatorType.fba && currRom.EMU != EmulatorType.ra && currRom.EMU != EmulatorType.ng && currRom.EMU != EmulatorType.pce) //don't add fba to the grid list since adding/editing roms for that is unsupported.
                        {
                            FoundEmusObj.Add(new Emu()
                            {
                                Type = currRom.EMU
                            });
                        }
                        EmuLists.Add(currRom.EMU, new List <RomInfo>());
                    }
                }
                else if (dataLine.StartsWith("PATH"))
                {
                    currRom.PATH = dataLine.Substring(5);
                }
                else
                {
                    if (currRom != null && !String.IsNullOrWhiteSpace(currRom.ID))
                    {
                        romInfos.Add(currRom);
                        EmuLists[currRom.EMU].Add(currRom);
                        currRom = null;
                    }
                }
            }
            if (currRom != null)
            {
                romInfos.Add(currRom);
                EmuLists[currRom.EMU].Add(currRom);
                currRom = null;
            } //clean up if we have one left e.g. if there isn't a new line at the end of the file
            dgEmus.DataSource = FoundEmusObj;
        }
Exemple #3
0
 private void ReloadAll()
 {
     dgRoms.SelectionChanged -= dgRoms_SelectionChanged;
     dgEmus.SelectionChanged -= dgEmus_SelectionChanged;
     dgRoms.ClearSelection();
     dgRoms.DataSource = null;
     dgEmus.ClearSelection();
     dgEmus.DataSource        = null;
     dgRoms.SelectionChanged += dgRoms_SelectionChanged;
     dgEmus.SelectionChanged += dgEmus_SelectionChanged;
     FoundEmus.Clear();
     FoundEmusObj.Clear();
     EmuLists.Clear();
     romInfos.Clear();
     currentList.Clear();
     currentRom          = null;
     currentExtendedInfo = null;
     LoadAll();
 }
Exemple #4
0
        private void bNew_Click(object sender, EventArgs e)
        {
            var newRomDlg = new NewRomDlg();

            newRomDlg.Text = $"Adding new ROM for {currentEmu} system";
            if (newRomDlg.ShowDialog() == DialogResult.OK)
            {
                Cursor.Current = Cursors.WaitCursor;
                try {
                    var newInfo = new RomInfo()
                    {
                        EMU = currentEmu,
                        ID  = Path.GetFileNameWithoutExtension(newRomDlg.RomPath)
                    };
                    if (_ASPMode)
                    {
                        newInfo.PATH = Path.Combine("/mnt/hdisk/asph/hack/roms/", newInfo.EmuString, Path.GetFileName(newRomDlg.RomPath)).Replace("\\", "/");
                    }
                    else
                    {
                        newInfo.PATH = Path.Combine("/vendor/res/roms/", newInfo.EmuString, Path.GetFileName(newRomDlg.RomPath)).Replace("\\", "/");
                    }
                    currentList.Add(newInfo);
                    ExtendedRomInfo newExt;
                    if (_ASPMode)
                    {
                        newExt = new ExtendedRomInfo()
                        {
                            ID         = -1, //we'll need to replace this when traversing the INI.
                            Name       = newRomDlg.RomName,
                            Dir        = newInfo.ID,
                            IsNew      = true,
                            CoverImage = Path.Combine(_ngmhFolder, "games", newInfo.ID, "cover.png")
                        };
                        //save images and move rom into place.
                        Directory.CreateDirectory(Path.GetDirectoryName(newExt.CoverImage));
                        Properties.Resources.Cover.Save(newExt.CoverImage);
                        Directory.CreateDirectory(Path.GetDirectoryName(newInfo.PATH.Replace("/mnt/hdisk/asph/hack/roms", _ngmhFolder)));
                        File.Copy(newRomDlg.RomPath, newInfo.PATH.Replace("/mnt/hdisk/asph/hack/roms", _ngmhFolder), true);
                        //add to RomInfo.txt
                        var romInfoData = File.ReadAllLines(_romInfoPath).ToList();
                        romInfoData.Add($"ID={newInfo.ID}");
                        romInfoData.Add($"EMU={newInfo.EMU}");
                        romInfoData.Add($"PATH={newInfo.PATH}");
                        WriteAllLinesLinux(_romInfoPath, romInfoData, "\n");
                        //finally add to games.Ini.
                        var local     = Path.Combine(_ngmhFolder, "local");
                        var langArray = File.ReadAllLines(Path.Combine(local, "lang_array.ini"));
                        var fold      = String.Empty;
                        foreach (var langLine in langArray)
                        {
                            if (langLine.StartsWith("["))
                            {
                                var lineSplit = langLine.Split('=');
                                var emu       = lineSplit[1].Substring(1, lineSplit[1].Length - 2);
                                if (emu.Equals(currentRom.ASPString, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    fold = Path.Combine(local, lineSplit[0].Substring(1, lineSplit[0].Length - 2));
                                    break;
                                }
                            }
                        }
                        if (fold != String.Empty)
                        {
                            var latestID = 0;
                            var gameIni  = File.ReadAllLines(Path.Combine(fold, "games.ini")).ToList();
                            foreach (var line in gameIni)
                            {
                                if (line.StartsWith("[ID]"))
                                {
                                    var a = line.Substring(5);
                                    latestID = int.Parse(a.Substring(1, a.Length - 2));
                                }
                            }
                            newExt.ID = latestID + 1;
                            if (gameIni.Any())
                            {
                                gameIni.Add("[GAME]");
                                gameIni.Add($"[ID]=<{newExt.ID}>");
                                gameIni.Add($"[TYPE]=< >");
                                gameIni.Add($"[NAME]=< >");
                                gameIni.Add($"[DIR]=<{newExt.Dir}>");
                                gameIni.Add("[GAME\\]");
                                gameIni.Add("");
                            }
                            WriteAllLinesLinux(Path.Combine(fold, "games.ini"), gameIni, "\n");
                        }
                    }
                    else
                    {
                        newExt = new ExtendedRomInfo()
                        {
                            ID       = -1, //we'll need to replace this when traversing the INI.
                            Name     = newRomDlg.RomName,
                            Dir      = newInfo.ID,
                            IsNew    = true,
                            Type     = 5,
                            LCDImage = Path.Combine(_ngmhFolder, "image\\games", newInfo.ID, "LCD.png"),
                            TVImage  = Path.Combine(_ngmhFolder, "image\\games", newInfo.ID, "TV.png"),
                        };
                        //save images and move rom into place.
                        Directory.CreateDirectory(Path.GetDirectoryName(newExt.LCDImage));
                        Properties.Resources.LCD.Save(newExt.LCDImage);
                        Properties.Resources.TV.Save(newExt.TVImage);
                        Directory.CreateDirectory(Path.GetDirectoryName(newInfo.PATH.Replace("/vendor/res", _ngmhFolder)));
                        File.Copy(newRomDlg.RomPath, newInfo.PATH.Replace("/vendor/res", _ngmhFolder), true);
                        //add to RomInfo.txt
                        var romInfoData = File.ReadAllLines(_romInfoPath).ToList();
                        romInfoData.Add($"ID={newInfo.ID}");
                        romInfoData.Add($"EMU={newInfo.EMU}");
                        romInfoData.Add($"PATH={newInfo.PATH}");
                        WriteAllLinesLinux(_romInfoPath, romInfoData, "\n");
                        //finally add to games.Ini.
                        var local = Path.Combine(_ngmhFolder, "local");
                        currentExtendedInfo = new ExtendedRomInfo();
                        List <string> gameIni = new List <string>();
                        string        lastDir = String.Empty;
                        foreach (var dir in Directory.GetDirectories(local))
                        {
                            lastDir = dir;
                            if (dir.Contains(currentRom.EmuString))
                            {
                                var latestID = 0;
                                gameIni = File.ReadAllLines(Path.Combine(dir, "games.ini")).ToList();
                                foreach (var line in gameIni)
                                {
                                    if (line.StartsWith("[ID]"))
                                    {
                                        latestID = int.Parse(line.Substring(5));
                                    }
                                }
                                if (latestID < 80)   //80 for NGM - ASP limit is 300 before things start getting funky.
                                {
                                    newExt.ID = latestID + 1;
                                    break;
                                }
                            }
                        }

                        /* if (newExt.ID == -1) {
                         *  //need to create a new folder...
                         *  //corss that bridge in a minute
                         * }*/
                        if (gameIni.Any())
                        {
                            gameIni.Add("[GAME]");
                            gameIni.Add($"[ID]={newExt.ID}");
                            gameIni.Add($"[TYPE]={newExt.Type}");
                            gameIni.Add($"[NAME]={newExt.Name}");
                            gameIni.Add($"[DIR]={newExt.Dir}");
                            gameIni.Add("");
                        }
                        WriteAllLinesLinux(Path.Combine(lastDir, "games.ini"), gameIni, "\n");
                    }
                    FixRoms();
                    ReloadAll();
                } finally {
                    Cursor.Current = Cursors.Default;
                }
            }
        }
Exemple #5
0
        private ExtendedRomInfo GetExtendedRomInfo(RomInfo currentRom)
        {
            var local     = Path.Combine(_ngmhFolder, "local");
            var gameFound = false;

            currentExtendedInfo = new ExtendedRomInfo();
            if (_ASPMode)
            {
                //need to read langarray as currently the langs can't be custom defined...
                var langArray = File.ReadAllLines(Path.Combine(local, "lang_array.ini"));
                var fold      = String.Empty;
                foreach (var langLine in langArray)
                {
                    if (langLine.StartsWith("["))
                    {
                        var lineSplit = langLine.Split('=');
                        var emu       = lineSplit[1].Substring(1, lineSplit[1].Length - 2);
                        if (emu.Equals(currentRom.ASPString, StringComparison.InvariantCultureIgnoreCase))
                        {
                            fold = Path.Combine(local, lineSplit[0].Substring(1, lineSplit[0].Length - 2));
                            break;
                        }
                    }
                }
                if (fold != String.Empty)
                {
                    var gameIni = File.ReadAllLines(Path.Combine(fold, "games.ini"));
                    foreach (var line in gameIni)
                    {
                        if (line.StartsWith("[GAME]"))
                        {
                        }
                        else if (line.StartsWith("[ID]"))
                        {
                            var a = line.Substring(5);
                            currentExtendedInfo.ID = int.Parse(a.Substring(1, a.Length - 2));
                        }
                        else if (line.StartsWith("[TYPE]"))
                        {
                            //always 5 for non fba
                        }
                        else if (line.StartsWith("[NAME]"))
                        {
                            //currentExtendedInfo.Name = line.Substring(7);
                        }
                        else if (line.StartsWith("[DIR]"))
                        {
                            var a = line.Substring(6);
                            currentExtendedInfo.Dir = a.Substring(1, a.Length - 2);
                            if (currentExtendedInfo.Dir.Equals(currentRom.ID))
                            {
                                gameFound = true;
                                currentExtendedInfo.GameINI = Path.Combine(fold, "games.ini");
                            }
                        }
                        else
                        {
                            if (gameFound)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (var dir in Directory.GetDirectories(local))
                {
                    if (dir.Contains(currentRom.EmuString))
                    {
                        var gameIni = File.ReadAllLines(Path.Combine(dir, "games.ini"));
                        foreach (var line in gameIni)
                        {
                            if (line.StartsWith("[GAME]"))
                            {
                            }
                            else if (line.StartsWith("[ID]"))
                            {
                                currentExtendedInfo.ID = int.Parse(line.Substring(5));
                            }
                            else if (line.StartsWith("[TYPE]"))
                            {
                                //always 5 for non fba
                            }
                            else if (line.StartsWith("[NAME]"))
                            {
                                currentExtendedInfo.Name = line.Substring(7);
                            }
                            else if (line.StartsWith("[DIR]"))
                            {
                                currentExtendedInfo.Dir = line.Substring(6);
                                if (currentExtendedInfo.Dir.Equals(currentRom.ID))
                                {
                                    gameFound = true;
                                    currentExtendedInfo.GameINI = Path.Combine(dir, "games.ini");
                                }
                            }
                            else
                            {
                                if (gameFound)
                                {
                                    break;
                                }
                            }
                        }
                        if (gameFound)
                        {
                            break;
                        }
                    }
                }
            }
            if (gameFound)
            {
                if (_ASPMode)
                {
                    currentExtendedInfo.CoverImage = Path.Combine(_ngmhFolder, "games", currentExtendedInfo.Dir, "cover.png");
                }
                else
                {
                    currentExtendedInfo.LCDImage = Path.Combine(_ngmhFolder, "image\\games", currentExtendedInfo.Dir, "LCD.png");
                    currentExtendedInfo.TVImage  = Path.Combine(_ngmhFolder, "image\\games", currentExtendedInfo.Dir, "TV.png");
                }
                return(currentExtendedInfo);
            }
            else
            {
                return(null);
            }
        }