Example #1
0
        public RomInspector()
        {
            this.InitializeComponent();

            // get the mainwindow
            MainWindow mw = Application.Current.Windows.OfType <MainWindow>().FirstOrDefault();

            int numRowsCount = mw.dgGameList.SelectedItems.Count;

            if (numRowsCount != 1)
            {
                return;
            }

            GamesLibraryModel drv = (GamesLibraryModel)mw.dgGameList.SelectedItem;

            if (drv == null)
            {
                return;
            }
            int romId = drv.ID;

            // get game object
            Game g = Game.GetGame(romId);

            GameObj = g;

            // populate tab textboxes with game name
            tbRawInspecResults.Text = g.gamePath;
            tbLibInspecResults.Text = g.gamePath;

            // init manual config button
            if (g.ManualEditSet == true)
            {
                btnToggleManualEdit.IsChecked = true;
                EnableControls();
            }
            else
            {
                btnToggleManualEdit.IsChecked = false;
                DisableControls();
            }

            // init ucon64 wrapper
            ucon64_wrapper.UconWrapper u = new ucon64_wrapper.UconWrapper(System.AppDomain.CurrentDomain.BaseDirectory + @"\ucon64-bin\ucon64.exe");
            string gamePath = Game.ReturnActualGamePath(g);

            UconResult obj = new UconResult();

            // is it a ROM or a DISC?
            string extension = System.IO.Path.GetExtension(gamePath);

            if (extension.ToLower().Contains(".m3u") ||
                extension.ToLower().Contains(".cue") ||
                extension.ToLower().Contains(".ccd") ||
                extension.ToLower().Contains(".toc")
                )
            {
                if (g.systemId == 13)
                {
                    // saturn
                    DiscGameFile dgf = new DiscGameFile(gamePath, g.systemId);
                    // get saturn data from disk image
                    var file = DiscScan.ParseTrackSheetForImageFiles(dgf, g.systemId).FirstOrDefault();
                    if (file != null)
                    {
                        var    satInfo = MedDiscUtils.GetSSData(file.FullPath);
                        string outp    = "Initialising MedLaunch Sega Saturn DISC Interogator\n*******************************************\n\n";
                        outp += satInfo.Title + "\n";
                        outp += satInfo.SerialNumber + "\n";
                        outp += satInfo.Date + "\n";
                        outp += satInfo.Country + "\n";
                        outp += satInfo.JpnTitle + "\n";
                        outp += satInfo.PeriphCode + "\n";
                        outp += satInfo.CountryCode + "\n";

                        tbInsResult.Text = outp;

                        // pop tbs
                        tbIntGame.Text    = satInfo.Title;
                        tbIntRegion.Text  = satInfo.Country;
                        tbIntYear.Text    = satInfo.Date;
                        tbIntVersion.Text = satInfo.SerialNumber;
                    }
                }
                else if (g.systemId == 9)
                {
                    // psx
                    DiscGameFile dgf   = new DiscGameFile(gamePath, g.systemId);
                    var          files = DiscScan.ParseTrackSheetForImageFiles(dgf, g.systemId);

                    // iterate through each image file and scan it
                    int cnt = 0;
                    foreach (var im in files)
                    {
                        var res = u.ScanGame(im.FullPath, uConOps.GetSystemType(g.systemId));
                        tbInsResult.Text += res.RawOutput;
                        if (files.Count > 1)
                        {
                            tbInsResult.Text += "\n****************************\n";
                        }
                        if (cnt == 0)
                        {
                            obj = res;
                        }
                        cnt++;
                    }
                }

                /*
                 * DiscGameFile dgf = new DiscGameFile(gamePath, g.systemId);
                 * var files = DiscScan.ParseTrackSheetForImageFiles(dgf, g.systemId);
                 *
                 * // iterate through each image file and scan it
                 * int cnt = 0;
                 * foreach (var im in files)
                 * {
                 *  var res = u.ScanGame(im.FullPath, uConOps.GetSystemType(g.systemId));
                 *  tbInsResult.Text += res.RawOutput;
                 *  if (files.Count > 1)
                 *      tbInsResult.Text += "\n****************************\n";
                 *  if (cnt == 0)
                 *      obj = res;
                 *  cnt++;
                 * }
                 */
            }

            else
            {
                // check whether game is within 7zip or part of a multi-game archive
                if (g.gamePath.Contains("*/"))
                {
                    // need to extract game first before scanning
                    GameLauncher gl       = new GameLauncher(g.gameId);
                    string       tempPath = gl.BuildFullGamePath(Paths.GetSystemPath(g.systemId), g.gamePath);

                    // scan game
                    var re = u.ScanGame(tempPath, uConOps.GetSystemType(g.systemId));

                    // update textbox
                    tbInsResult.Text = re.RawOutput;
                    obj = re;
                }
                else
                {
                    // no extraction needed
                    var result = u.ScanGame(gamePath, uConOps.GetSystemType(g.systemId));

                    // update text box
                    tbInsResult.Text = result.RawOutput;
                    obj = result;
                }


                // library data tab
            }

            if (GameObj.systemId == 9)
            {
                // get the playstation serial
                string ser = MedDiscUtils.GetPSXSerial(GameObj.gamePath);
                tbIntVersion.Text = ser;
            }

            PopulateLibraryData();
            LookupDAT();
            LookupScrapeMatched();


            /* populate other textboxes */

            // raw
            if (g.systemId != 13)
            {
                tbIntSystem.Text         = obj.Data.DetectedSystemType;
                tbIntGame.Text           = obj.Data.DetectedGameName;
                tbIntPublisher.Text      = obj.Data.DetectedPublisher;
                tbIntRegion.Text         = obj.Data.DetectedRegion;
                tbIntType.Text           = obj.Data.DetectedRomType;
                tbIntYear.Text           = obj.Data.DetectedYear;
                tbIntChecksumString.Text = obj.Data.DetectedChecksumComparison;
                if (obj.Data.IsInterleaved == true)
                {
                    tbIntInterleaving.Text = "Yes";
                }
                if (obj.Data.IsInterleaved == false)
                {
                    tbIntInterleaving.Text = "No";
                }
                tbIntChecksumCrc.Text = obj.Data.CRC32;

                if (tbIntChecksumString.Text.Contains("Bad,"))
                {
                    tbIntChecksumString.Foreground = new SolidColorBrush(Colors.Red);
                }
                if (tbIntChecksumString.Text.Contains("OK,"))
                {
                    tbIntChecksumString.Foreground = new SolidColorBrush(Colors.Green);
                }

                tbIntVersion.Text = obj.Data.DetectedVersion;
                tbIntPadding.Text = obj.Data.DetectedPadding;
                tbIntSize.Text    = obj.Data.DetectedSize;

                // status box
                string resultMessage = obj.Status;

                if (obj.Data.systemType == SystemType.Genesis && obj.Data.romType == RomType.SMD)
                {
                    if (obj.Data.IsChecksumValid == false)
                    {
                        resultMessage = "Checksum invalid\n";
                        if (obj.Data.IsInterleaved == true)
                        {
                            // needs de-interleaving
                            resultMessage += "Also, this is a genesis SMD ROM that is interleaved. Mednafen will not run this game and MedLaunch cannot currently convert it.";
                        }
                        if (obj.Data.IsInterleaved == false)
                        {
                            // game will most probably play
                            resultMessage += "However this is a genesis ROM that is NOT interleaved. It should work in Mednafen.";
                        }
                    }
                    else
                    {
                        resultMessage = "Checksum is valid\n";
                        if (obj.Data.IsInterleaved == true)
                        {
                            // needs de-interleaving
                            resultMessage += "This is a genesis SMD ROM that is interleaved. MedLaunch will auto-convert this game at launch-time so that it works with Mednafen.";
                        }
                        if (obj.Data.IsInterleaved == false)
                        {
                            // game will most probably play
                            resultMessage += "This is a genesis ROM that is NOT interleaved. It should work in Mednafen without conversion.";
                        }
                    }
                }

                tbIntResult.Text = resultMessage;
            }


            //populate rom field on library tab
            LookupROM();

            // add gameobj to mainwindow
            mw.InspGame = GameObj;
        }