예제 #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();

            var files = container.GetGameFiles();
            var id    = container.GetGameId();

            bool inventoryFound  = false;
            bool vocabularyFound = false;
            bool volumeFound     = false;
            bool amigaMapFound   = false;

            foreach (string file in files)
            {
                if (string.Compare("object", file, true, CultureInfo.InvariantCulture) == 0)
                {
                    inventoryFound = true;
                    continue;
                }

                if (string.Compare("words.tok", file, true, CultureInfo.InvariantCulture) == 0)
                {
                    vocabularyFound = true;
                    continue;
                }

                if (file.ToLower(CultureInfo.InvariantCulture).EndsWith("vol.0"))
                {
                    volumeFound = true;
                    continue;
                }

                if (string.Compare("dirs", file, true, CultureInfo.InvariantCulture) == 0)
                {
                    amigaMapFound = true;
                    continue;
                }
            }

            if (inventoryFound && vocabularyFound && volumeFound)
            {
                var name        = container.Name;
                var platform    = amigaMapFound ? Platform.Amiga : Platform.PC;
                var interpreter = id.Length > 0 ? InterpreterVersion.V3002149 : InterpreterVersion.V2936;
                var version     = string.Empty;

                result = new GameDetectorResult(name, interpreter, platform, version);
            }

            return(result);
        }
예제 #2
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);
        }
예제 #4
0
        /// <summary>
        /// Search the specified folder for a game.
        /// </summary>
        /// <param name="container">Game container to search.</param>
        /// <returns>Game detection result.</returns>
        public GameDetectorResult Detect(IGameContainer container)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            var result = new GameDetectorResult();

            int i = 0;

            while (!result.Detected && i < this.algorithms.Length)
            {
                result = this.algorithms[i].Detect(container);
                i++;
            }

            return(result);
        }
예제 #5
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);
        }