Exemplo n.º 1
0
        private static Game[] LoadGames(XmlReader reader)
        {
            var games = new List <Game>();

            reader.ReadStartElement("games");

            while (reader.Name == "game")
            {
                var game = new Game
                {
                    Name        = reader.GetAttribute("name", string.Empty),
                    Interpreter = reader.GetAttribute("interpreter", string.Empty),
                    Platform    = reader.GetAttribute("platform", string.Empty),
                    Version     = reader.GetAttribute("version", string.Empty),
                };

                reader.ReadStartElement("game");

                // Files
                while (reader.Name == "file")
                {
                    var file = new GameFile
                    {
                        Name = reader.GetAttribute("name", string.Empty),
                        Sha1 = reader.GetAttribute("sha1", string.Empty),
                    };

                    game.Files.Add(file);

                    if (reader.IsEmptyElement)
                    {
                        reader.Read();
                    }
                    else
                    {
                        reader.ReadStartElement("file");
                        reader.ReadEndElement();
                    }
                }

                games.Add(game);

                reader.ReadEndElement();
            }

            reader.ReadEndElement();

            return(games.ToArray());
        }
Exemplo 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);
        }