/// <summary> /// Enable all dependencies for this package, and optionally download and install them if missing. /// </summary> /// <param name="forceInstall">If true, will download and install missing dependencies.</param> /// <returns><see langword="true"/> if successful, otherwise <see langword="false"/>.</returns> public bool TryEnableAllDependencies(bool forceInstall) { bool ret = true; if (this.dependencies != null && this.dependencies.Any()) { foreach (var dep in this.dependencies) { var pkg = LocalPackageManager.TryGetInstalledPackage(dep); if (pkg == null) { if (!forceInstall) { return(false); } else if (!LocalPackageManager.TryInstallWebPackage(dep, true)) { Console.WriteLine("LPM.TryInstallWebPackage return false?"); return(false); } } else if (pkg.IsDisabled && !LocalPackageManager.TryEnablePackage(dep)) { return(false); } } } return(ret); }
/// <summary> /// Process an actual PackageManifest result, either from a list or just a standalone one. /// </summary> internal static void ProcessManifest(PackageManifest manifest, string hostUsername, string repoName) { if (manifest == null) { return; } if (string.IsNullOrEmpty(manifest.author) || !string.Equals(hostUsername, manifest.author, StringComparison.OrdinalIgnoreCase)) { manifest.author = hostUsername; } manifest.repository = repoName; var state = GetStateForGuid(manifest.GUID); if (state == GuidFilterState.Blacklist) { return; } if (state == GuidFilterState.BrokenList) { manifest.m_installState = InstallState.NotWorking; } if (s_webManifests.ContainsKey(manifest.GUID)) { Console.WriteLine("Duplicate web manifests found! Skipping this one: " + manifest.GUID); return; } s_webManifests.Add(manifest.GUID, manifest); if (LocalPackageManager.TryGetInstalledPackage(manifest.GUID) is PackageManifest installed) { if (installed.version == manifest.version) { // Same version, but manifest may have been updated. // Ensure the local manifest matches the web one. var path = installed.IsDisabled ? Folders.MEFINO_DISABLED_FOLDER : Folders.OUTWARD_PLUGINS; path += $@"\{installed.GUID}\{LocalPackageManager.PKG_MANIFEST_FILENAME}"; if (File.Exists(path)) { File.Delete(path); } File.WriteAllText(path, manifest.ToJsonObject().ToString(true)); //LocalPackageManager.RefreshInstalledPackages(); } else { installed.m_installState = installed.CompareVersionAgainst(manifest); } } }
/// <summary> /// Disable all packages which depend on this package. /// </summary> /// <returns><see langword="true"/> if successful, otherwise <see langword="false"/>.</returns> public void TryDisableAllDependencies() { var packages = GetCurrentlyEnabledDependantPackages(); foreach (var pkg in packages) { LocalPackageManager.TryDisablePackage(pkg, true); } }
/// <summary> /// Try to disable all enabled conflicts with this package (all GUIDs inside this <see cref="conflicts_with"/> list). /// </summary> /// <returns><see langword="true"/> if successful, otherwise <see langword="false"/></returns> public bool TryDisableAllConflicts() { bool ret = true; if (this.conflicts_with != null && this.conflicts_with.Any()) { foreach (var guid in this.conflicts_with) { if (LocalPackageManager.s_enabledPackages.ContainsKey(guid)) { if (!LocalPackageManager.TryDisablePackage(guid, true)) { return(false); } } } } return(ret); }
/// <summary> /// Verify packages and try to launch Outward. /// </summary> /// <returns><see langword="true"/> if successful, otherwise <see langword="false"/></returns> public static bool TryLaunchOutward() { if (IsOutwardRunning()) { MessageBox.Show("Outward is already running!"); return(false); } if (!Folders.IsCurrentOutwardPathValid()) { return(false); } if (!LocalPackageManager.RefreshInstalledPackages()) { var result = MessageBox.Show($"Some enabled packages are not Ready. Fix them and launch?", $"Warning", MessageBoxButtons.OKCancel); if (result == DialogResult.Cancel) { return(false); } for (int i = LocalPackageManager.s_enabledPackages.Count - 1; i >= 0; i--) { var entry = LocalPackageManager.s_enabledPackages.ElementAt(i); if (entry.Value.m_installState != InstallState.Outdated) { continue; } if (!LocalPackageManager.TryUpdatePackage(entry.Key)) { return(false); } } // update package states LocalPackageManager.RefreshInstalledPackages(true); // Pass 1: enable missing dependencies. for (int i = LocalPackageManager.s_enabledPackages.Count - 1; i >= 0; i--) { var entry = LocalPackageManager.s_enabledPackages.ElementAt(i); if (entry.Value.m_installState != InstallState.MissingDependency) { continue; } if (!entry.Value.TryEnableAllDependencies(true)) { return(false); } } // update package states LocalPackageManager.RefreshInstalledPackages(true); // Pass 2: disable packages WITH conflicts for (int i = LocalPackageManager.s_enabledPackages.Count - 1; i >= 0; i--) { var entry = LocalPackageManager.s_enabledPackages.ElementAt(i); if (entry.Value.m_installState != InstallState.HasConflict) { continue; } if (!LocalPackageManager.TryDisablePackage(entry.Key, true)) { return(false); } } } try { if (Folders.OUTWARD_FOLDER.Contains(Path.Combine("Steam", "steamapps", "common", "Outward"))) { Process.Start($"steam://rungameid/794260"); } else { Process.Start(Path.Combine(Folders.OUTWARD_FOLDER, "Outward.exe")); } } catch (Exception ex) { MessageBox.Show($"Error launching Outward:\n\n{ex}", "Error!", MessageBoxButtons.OK); } return(false); }
/// <summary> /// Try to uninstall this package. /// </summary> public bool TryUninstall() { return(LocalPackageManager.TryUninstallPackage(this)); }
/// <summary> /// Try to install this package and optionally enable it. /// </summary> public bool TryInstall(bool andEnable) { return(LocalPackageManager.TryInstallWebPackage(this.GUID, andEnable)); }
/// <summary> /// Try to disable this package. /// </summary> public bool TryDisable(bool skipWarnings = false) { return(LocalPackageManager.TryDisablePackage(this.GUID, skipWarnings)); }
///// <summary> ///// Check if the version of this package instance is greater than the version of the other package instance, or optionally check if equal version. ///// </summary> ///// <param name="other">The other package to check against, presumably the same GUID.</param> ///// <param name="greaterOrEqual">Allow equal to return true?</param> ///// <returns><see langword="true"/> if this version is greater than the other package (or equal when <paramref name="greaterOrEqual"/> is <see langword="true"/>), ///// otherwise <see langword="false"/>.</returns> //public bool IsGreaterVersionThan(PackageManifest other, bool greaterOrEqual = false) //{ // Version otherVersion; // try // { // otherVersion = new Version(other.version); // } // catch { return true; } // Version thisVersion; // try // { // thisVersion = new Version(this.version); // } // catch { return false; } // return greaterOrEqual // ? thisVersion >= otherVersion // : thisVersion > otherVersion; //} /// <summary> /// Try to enable this package, and optionally all dependencies too. /// </summary> public bool TryEnable(bool tryEnableDependencies = true) { return(LocalPackageManager.TryEnablePackage(this.GUID, tryEnableDependencies)); }