Exemplo n.º 1
0
        private bool LoadDisc(string path, CoreComm nextComm, HawkFile file, string ext, out IEmulator nextEmulator, out GameInfo game)
        {
            var disc = DiscExtensions.CreateAnyType(path, str => DoLoadErrorCallback(str, "???", LoadErrorType.DiscError));

            if (disc == null)
            {
                game         = null;
                nextEmulator = null;
                return(false);
            }

            // TODO - use more sophisticated IDer
            var discType   = new DiscIdentifier(disc).DetectDiscType();
            var discHasher = new DiscHasher(disc);
            var discHash   = discType == DiscType.SonyPSX
                                ? discHasher.Calculate_PSX_BizIDHash().ToString("X8")
                                : discHasher.OldHash();

            game = Database.CheckDatabase(discHash);
            if (game == null)
            {
                // try to use our wizard methods
                game = new GameInfo {
                    Name = Path.GetFileNameWithoutExtension(file.Name), Hash = discHash
                };

                switch (discType)
                {
                case DiscType.SegaSaturn:
                    game.System = "SAT";
                    break;

                case DiscType.SonyPSP:
                    game.System = "PSP";
                    break;

                case DiscType.MegaCD:
                    game.System = "GEN";
                    break;

                case DiscType.PCFX:
                    game.System = "PCFX";
                    break;

                case DiscType.TurboGECD:
                case DiscType.TurboCD:
                    game.System = "PCECD";
                    break;

                case DiscType.Amiga:
                case DiscType.CDi:
                case DiscType.Dreamcast:
                case DiscType.GameCube:
                case DiscType.NeoGeoCD:
                case DiscType.Panasonic3DO:
                case DiscType.Playdia:
                case DiscType.Wii:
                    // no supported emulator core for these (yet)
                    game.System = discType.ToString();
                    throw new NoAvailableCoreException(discType.ToString());

                case DiscType.AudioDisc:
                case DiscType.UnknownCDFS:
                case DiscType.UnknownFormat:
                    game.System = PreferredPlatformIsDefined(ext)
                                                        ? _config.PreferredPlatformsForExtensions[ext]
                                                        : "NULL";
                    break;

                default:                         //"for an unknown disc, default to psx instead of pce-cd, since that is far more likely to be what they are attempting to open" [5e07ab3ec3b8b8de9eae71b489b55d23a3909f55, year 2015]
                case DiscType.SonyPSX:
                    game.System = "PSX";
                    break;
                }
            }

            var cip = new CoreInventoryParameters(this)
            {
                Comm  = nextComm,
                Game  = game,
                Discs =
                {
                    new DiscAsset
                    {
                        DiscData = disc,
                        DiscType = new DiscIdentifier(disc).DetectDiscType(),
                        DiscName = Path.GetFileNameWithoutExtension(path)
                    }
                },
            };

            nextEmulator = MakeCoreFromCoreInventory(cip);
            return(true);
        }
Exemplo n.º 2
0
        private GameInfo MakeGameFromDisc(Disc disc, string ext, string name)
        {
            // TODO - use more sophisticated IDer
            var discType   = new DiscIdentifier(disc).DetectDiscType();
            var discHasher = new DiscHasher(disc);
            var discHash   = discType == DiscType.SonyPSX
                                ? discHasher.Calculate_PSX_BizIDHash().ToString("X8")
                                : discHasher.OldHash();

            var game = Database.CheckDatabase(discHash);

            if (game == null)
            {
                // try to use our wizard methods
                game = new GameInfo {
                    Name = name, Hash = discHash
                };

                switch (discType)
                {
                case DiscType.SegaSaturn:
                    game.System = "SAT";
                    break;

                case DiscType.SonyPSP:
                    game.System = "PSP";
                    break;

                case DiscType.SonyPS2:
                    game.System = "PS2";
                    break;

                case DiscType.MegaCD:
                    game.System = "GEN";
                    break;

                case DiscType.PCFX:
                    game.System = "PCFX";
                    break;

                case DiscType.TurboGECD:
                case DiscType.TurboCD:
                    game.System = "PCE";
                    break;

                case DiscType.Amiga:
                case DiscType.CDi:
                case DiscType.Dreamcast:
                case DiscType.GameCube:
                case DiscType.NeoGeoCD:
                case DiscType.Panasonic3DO:
                case DiscType.Playdia:
                case DiscType.Wii:
                    // no supported emulator core for these (yet)
                    game.System = discType.ToString();
                    throw new NoAvailableCoreException(discType.ToString());

                case DiscType.AudioDisc:
                case DiscType.UnknownCDFS:
                case DiscType.UnknownFormat:
                    game.System = PreferredPlatformIsDefined(ext)
                                                        ? _config.PreferredPlatformsForExtensions[ext]
                                                        : "NULL";
                    break;

                default:                         //"for an unknown disc, default to psx instead of pce-cd, since that is far more likely to be what they are attempting to open" [5e07ab3ec3b8b8de9eae71b489b55d23a3909f55, year 2015]
                case DiscType.SonyPSX:
                    game.System = "PSX";
                    break;
                }
            }
            return(game);
        }
        public void Run(string[] args)
        {
            string indir     = null;
            string dpTemp    = null;
            string fpOutfile = null;

            for (int i = 0; ;)
            {
                if (i == args.Length)
                {
                    break;
                }
                var arg = args[i++];
                if (arg == "--indir")
                {
                    indir = args[i++];
                }
                if (arg == "--tempdir")
                {
                    dpTemp = args[i++];
                }
                if (arg == "--outfile")
                {
                    fpOutfile = args[i++];
                }
            }

            var done = new HashSet <string>();

            foreach (var line in File.ReadAllLines(fpOutfile))
            {
                if (line.Trim() == "")
                {
                    continue;
                }
                var parts = line.Split(new[] { "//" }, StringSplitOptions.None);
                done.Add(parts[1]);
            }

            using (var outf = new StreamWriter(fpOutfile))
            {
                Dictionary <uint, string> FoundHashes = new Dictionary <uint, string>();
                object olock = new object();

                var todo = FindExtensionsRecurse(indir, ".CUE");

                int progress = 0;

                //loop over games (parallel doesnt work well when reading tons of data over the network, as we are here to do the complete redump hash)
                var po = new ParallelOptions();
                //po.MaxDegreeOfParallelism = Environment.ProcessorCount - 1;
                po.MaxDegreeOfParallelism = 1;
                Parallel.ForEach(todo, po, (fiCue) =>
                {
                    string name = Path.GetFileNameWithoutExtension(fiCue);

                    lock (olock)
                    {
                        if (done.Contains(name))
                        {
                            progress++;
                            return;
                        }
                    }

                    //now look for the cue file
                    using (var disc = Disc.LoadAutomagic(fiCue))
                    {
                        var hasher = new DiscHasher(disc);

                        uint bizHashId  = hasher.Calculate_PSX_BizIDHash();
                        uint redumpHash = hasher.Calculate_PSX_RedumpHash();

                        lock (olock)
                        {
                            progress++;
                            Console.WriteLine("{0}/{1} [{2:X8}] {3}", progress, todo.Count, bizHashId, Path.GetFileNameWithoutExtension(fiCue));
                            outf.WriteLine("bizhash:{0:X8} datahash:{1:X8} //{2}", bizHashId, redumpHash, name);
                            if (FoundHashes.ContainsKey(bizHashId))
                            {
                                Console.WriteLine("--> COLLISION WITH: {0}", FoundHashes[bizHashId]);
                                outf.WriteLine("--> COLLISION WITH: {0}", FoundHashes[bizHashId]);
                            }
                            else
                            {
                                FoundHashes[bizHashId] = name;
                            }

                            Console.Out.Flush();
                            outf.Flush();
                        }
                    }
                }); //major loop
            }       //using(outfile)
        }           //MyRun()