//////////////// public void CheckVersion(string modName, BasicModInfo modInfo, UIList modsUiModList, Version modVersion) { //LogHelpers.Log( "modInfo.Count:"+modInfo.Count+ ", name:"+name+", vers:"+vers); if (modInfo.Version == modVersion) { return; } UIPanel uiModItem = null; foreach (UIElement modItem in modsUiModList._items) { object mod; TmodFile modFile; if (!ReflectionHelpers.Get(modItem, "_mod", out mod) || mod == null) { LogHelpers.Warn("Could not get mod for version check from mod list item " + modItem.ToString()); continue; } if (!ReflectionHelpers.Get(mod, "modFile", out modFile) || modFile == null) { LogHelpers.Warn("Could not get mod file for version check from mod " + mod.ToString() + "'s list item " + modItem.ToString()); continue; } if (modFile.name == modName) { uiModItem = (UIPanel)modItem; break; } } if (uiModItem != null) { Version newModVersion = modInfo.Version; string msg = newModVersion.ToString() + " On Mod Browser"; //LogHelpers.Log( " name: "+name+", uiModItem: " + uiModItem.GetOuterDimensions().ToRectangle() ); var txt = new UIText(msg, 0.8f, true); txt.Top.Set(24f, 0f); txt.Left.Set(-184f, 0.5f); if (newModVersion > modVersion) { txt.TextColor = Color.Gold; } else { txt.SetText(msg, 0.6f, true); txt.TextColor = Color.Gray; } uiModItem.Append(txt); uiModItem.Recalculate(); uiModItem.Parent?.Recalculate(); uiModItem.Parent?.Parent?.Recalculate(); uiModItem.Parent?.Parent?.Parent?.Recalculate(); } }
private static void RegisterBadMods(ModInfoListLoadHookArguments modInfoArgs, BadModsDatabase badMods) { foreach (var kv in modInfoArgs.ModInfo) { string modName = kv.Key; BasicModInfo modInfo = kv.Value; modInfo.IsBadMod = badMods.ContainsKey(modName); } }
private static bool HandleModInfoReceipt(string jsonStr, out BasicModInfoDatabase modInfoDb) { modInfoDb = new BasicModInfoDatabase(); JObject respJson = JObject.Parse(jsonStr); if (respJson.Count == 0) { return(false); } IEnumerable <JToken> modList; string modlistCompressed = (string)respJson["modlist_compressed"]; // From tModLoader's code: if (modlistCompressed != null) { byte[] data = Convert.FromBase64String(modlistCompressed); var memStream = new MemoryStream(data); using (var zip = new GZipStream(memStream, CompressionMode.Decompress)) { using (var reader = new StreamReader(zip)) { modList = JArray.Parse(reader.ReadToEnd()); } } } else { // Fallback if needed. modList = (JArray)respJson["modlist"]; } /*JToken modListToken = respJson.SelectToken( "modlist_compressed" ); * if( modListToken == null ) { * throw new NullReferenceException( "No modlist" ); * } * * JToken[] modList = modListToken.ToArray();*/ foreach (JToken modEntry in modList) { JToken modNameToken = modEntry.SelectToken("name"); JToken modDisplaynameToken = modEntry.SelectToken("displayname"); JToken modAuthorToken = modEntry.SelectToken("author"); JToken modVersRawToken = modEntry.SelectToken("version"); //JToken modDescRawToken = modEntry.SelectToken( "hasdescription" ); //JToken modHomepageRawToken = modEntry.SelectToken( "homepage" ); if (modNameToken == null || modVersRawToken == null || modDisplaynameToken == null || modAuthorToken == null /*|| hasDescRawToken == null || modHomepageRawToken == null*/) { continue; } string modName = modNameToken.ToObject <string>(); string modDisplayName = modDisplaynameToken.ToObject <string>(); string modVersRaw = modVersRawToken.ToObject <string>(); //string modDesc = modDescRawToken?.ToObject<string>() ?? null; //string modHomepage = modHomepageRawToken.ToObject<string>(); Version modVers = Version.Parse(modVersRaw.Substring(1)); IEnumerable <string> modAuthors = modAuthorToken.ToObject <string>() .Split(',') .SafeSelect(a => a.Trim()); modInfoDb[modName] = new BasicModInfo(modDisplayName, modAuthors, modVers, null, null); //modDesc, modHomepage } return(true); }