/// <summary> /// Removes a package from the Package Manager. /// </summary> /// <param name="package">A string representing the package to be removed.</param> public static async void RemovePackage(string package) { if (EditorApplication.isPlayingOrWillChangePlaymode == false) { if (IsPackageLoaded(package)) { RemoveRequest removeRequest = Client.Remove(package); Debug.Log($"Removing {package}."); while (removeRequest.IsCompleted == false) { await Task.Delay(100); } if (removeRequest.Status >= StatusCode.Failure) { Debug.LogError($"There was an error trying to enable '{package}' - Error Code: [{removeRequest.Error.errorCode}] .\n{removeRequest.Error.message}"); } else { OnPackageDisabled?.Invoke(null, new PackageDisabledEventArgs(removeRequest.PackageIdOrName)); Debug.Log($"The package '{removeRequest.PackageIdOrName} has been removed"); } } } }
/// <summary> /// Try to disable the package. This will disable dependant packages as well. /// </summary> /// <param name="skipDependencyWarning">Skip the user prompt and just automatically disable all dependants?</param> /// <returns><see langword="true"/> if successful, otherwise <see langword="false"/></returns> public static bool TryDisablePackage(string guid, bool skipDependencyWarning = false) { if (OutwardHelper.IsOutwardRunning()) { MessageBox.Show("You need to close Outward to do that."); return(false); } var package = TryGetInstalledPackage(guid); if (package == null) { return(true); } if (s_disabledPackages.ContainsKey(guid)) { OnPackageDisabled.Invoke(package); //Console.WriteLine("Package '" + guid + "' is already disabled!"); return(true); } if (!skipDependencyWarning) { if (!PreRemovalDependencyCheck(package, true)) { return(false); } } else { package.TryDisableAllDependencies(); } string toDir = Folders.MEFINO_DISABLED_FOLDER + $@"\{package.GUID}"; string fromDir = Folders.OUTWARD_PLUGINS + $@"\{package.GUID}"; if (IOHelper.TryMoveDirectory(fromDir, toDir)) { ////Console.WriteLine("Disable package: " + guid); //s_enabledPackages.Remove(guid); //s_disabledPackages.Add(guid, package); RefreshInstalledPackages(); OnPackageDisabled.Invoke(package); return(true); } return(false); }