Exemple #1
0
        /// <summary>
        ///     Converts an AppInfo node to an AppInfo object.
        /// </summary>
        /// <param name="node">
        ///     AppInfo node to parse.
        /// </param>
        /// <returns>
        ///     Returns an AppInfo object if the node was successfully parsed, else it returns null.
        /// </returns>
        private static AppInfo FromNode(AppInfoNode node)
        {
            if (node?.Items == null)
            {
                return(null);
            }

            if (!node.Items.ContainsKey(NodeAppInfo))
            {
                return(null);
            }

            if (node[NodeAppInfo].Items == null || !node[NodeAppInfo].Items.ContainsKey(NodeCommon))
            {
                return(null);
            }

            AppInfoNode dataNode = node[NodeAppInfo][NodeCommon];

            if (dataNode.Items == null || !dataNode.Items.ContainsKey(NodeId))
            {
                return(null);
            }

            string gameIdNode = dataNode[NodeId].Value;

            if (!int.TryParse(gameIdNode, out int appId))
            {
                return(null);
            }

            AppInfo appInfo = new AppInfo(appId);

            if (dataNode.Items.ContainsKey(NodeName))
            {
                appInfo.Name = dataNode[NodeName].Value;
            }

            if (dataNode.Items.ContainsKey(NodeAppType))
            {
                string typeData = dataNode[NodeAppType].Value;
                if (Enum.TryParse(typeData, true, out AppType type))
                {
                    appInfo.AppType = type;
                }
                else
                {
                    Debug.WriteLine(string.Format(CultureInfo.InvariantCulture, "AppInfo: New AppType '{0}'", typeData));
                }
            }

            if (dataNode.Items.ContainsKey(NodePlatforms))
            {
                string osList = dataNode[NodePlatforms].Value;
                if (osList.IndexOf(NodePlatformsWindows, StringComparison.OrdinalIgnoreCase) != -1)
                {
                    appInfo.Platforms |= AppPlatforms.Windows;
                }

                if (osList.IndexOf(NodePlatformsMac, StringComparison.OrdinalIgnoreCase) != -1)
                {
                    appInfo.Platforms |= AppPlatforms.Mac;
                }

                if (osList.IndexOf(NodePlatformsLinux, StringComparison.OrdinalIgnoreCase) != -1)
                {
                    appInfo.Platforms |= AppPlatforms.Linux;
                }
            }

            if (!dataNode.Items.ContainsKey(NodeParentId))
            {
                return(appInfo);
            }

            string parentNode = dataNode[NodeParentId].Value;

            if (int.TryParse(parentNode, out int parentId))
            {
                appInfo.ParentId = parentId;
            }

            return(appInfo);
        }
Exemple #2
0
        public static AppInfo FromNode(AppInfoNode node)
        {
            if (node == null)
            {
                return(null);
            }

            if (!node.Items.ContainsKey("appinfo") || !node["appinfo"].Items.ContainsKey("common") || !node["appinfo"]["common"].Items.ContainsKey("gameid"))
            {
                return(null);
            }

            AppInfoNode dataNode = node["appinfo"]["common"];

            string gameIdNode = dataNode["gameid"].Value;

            if (!int.TryParse(gameIdNode, out int appId))
            {
                return(null);
            }

            AppInfo appInfo = new AppInfo(appId);

            if (dataNode.Items.ContainsKey("name"))
            {
                appInfo.Name = dataNode["name"].Value;
            }

            if (dataNode.Items.ContainsKey("type"))
            {
                string typeData = dataNode["type"].Value;
                if (Enum.TryParse(typeData, true, out AppType type))
                {
                    appInfo.AppType = type;
                }
                else
                {
                    SentryLogger.Log(new DataException(string.Format(CultureInfo.InvariantCulture, "New AppType '{0}'", typeData)));
                }
            }

            if (dataNode.Items.ContainsKey("oslist"))
            {
                string osList = dataNode["oslist"].Value;
                if (osList.IndexOf("windows", StringComparison.OrdinalIgnoreCase) != -1)
                {
                    appInfo.Platforms |= AppPlatforms.Windows;
                }

                if (osList.IndexOf("mac", StringComparison.OrdinalIgnoreCase) != -1)
                {
                    appInfo.Platforms |= AppPlatforms.Mac;
                }

                if (osList.IndexOf("linux", StringComparison.OrdinalIgnoreCase) != -1)
                {
                    appInfo.Platforms |= AppPlatforms.Linux;
                }
            }

            if (!dataNode.Items.ContainsKey("parent"))
            {
                return(appInfo);
            }

            string parentNode = dataNode["parent"].Value;

            if (int.TryParse(parentNode, out int parentId))
            {
                appInfo.ParentId = parentId;
            }

            return(appInfo);
        }