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()); }
public static MLibrary[] ParseJson(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(name, nativeId, lObj)); } } // COMMON library if (artifact != null) { var obj = createMLibrary(name, "", (JObject)artifact); list.Add(obj); } // library if (classifiers == null && artifact == null) { var obj = createMLibrary(name, "", item); list.Add(obj); } } catch { } } return(list.ToArray()); }
public static MLibrary[] ParseJson(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 library if (item["downloads"] == null) { bool isn = item["natives"]?["windows"] != null; var nativeStr = ""; if (isn) { nativeStr = item["natives"]["windows"].ToString(); } if (name == null) { continue; } list.Add(createMLibrary(name, nativeStr, item)); continue; } // NATIVE library var classif = item["downloads"]["classifiers"]; if (classif != null) { JObject job = null; bool isgo = true; var nativeId = ""; if (classif["natives-windows-64"] != null && Environment.Is64BitOperatingSystem) { nativeId = "natives-windows-64"; } else if (classif["natives-windows-32"] != null) { nativeId = "natives-windows-32"; } else if (classif["natives-windows"] != null) { nativeId = "natives-windows"; } else { isgo = false; } job = (JObject)classif[nativeId]; if (isgo) { var obj = createMLibrary(name, nativeId, job); list.Add(obj); } } // COMMON library var arti = item["downloads"]["artifact"]; if (arti != null) { var job = (JObject)arti; var obj = createMLibrary(name, "", job); list.Add(obj); } } catch { } } return(list.ToArray()); }