Ejemplo n.º 1
0
        /// <summary>
        /// Find a game in the database that matches the file set and checksums.
        /// </summary>
        /// <param name="files">File set.</param>
        /// <returns>Matched game, or null if no match.</returns>
        internal Game FindMatch(GameFileCollection files)
        {
            if (files == null)
            {
                throw new ArgumentNullException(nameof(files));
            }

            // If there are no game data files, then don't return a match
            if (files.Count == 0)
            {
                return(null);
            }

            // Look at each game data for a match
            foreach (var curGame in this.Games)
            {
                // Check if the number of files match
                if (curGame.Files.Count == files.Count)
                {
                    // Assume it's a match, we'll set it to false if any crc doesn't match
                    bool match = true;

                    // Check each crc, they have to all match
                    foreach (GameFile curCrc in curGame.Files)
                    {
                        // Check this crc
                        GameFile crc = files[curCrc.Name];
                        if (crc == null)
                        {
                            // Filename not found, continue with next game
                            match = false;
                            break;
                        }

                        if (crc.Sha1.Length > 0 && curCrc.Sha1.Length > 0)
                        {
                            if (crc.Sha1 != curCrc.Sha1)
                            {
                                // Checksum for this file doesn't match, continue with next game
                                match = false;
                                break;
                            }
                        }
                        else
                        {
                            match = false;
                            break;
                        }
                    }

                    // All crcs match for this game, so this is it
                    if (match)
                    {
                        return(curGame);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get all the files in the specified container that are game data files and calculate
        /// the crc for them.
        /// </summary>
        /// <param name="container">Game container.</param>
        /// <returns>List of files.</returns>
        internal static GameFileCollection GetFolderGameFiles(IGameContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            string[] gameFiles = container.GetGameFiles();

            // Calculate the checksum for each game file
            GameFileCollection crcs = new GameFileCollection();

            foreach (string file in gameFiles)
            {
                GameFile crc = GameFile.FromFile(container, file);
                crcs.Add(crc);
            }

            return(crcs);
        }