Beispiel #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;
        }
Beispiel #2
0
        // Constructor
        public GameLauncher(int gameId)
        {
            db = new MyDbContext();

            GameId = gameId;

            // get Game object
            Game game = (from g in db.Game
                         where g.gameId == gameId
                         select g).SingleOrDefault();

            ConfigId = game.configId;
            RomPath  = game.gamePath;
            RomName  = game.gameName;

            // get globals
            Global = (from g in db.GlobalSettings
                      where g.settingsId == 1
                      select g).SingleOrDefault();

            SystemId = game.systemId;

            // do PSX sbi check and check whether game file actually exists (as it might have been renamed)
            if (SystemId == 9 && File.Exists(game.gamePath))
            {
                // get all implied files from othe cue/m3u that is in the database
                string       cuePath     = game.gamePath; // this is never relative with disc-based games
                DiscGameFile originalCue = new DiscGameFile(cuePath, 9);

                List <DiscGameFile> imageFiles = new List <DiscGameFile>(); // DiscScan.ParseTrackSheetForImageFiles(new DiscGameFile(cuePath, 9), 9);

                // check whether m3u
                if (originalCue.Extension.ToLower() == ".m3u")
                {
                    // get all cue files
                    var allc = DiscScan.ParseTrackSheet(originalCue, CueType.m3u, SystemId);
                    foreach (var g in allc)
                    {
                        imageFiles.Add(g);
                    }
                }
                else
                {
                    // standard cue file
                    imageFiles.Add(originalCue);
                }

                // iterate through each image and check for serial number
                for (int i = 0; i < imageFiles.Count; i++)
                {
                    string serial = MedDiscUtils.GetPSXSerial(imageFiles[i].FullPath);

                    if (serial == null || serial == "")
                    {
                        continue;
                    }

                    // add serial to imageFiles
                    imageFiles[i].ExtraInfo = serial;
                }

                // if imageFile has only one entry, then this matches originalCue
                if (imageFiles.Count == 1)
                {
                    if (PsxSBI.IsSbiAvailable(imageFiles.First().ExtraInfo) == true)
                    {
                        // sbi is available - check whether sbi already exists
                        string sbipath = imageFiles.First().FullPath.Replace(imageFiles.First().Extension, ".sbi");

                        //if (!File.Exists(imageFiles.First().FolderPath + "\\" + imageFiles.First().FileName.Replace(imageFiles.First().Extension, "") + ".sbi"))

                        if (!File.Exists(sbipath))
                        {
                            var result = MessagePopper.ShowMessageDialog("MedLaunch has determined that you need an available SBI patch file to play this game properly.\n\nDo you wish to copy this file to your disc directory?\n",
                                                                         "SBI Patch Needed - " + imageFiles.First().FileName, MessagePopper.DialogButtonOptions.YESNO);

                            //MessageBoxResult result = MessageBox.Show("MedLaunch has determined that you need an available SBI patch file to play this game properly.\n\nDo you wish to copy this file to your disc directory?\n",
                            //    "SBI Patch Needed - " + imageFiles.First().FileName, MessageBoxButton.YesNo, MessageBoxImage.Question);

                            if (result == MessagePopper.ReturnResult.Affirmative)
                            {
                                // copy sbi file to folder (named the same as the cue file)
                                originalCue.ExtraInfo = imageFiles.First().ExtraInfo;

                                //PsxSBI.InstallSBIFile(originalCue);
                                PsxSBI.InstallSBIFile(imageFiles.First());
                            }
                        }
                    }
                }

                // if imageFiles has multiple entries - it will have come from an m3u file
                if (imageFiles.Count > 1)
                {
                    // create an array of m3u cue files
                    string[] cues = File.ReadAllLines(originalCue.FullPath);

                    // loop through
                    for (int image = 0; image < imageFiles.Count; image++)
                    {
                        if (PsxSBI.IsSbiAvailable(imageFiles[image].ExtraInfo) == true)
                        {
                            // sbi is available - prompt user
                            if (!File.Exists(imageFiles[image].FolderPath + "\\" + imageFiles[image].FileName.Replace(imageFiles[image].Extension, "") + ".sbi"))
                            {
                                var result = MessagePopper.ShowMessageDialog("MedLaunch has determined that you need an available SBI patch file to play this game properly.\n\nDo you wish to copy this file to your disc directory?\n",
                                                                             "SBI Patch Needed - " + imageFiles.First().FileName, MessagePopper.DialogButtonOptions.YESNO);

                                //MessageBoxResult result = MessageBox.Show("MedLaunch has determined that you need an available SBI patch file to play this game properly.\n\nDo you wish to copy this file to your disc directory?\n",
                                //"SBI Patch Needed - " + imageFiles[image].FileName + imageFiles[image].Extension, MessageBoxButton.YesNo, MessageBoxImage.Question);

                                if (result == MessagePopper.ReturnResult.Affirmative)
                                {
                                    // copy sbi file to folder (named the same as the cue file)
                                    DiscGameFile d = new DiscGameFile(cues[image], 9);
                                    d.ExtraInfo = imageFiles[image].ExtraInfo;

                                    PsxSBI.InstallSBIFile(d);
                                }
                            }
                        }
                    }
                }
            }

            // logic for faust & fast
            if (game.systemId == 12)
            {
                if (Global.enableSnes_faust == true)
                {
                    SystemId = 16;
                    //MessageBoxResult result = MessageBox.Show("FAUST DETECTED");
                }
                else
                {
                    SystemId = game.systemId;
                }
            }
            if (game.systemId == 7 || game.systemId == 18)
            {
                if (Global.enablePce_fast == true)
                {
                    SystemId = 17;
                }
                else
                {
                    SystemId = 7;
                }
            }

            gSystem    = GSystem.GetSystems().Where(a => a.systemId == SystemId).Single();
            SystemCode = gSystem.systemCode;



            RomFolder = GetRomFolder(SystemId, db);

            MednafenFolder = (from m in db.Paths
                              select m.mednafenExe).SingleOrDefault();

            // set the config id
            int actualConfigId = SystemId + 2000000000;

            // take general settings from base config (2000000000) and system specific settings from actual config



            ConfigBaseSettings _config = (from c in db.ConfigBaseSettings
                                          where (c.ConfigId == actualConfigId)
                                          select c).SingleOrDefault();

            List <ConfigObject> sysConfigObject = ListFromType(_config).Where(a => !a.Key.StartsWith("__")).ToList();

            SysConfigObject = new List <ConfigObject>();

            foreach (var x in sysConfigObject)
            {
                var  systems = GSystem.GetSystems().Where(a => a.systemCode != SystemCode);
                bool isValid = true;
                foreach (var sc in systems)
                {
                    if (x.Key.StartsWith(sc.systemCode + "__"))
                    {
                        isValid = false;
                        break;
                    }
                }
                if (isValid == true)
                {
                    SysConfigObject.Add(x);
                }
            }


            // if option is enabled save system specific config for this system
            if (Global.saveSystemConfigs == true)
            {
                if (SystemCode == "pcecd")
                {
                    SystemCode = "pce";
                }

                SaveSystemConfigToDisk(SystemCode, SysConfigObject);
            }


            // build actual config list
            //ConfObject = new List<ConfigObject>();
            //ConfObject.AddRange(GenConfigObject);
            //ConfObject.AddRange(SysConfigObject);

            /*
             * if (_config.isEnabled == true)
             * {
             *  Config = _config;
             * }
             * else
             * {
             *  Config = (from c in db.ConfigBaseSettings
             *            where c.ConfigId == 2000000000
             *            select c).SingleOrDefault();
             * }
             */


            // get netplay
            Netplay = (from n in db.ConfigNetplaySettings
                       where n.ConfigNPId == 1
                       select n).SingleOrDefault();



            // get server
            Server = (from s in db.ConfigServerSettings
                      where s.ConfigServerId == Global.serverSelected
                      select s).SingleOrDefault();

            // get overide server settings (password and gamekey from custom
            ServerOveride = (from s in db.ConfigServerSettings
                             where s.ConfigServerId == 100
                             select s).SingleOrDefault();
        }