Esempio n. 1
0
        /// <summary>
        /// Detect a game in the specified folder.
        /// </summary>
        /// <param name="container">Game container.</param>
        /// <returns>Detection result.</returns>
        GameDetectorResult IGameDetectorAlgorithm.Detect(IGameContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            var result = new GameDetectorResult();

            const string GameInfoExtension = ".agigame";

            var files = container.GetFilesByExtension(GameInfoExtension);

            if (files.Length > 0)
            {
                try
                {
                    // Example .agigame file contents:
                    //
                    // <?xml version="1.0" encoding="utf-8" ?>
                    // <game name="The Black Cauldron"
                    //  platform="PC"
                    //  date="XXXX-XX-XX"
                    //  version="2.00"
                    //  format="FLOPPY"
                    //  interpreter="2.439"
                    //  language="English"/>
                    var doc = new XmlDocument();
                    doc.Load(files[0]);

                    var node = doc.SelectSingleNode("game");
                    if (node != null)
                    {
                        var name        = node.Attributes["name"].Value;
                        var platform    = node.Attributes["platform"].Value;
                        var interpreter = node.Attributes["interpreter"].Value;
                        var version     = node.Attributes["version"].Value;

                        result = new GameDetectorResult(name, GameInfoParser.ParseInterpreterVersion(interpreter), GameInfoParser.ParsePlatform(platform), version);
                    }
                }
                catch (XmlException)
                {
                }
            }

            return(result);
        }
        /// <summary>
        /// Detect a game in the specified folder.
        /// </summary>
        /// <param name="container">Game container.</param>
        /// <returns>Detection result.</returns>
        GameDetectorResult IGameDetectorAlgorithm.Detect(IGameContainer container)
        {
            var result = new GameDetectorResult();

            // Look in the current directory for all game files
            var files = Database.GetFolderGameFiles(container);

            if (files.Count > 0)
            {
                // Find a game match
                var match = this.database.FindMatch(files);
                if (match != null)
                {
                    result = new GameDetectorResult(match.Name, GameInfoParser.ParseInterpreterVersion(match.Interpreter), GameInfoParser.ParsePlatform(match.Platform), match.Version);
                }
            }

            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Detect a game in the specified folder.
        /// </summary>
        /// <param name="container">Game container.</param>
        /// <returns>Detection result.</returns>
        GameDetectorResult IGameDetectorAlgorithm.Detect(IGameContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            var result = new GameDetectorResult();

            const string GameInfoExtension = ".wag";

            var files = container.GetFilesByExtension(GameInfoExtension);

            if (files.Length > 0)
            {
                try
                {
                    var id          = new StringBuilder();
                    var description = new StringBuilder();
                    var interpreter = new StringBuilder();
                    var version     = new StringBuilder();

                    // Last 16 bytes are not stored as properties, it's the
                    // WinAGI version string. Ex: "PMWINAGI v1.0"
                    var data  = container.Read(files[0]);
                    var index = 0;
                    while (index < (data.Length - 16))
                    {
                        byte code = data[index++];
                        index++; // type - not used
                        index++; // num - not used
                        int size = data[index++] + (data[index++] * 256);

                        switch (code)
                        {
                        case 129:
                            // game description
                            for (int i = 0; i < size; i++)
                            {
                                description.Append((char)data[index + i]);
                            }

                            break;

                        case 131:
                            // game id
                            for (int i = 0; i < size; i++)
                            {
                                id.Append((char)data[index + i]);
                            }

                            break;

                        case 132:
                            // interpreter
                            for (int i = 0; i < size; i++)
                            {
                                interpreter.Append((char)data[index + i]);
                            }

                            break;

                        case 134:
                            // game version
                            for (int i = 0; i < size; i++)
                            {
                                version.Append((char)data[index + i]);
                            }

                            break;
                        }

                        index += size;
                    }

                    var name     = description.Length > 0 ? description.ToString() : id.ToString();
                    var platform = Platform.PC;

                    result = new GameDetectorResult(name, GameInfoParser.ParseInterpreterVersion(interpreter.ToString()), platform, version.ToString());
                }
                catch (IOException)
                {
                }
                catch (ArgumentOutOfRangeException)
                {
                }
            }

            return(result);
        }