private void PerformLateUpdates() { while (modRegisteredForLateUpdateQueue.Count > 0) { ModUpdateRequest modUpdateRequest = modRegisteredForLateUpdateQueue.Dequeue(); DeactivateMod(modUpdateRequest); DeployModUpdate(modUpdateRequest, Path.Combine(Path.GetTempPath(), modUpdateRequest.packageName + ".zip")); } }
internal void PerformUpdate(ModUpdateRequest modUpdateRequest) { byte a = DeactivateMod(modUpdateRequest); //Backup and deploy if (a == 1) { DeployModUpdate(modUpdateRequest, Path.Combine(Path.GetTempPath(), modUpdateRequest.packageName + ".zip")); } else if (a == 2) { Debug.Log(LOG + "This mod use some files on runtime. This means that the mod will be updated automaticly when you will exit the game."); } }
private byte DeactivateMod(ModUpdateRequest modUpdateRequest) { if (modUpdateRequest.modUseRuntimeRessourceLoading) { /*This is badly coded, but it was a shortcute i took. Basically if a mod is late update, we add it to another queue and * remove the flag so that we we use the perform update on the second queue at game closure, it doesnt block here again*/ modUpdateRequest.modUseRuntimeRessourceLoading = false; modRegisteredForLateUpdateQueue.Enqueue(modUpdateRequest); return(2); } else { try { DirectoryInfo backupFolder = Directory.CreateDirectory(Path.Combine(workingDirectory, BACKUPFOLDER, modUpdateRequest.packageName + '-' + modUpdateRequest.currentVersion.ToString() + "-" + DateTime.Now.Day + "." + DateTime.Now.Month + "." + DateTime.Now.Year + "." + DateTime.Now.Hour + "." + DateTime.Now.Minute + "." + DateTime.Now.Second)); string path = Directory.GetParent(modUpdateRequest.currentDllFileLocation).FullName; Debug.Log(modUpdateRequest.currentDllFileLocation); File.Move(modUpdateRequest.currentDllFileLocation, Path.Combine(backupFolder.FullName, Path.GetFileName(modUpdateRequest.currentDllFileLocation) + ".old")); foreach (string fileLocation in modUpdateRequest.otherFilesLocationRelativeToTheDll) { if (File.Exists(Path.Combine(path, fileLocation))) { Debug.Log(Path.Combine(path, fileLocation)); if (fileLocation.Contains("..")) { throw new Exception("One or multiple files used as ressource by the mod is in a parent folder to its assembly (dll). Hj-UpdaterAPI isnt able (for security reasons) to perform this type of update. Please make the update manually and contact this mod owner so that (s)he know (s)he uses Hj-UpdaterAPI outside of its defined limitations."); } Directory.Move(Path.Combine(path, fileLocation), Path.Combine(backupFolder.FullName, fileLocation + ".old")); } } Debug.Log(LOG + modUpdateRequest.packageName + " has been updated to the latest version."); return(1); } catch (Exception e) { Debug.LogError(LOG + "An error occured during the deactivation process of the following mod : " + modUpdateRequest.packageName + '-' + modUpdateRequest.currentVersion.ToString() + System.Environment.NewLine + "Details : " + e); return(0); } } }
internal static IEnumerator DownloadUpdate(ModUpdateRequest modUpdateRequest, Package pk, Action <ModUpdateRequest> callback) { Debug.Log(LOG + "Downloading package for update..."); UnityWebRequest web = UnityWebRequest.Get(pk.Versions[0].DownloadUrl); yield return(web.SendWebRequest()); if (web.isNetworkError || web.isHttpError) { Debug.LogError(LOG + "Download failed. Skipping this mod update for now."); yield break; } else { bool success = ByteArrayToFile(Path.Combine(Path.GetTempPath(), modUpdateRequest.packageName + ".zip"), web.downloadHandler.data); if (success) { Debug.Log(LOG + "Download complete."); callback(modUpdateRequest); } } }
private IEnumerator StartPerformUpdate(ModUpdateRequest modUpdateRequest, Package pk) { Debug.Log(LOG + "An update for " + modUpdateRequest.packageName + " is available. Current version(" + modUpdateRequest.currentVersion.ToString() + "). Newest version (" + pk.Versions[0].VersionNumber.ToString() + ")."); yield return(ThunderAPI.DownloadUpdate(modUpdateRequest, pk, PerformUpdate)); }
private void DeployModUpdate(ModUpdateRequest modUpdateRequest, string modZipFilePath) { ZipFile.ExtractToDirectory(modZipFilePath, Directory.GetParent(modUpdateRequest.currentDllFileLocation).FullName); }
internal IEnumerator ProcessQueueElement(ModUpdateRequest modUpdateRequest) { Package pk; try { pk = Package.GetPackage(modUpdateRequest.packageName); } catch { yield break; } if ((pk.Versions == null) || pk.Versions.Length <= 0) { Debug.LogWarning(LOG + "Couldnt find versions for the package named '" + modUpdateRequest.packageName + "' in the package list. Update check will not be performed for that mod."); yield break; } else if (modUpdateRequest.currentVersion < pk.Versions[0].VersionNumber) { ModUpdateLog mul = new ModUpdateLog(modUpdateRequest.packageName, modUpdateRequest.currentVersion, pk.Versions[0].VersionNumber); if (ModUpdateLog.checkIfSimilarUpdateAlreadyProceed(mul)) { Debug.LogWarning(LOG + "Similar update already proceed last time. Maybe the modder forgot to change the version number ?"); } else { if (modUpdateRequest.flag.Equals(Flag.UpdateAlways)) { yield return(StartPerformUpdate(modUpdateRequest, pk)); } else if (modUpdateRequest.flag.Equals(Flag.UpdateIfSameDependencyOnlyElseWarnOnly)) { bool sameDependencies; try { sameDependencies = Package.EqualsDependecy(pk, modUpdateRequest.currentVersion); } catch { yield break; } if (!sameDependencies) { Debug.LogWarning(LOG + "An update for " + modUpdateRequest.packageName + " is available. Current version(" + modUpdateRequest.currentVersion.ToString() + "). Newest version (" + pk.Versions[0].VersionNumber.ToString() + ")." + System.Environment.NewLine + "However, the newest version uses a different dependency version. This mod specifie not to update automaticly in that case. Please go to " + pk.PackageUrl + " and update manually."); } else { yield return(StartPerformUpdate(modUpdateRequest, pk)); } } else if (modUpdateRequest.flag.Equals(Flag.UpdateIfSameDependencyOnlyElseWarnAndDeactivate)) { if (Package.EqualsDependecy(pk, modUpdateRequest.currentVersion)) { yield return(StartPerformUpdate(modUpdateRequest, pk)); } else { Debug.LogWarning(LOG + "An update for " + modUpdateRequest.packageName + " is available. Current version(" + modUpdateRequest.currentVersion.ToString() + "). Newest version (" + pk.Versions[0].VersionNumber.ToString() + ")." + System.Environment.NewLine + "However, the newest version uses a different dependency version. This mod specifie not to update automaticly in that case and to deactivate the mod at the next game start. Please go to " + pk.PackageUrl + " and update manually."); DeactivateMod(modUpdateRequest); } } else if (modUpdateRequest.flag.Equals(Flag.WarnOnly)) { Debug.LogWarning(LOG + "An update for " + modUpdateRequest.packageName + " is available. Current version(" + modUpdateRequest.currentVersion.ToString() + "). Newest version (" + pk.Versions[0].VersionNumber.ToString() + ")." + System.Environment.NewLine + "This mod specifie not to update automaticly. Please go to " + pk.PackageUrl + " and update manually."); } else if (modUpdateRequest.flag.Equals(Flag.WarnAndDeactivate)) { Debug.LogWarning(LOG + "An update for " + modUpdateRequest.packageName + " is available. Current version(" + modUpdateRequest.currentVersion.ToString() + "). Newest version (" + pk.Versions[0].VersionNumber.ToString() + ")." + System.Environment.NewLine + "This mod specifie to deactivate the mod when you will close the game. Please go to " + pk.PackageUrl + " and reinstall manually."); DeactivateMod(modUpdateRequest); } } ModUpdateLog.logModUpdate(mul); } else if (pk.IsDeprecated) { Debug.LogWarning(LOG + pk.Name + "Has been flagged as deprecated. This means it doesnt work anymore. The mod will be deactivate when you will close the game except if you specified otherwise in the config file."); if (ConfigPerformDepreactedCheckAndRemove.Value) { DeactivateMod(modUpdateRequest); } } else { Debug.Log(LOG + "The package (mod) named '" + modUpdateRequest.packageName + "' (" + modUpdateRequest.currentVersion.ToString() + ") is up to date."); } }