Beispiel #1
0
        /// <summary>
        /// 解析游戏JVM参数
        /// </summary>
        /// <param name="arguments"></param>
        /// <returns></returns>
        public string ParseJvmArguments(List <object> arguments)
        {
            if (!(arguments?.Any() ?? false))
            {
                return(string.Empty);
            }

            var sb = new StringBuilder();

            foreach (var jvmRule in arguments)
            {
                if (!(jvmRule is JObject))
                {
                    sb.Append($" {jvmRule}");
                    continue;
                }

                var jvmRuleObj = (JObject)jvmRule;
                var flag       = true;
                if (jvmRuleObj.ContainsKey("rules"))
                {
                    foreach (var rule in jvmRuleObj["rules"].Select(r => r.ToObject <JvmRules>()))
                    {
                        if (rule.OperatingSystem.ContainsKey("arch"))
                        {
                            flag = rule.Action.Equals("allow", StringComparison.Ordinal) &&
                                   rule.OperatingSystem["arch"].Equals($"x{SystemInfoHelper.GetSystemArch()}",
                                                                       StringComparison.Ordinal);
                            break;
                        }

                        if (!rule.OperatingSystem.ContainsKey("version"))
                        {
                            flag = rule.Action.Equals("allow", StringComparison.Ordinal) &&
                                   rule.OperatingSystem["name"].Equals("windows", StringComparison.Ordinal);
                        }
                        else
                        {
                            flag = rule.Action.Equals("allow", StringComparison.Ordinal) &&
                                   rule.OperatingSystem["name"].Equals("windows", StringComparison.Ordinal) &&
                                   rule.OperatingSystem["version"].Equals($"^{SystemInfoHelper.GetSystemVersion()}\\.",
                                                                          StringComparison.Ordinal);
                        }
                    }
                }

                if (!flag)
                {
                    continue;
                }

                if (!jvmRuleObj.ContainsKey("value"))
                {
                    continue;
                }

                if (jvmRuleObj["value"].Type == JTokenType.Array)
                {
                    sb.Append(" ");
                    foreach (var arg in jvmRuleObj["value"])
                    {
                        sb.Append(" ").Append(StringHelper.FixArgument(arg.ToString()));
                    }
                }
                else
                {
                    sb.Append($" {StringHelper.FixArgument(jvmRuleObj["value"].ToString())}");
                }
            }

            return(sb.ToString().Trim());
        }