예제 #1
0
        /// <summary>
        /// 获取Natives与Libraries(核心依赖)列表
        /// </summary>
        /// <param name="libraries"></param>
        /// <returns>二元组(包含一组list,T1是Natives列表,T2是Libraries列表)</returns>
        private protected override Tuple <List <NativeFileInfo>, List <FileInfo> > GetNatives(IEnumerable <Library> libraries)
        {
            var result = new Tuple <List <NativeFileInfo>, List <FileInfo> >(new List <NativeFileInfo>(), new List <FileInfo>());

            foreach (var lib in libraries)
            {
                if (!lib.ClientRequired)
                {
                    continue;
                }
                if (!lib.Rules.CheckAllow())
                {
                    continue;
                }

                if (lib.Downloads == null)
                {
                    var mavenInfo   = lib.Name.ResolveMavenString();
                    var downloadUrl = string.IsNullOrEmpty(lib.Url)
                        ? mavenInfo.OrganizationName.Equals("net.minecraftforge", StringComparison.Ordinal)
                            ? "https://files.minecraftforge.net/maven/"
                            : "https://libraries.minecraft.net/"
                        : lib.Url;

                    result.Item2.Add(new FileInfo
                    {
                        Name = lib.Name,
                        Path = mavenInfo.Path,
                        Url  = $"{downloadUrl}{mavenInfo.Path}"
                    });
                    continue;
                }

                if (lib.Downloads?.Artifact != null)
                {
                    if (lib.Downloads.Artifact.Name == null)
                    {
                        lib.Downloads.Artifact.Name = lib.Name;
                        result.Item2.Add(lib.Downloads.Artifact);
                    }
                }
                else
                {
                    if (!(lib.Natives?.Any() ?? false))
                    {
                        result.Item2.Add(new FileInfo
                        {
                            Name = lib.Name
                        });
                        continue;
                    }
                }

                if (!(lib.Natives?.Any() ?? false))
                {
                    continue;
                }
                if (lib.Downloads.Classifiers == null)
                {
                    continue;
                }

                var key = lib.Natives.ContainsKey("windows")
                    ? lib.Natives["windows"].Replace("${arch}", SystemInfoHelper.GetSystemArch())
                    : "natives-windows";

                if (lib.Downloads.Classifiers.ContainsKey(key))
                {
                    lib.Downloads.Classifiers[key].Name = lib.Name;
                }

                result.Item1.Add(new NativeFileInfo
                {
                    Extract  = lib.Extract,
                    FileInfo = lib.Downloads.Classifiers[key]
                });
            }

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