/// <summary> /// Parses the JSON file and looks up the version for the specified mod. /// </summary> /// <param name="mod">The mod's static ID.</param> /// <param name="versions">The data from the web JSON file.</param> /// <returns>The results of the update, or null if the mod could not be found in the /// JSON.</returns> private ModVersionCheckResults ParseModVersion(Mod mod, ModVersions versions) { ModVersionCheckResults result = null; string id = mod.staticID; if (versions.mods != null) { foreach (var modVersion in versions.mods) { if (modVersion != null && modVersion.staticID == id) { string newVersion = modVersion.version?.Trim(); if (string.IsNullOrEmpty(newVersion)) { result = new ModVersionCheckResults(id, true); } else { result = new ModVersionCheckResults(id, newVersion != PVersionCheck.GetCurrentVersion(mod), newVersion); } break; } } } return(result); }
public override void Initialize(Harmony plibInstance) { Instance = this; plibInstance.Patch(typeof(MainMenu), "OnSpawn", postfix: PatchMethod(nameof( MainMenu_OnSpawn_Postfix))); plibInstance.Patch(typeof(ModsScreen), "BuildDisplay", postfix: PatchMethod( nameof(ModsScreen_BuildDisplay_Postfix))); }
internal AllVersionCheckTask(IEnumerable <PForwardedComponent> allMods, PVersionCheck parent) { if (allMods == null) { throw new ArgumentNullException(nameof(allMods)); } checkAllVersions = new List <PForwardedComponent>(allMods); index = 0; this.parent = parent ?? throw new ArgumentNullException(nameof(parent)); }
/// <summary> /// When a web request completes, triggers the handler for the next updater. /// </summary> /// <param name="request">The YAML web request data.</param> /// <param name="mod">The mod that needs to be checked.</param> private void OnRequestFinished(UnityWebRequest request, Mod mod) { ModVersionCheckResults result = null; if (request.result == UnityWebRequest.Result.Success) { // Parse the text var modInfo = YamlIO.Parse <Mod.PackagedModInfo>(request.downloadHandler. text, default); string newVersion = modInfo?.version; if (modInfo != null && !string.IsNullOrEmpty(newVersion)) { string curVersion = PVersionCheck.GetCurrentVersion(mod); #if DEBUG PUtil.LogDebug("Current version: {0} New YAML version: {1}".F( curVersion, newVersion)); #endif result = new ModVersionCheckResults(mod.staticID, newVersion != curVersion, newVersion); } } request.Dispose(); OnVersionCheckCompleted?.Invoke(result); }