Пример #1
0
        static string[] argParse(JArray arr)
        {
            var strList     = new List <string>(arr.Count);
            var ruleChecker = new MRule();

            foreach (var item in arr)
            {
                if (item is JObject)
                {
                    bool allow = true;

                    if (item["rules"] != null)
                    {
                        allow = ruleChecker.CheckOSRequire((JArray)item["rules"]);
                    }

                    var value = item["value"] ?? item["values"];

                    if (allow && value != null)
                    {
                        if (value is JArray)
                        {
                            foreach (var str in value)
                            {
                                strList.Add(str.ToString());
                            }
                        }
                        else
                        {
                            strList.Add(value.ToString());
                        }
                    }
                }
                else
                {
                    strList.Add(item.ToString());
                }
            }

            return(strList.ToArray());
        }
Пример #2
0
            public static MLibrary[] ParseJson(string libraryPath, JArray json)
            {
                var ruleChecker = new MRule();
                var list        = new List <MLibrary>(json.Count);

                foreach (JObject item in json)
                {
                    try
                    {
                        var name = item["name"]?.ToString();

                        // check rules array
                        var rules = item["rules"];
                        if (CheckOSRules && rules != null)
                        {
                            var isRequire = ruleChecker.CheckOSRequire((JArray)rules);

                            if (!isRequire)
                            {
                                continue;
                            }
                        }

                        // forge clientreq
                        var req = item["clientreq"]?.ToString();
                        if (req != null && req.ToLower() != "true")
                        {
                            continue;
                        }

                        // support TLauncher
                        var artifact    = item["artifact"] ?? item["downloads"]?["artifact"];
                        var classifiers = item["classifies"] ?? item["downloads"]?["classifiers"];
                        var natives     = item["natives"];

                        // NATIVE library
                        if (classifiers != null)
                        {
                            var nativeId = "";

                            if (natives != null)
                            {
                                nativeId = natives[MRule.OSName]?.ToString();
                            }

                            if (nativeId != null && classifiers[nativeId] != null)
                            {
                                nativeId = nativeId.Replace("${arch}", MRule.Arch);
                                var lObj = (JObject)classifiers[nativeId];
                                list.Add(createMLibrary(libraryPath, name, nativeId, lObj));
                            }
                        }

                        // COMMON library
                        if (artifact != null)
                        {
                            var obj = createMLibrary(libraryPath, name, "", (JObject)artifact);
                            list.Add(obj);
                        }

                        // library
                        if (classifiers == null && artifact == null)
                        {
                            var obj = createMLibrary(libraryPath, name, "", item);
                            list.Add(obj);
                        }
                    }
                    catch { }
                }

                return(list.ToArray());
            }