Beispiel #1
0
        //If this function returns null the plugin will attempt to launch the item
        //as a rom
        public List <string> ViewFiles(Game game, out int matchIndex)
        {
            lock (syncRoot)
            {
                matchIndex = -1;
                if (!loadArchive(game.CurrentDisc.Path))
                {
                    throw new ExtractException("{0} {1}", Translator.Instance.goodmergearchiveerror, game.CurrentDisc.Path);
                }

                List <string> files = new List <string>();
                using (extractor)
                {
                    //List<IArchiveEntry> entries;
                    List <IArchiveEntry> entries;
                    if (extractor.Entries == null || (entries = extractor.Entries.Where(e => !e.IsDirectory).ToList()).Count < 1)
                    {
                        Logger.LogError("Goodmerge: Archive '{0}' appears to be empty");
                        throw new ExtractException(Translator.Instance.goodmergeempty);
                    }

                    Logger.LogInfo("Goodmerge: Viewing archive '{0}', found {1} file{2}", game.CurrentDisc.Path, entries.Count, entries.Count == 1 ? "" : "s");

                    bool matchFile = !string.IsNullOrEmpty(game.CurrentDisc.LaunchFile);
                    if (entries.Count > 0)
                    {
                        for (int i = 0; i < entries.Count; i++)
                        {
                            string file = entries[i].FilePath;
                            if (matchFile && file == game.CurrentDisc.LaunchFile)
                            {
                                matchIndex = i;
                                matchFile  = false;
                            }
                            files.Add(file);
                        }
                        if (matchIndex < 0)
                        {
                            EmulatorProfile profile = game.GetSelectedProfile();
                            if (profile != null)
                            {
                                matchIndex = getBestGoodmergeMatch(entries, profile.GetGoodmergeTags());
                            }
                        }
                    }
                }
                return(files);
            }
        }
Beispiel #2
0
        public string ExtractGame(Game game, EmulatorProfile profile = null, ExecutorLaunchProgressHandler progressHandler = null)
        {
            if (profile == null || profile.EmulatorID != game.ParentEmulator.UID)
            {
                profile = game.GetSelectedProfile();
            }

            lock (syncRoot)
            {
                if (progressHandler != null)
                {
                    progressHandler("Loading archive...", 0);
                }

                if (!loadArchive(game.CurrentDisc.Path))
                {
                    throw new ExtractException("{0} {1}", Translator.Instance.goodmergearchiveerror, game.CurrentDisc.Path);
                }

                using (extractor)
                {
                    List <IArchiveEntry> entries;
                    if (extractor.Entries == null || (entries = extractor.Entries.Where(e => !e.IsDirectory).ToList()).Count < 1)
                    {
                        Logger.LogError("Goodmerge: Archive '{0}' appears to be empty");
                        throw new ExtractException(Translator.Instance.goodmergeempty);
                    }

                    if (progressHandler != null)
                    {
                        progressHandler("Selecting file...", 0);
                    }
                    IArchiveEntry selectedEntry = selectEntry(entries, game.CurrentDisc.LaunchFile, profile.GetGoodmergeTags());
                    Logger.LogDebug("Goodmerge: Selected entry {0}", selectedEntry.FilePath);

                    string cacheKey = string.Format("{0}****{1}", game.CurrentDisc.Path, selectedEntry.FilePath);
                    string extractionPath;
                    if (isInCache(cacheKey, out extractionPath))
                    {
                        Logger.LogDebug("Goodmerge: Using cached file '{0}'", extractionPath);
                        return(extractionPath);
                    }

                    extractionPath = Path.Combine(GoodmergeTempPath, GOODMERGE_FILENAME_PREFIX + game.Filename);
                    string extractedFile = extractFile(extractor, selectedEntry, extractionPath, progressHandler);
                    if (extractedFile != null)
                    {
                        addToCache(cacheKey, extractedFile);
                    }

                    return(extractedFile);
                }
            }
        }