Exemplo n.º 1
0
        /// <summary>
        /// Try to uninstall the package.
        /// </summary>
        /// <returns><see langword="true"/> if successful, otherwise <see langword="false"/></returns>
        internal static bool TryUninstallPackage(PackageManifest package)
        {
            if (OutwardHelper.IsOutwardRunning())
            {
                MessageBox.Show("You need to close Outward to do that.");
                return(false);
            }

            string dir;
            Dictionary <string, PackageManifest> dict;

            if (!package.IsDisabled)
            {
                dir  = Folders.OUTWARD_PLUGINS + $@"\{package.GUID}";
                dict = s_enabledPackages;
            }
            else
            {
                dir  = Folders.MEFINO_DISABLED_FOLDER + $@"\{package.GUID}";
                dict = s_disabledPackages;
            }

            if (PreRemovalDependencyCheck(package, false))
            {
                if (IOHelper.TryDeleteDirectory(dir))
                {
                    dict.Remove(package.GUID);

                    OnPackageUninstalled?.Invoke(package);
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Attempt to update the provided package to a newer version, if any is available.
        /// </summary>
        /// <param name="guid">The guid to try to update.</param>
        /// <returns><see langword="true"/> if successful, otherwise <see langword="false"/></returns>
        public static bool TryUpdatePackage(string guid)
        {
            if (OutwardHelper.IsOutwardRunning())
            {
                MessageBox.Show("You need to close Outward to do that.");
                return(false);
            }

            var installed = TryGetInstalledPackage(guid);

            if (installed == null)
            {
                return(false);
            }

            if (!WebManifestManager.s_webManifests.TryGetValue(guid, out PackageManifest webManifest))
            {
                return(false);
            }

            if (installed.CompareVersionAgainst(webManifest) != InstallState.Outdated)
            {
                return(true);
            }

            //if (installed.IsGreaterVersionThan(webManifest))
            //    return true;

            string dir = installed.IsDisabled
                            ? Folders.MEFINO_DISABLED_FOLDER
                            : Folders.OUTWARD_PLUGINS;

            dir = Path.Combine(dir, installed.GUID);

            if (!IOHelper.TryDeleteDirectory(dir))
            {
                return(false);
            }

            if (s_enabledPackages.ContainsKey(guid))
            {
                s_enabledPackages.Remove(guid);
            }
            else
            {
                s_disabledPackages.Remove(guid);
            }

            return(TryInstallWebPackage(webManifest.GUID, !installed.IsDisabled));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Try to enable the package GUID.
        /// If this GUID is not installed or this method fails it will return false,
        /// otherwise it will return true and enable/install all dependencies.
        /// </summary>
        /// <param name="guid">The guid to try to enable</param>
        /// <param name="tryEnableDependencies">If any dependencies are disabled, should we try to automatically install/enable them?</param>
        /// <returns><see langword="true"/> if successful, otherwise <see langword="false"/></returns>
        public static bool TryEnablePackage(string guid, bool tryEnableDependencies = true)
        {
            if (OutwardHelper.IsOutwardRunning())
            {
                MessageBox.Show("You need to close Outward to do that.");
                return(false);
            }

            var package = TryGetInstalledPackage(guid);

            if (package == null)
            {
                return(false);
            }

            if (!PreEnableConflictCheck(package))
            {
                //Console.WriteLine("PreEnableConflictCheck returned false");
                return(false);
            }

            if (!package.AreAllDependenciesEnabled(out List <string> missing))
            {
                if (!tryEnableDependencies || !PreEnableDependencyCheck(package, missing))
                {
                    return(false);
                }
            }

            if (s_enabledPackages.ContainsKey(guid))
            {
                OnPackageEnabled?.Invoke(package);
                return(true);
            }

            string toDir   = Folders.OUTWARD_PLUGINS + $@"\{package.GUID}";
            string fromDir = Folders.MEFINO_DISABLED_FOLDER + $@"\{package.GUID}";

            if (IOHelper.TryMoveDirectory(fromDir, toDir))
            {
                RefreshInstalledPackages();

                OnPackageEnabled?.Invoke(package);

                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Disable ALL packages.
        /// </summary>
        /// <returns><see langword="true"/> if successful, otherwise <see langword="false"/></returns>
        public static bool DisableAllPackages()
        {
            if (OutwardHelper.IsOutwardRunning())
            {
                MessageBox.Show("You need to close Outward to do that.");
                return(false);
            }

            bool ret = true;

            for (int i = s_enabledPackages.Count - 1; i >= 0; i--)
            {
                if (!s_enabledPackages.Any())
                {
                    break;
                }

                var pkg = s_enabledPackages.ElementAt(i);
                ret &= TryDisablePackage(pkg.Key, true);
            }
            return(ret);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Attempt to install a GUID from a GitHub web package, if such a package can be found.
        /// </summary>
        /// <param name="guid">The guid to try to install.</param>
        /// <param name="andEnable">Should the package be enabled after installing? Otherwise it will be disabled.</param>
        /// <returns><see langword="true"/> if successful, otherwise <see langword="false"/></returns>
        public static bool TryInstallWebPackage(string guid, bool andEnable = true)
        {
            if (OutwardHelper.IsOutwardRunning())
            {
                MessageBox.Show("You need to close Outward to do that.");
                return(false);
            }

            if (!Folders.IsCurrentOutwardPathValid())
            {
                Console.WriteLine("Outward folder is not set! Cannot install package.");
                return(false);
            }

            WebManifestManager.s_webManifests.TryGetValue(guid, out PackageManifest webManifest);

            if (webManifest == null)
            {
                if (!string.IsNullOrEmpty(guid) && TryGetInstalledPackage(guid) != null)
                {
                    Console.WriteLine("Could not find online package by GUID '" + guid + ", but an installed package exists with that GUID, enabling.");
                    TryEnablePackage(guid);
                    return(true);
                }

                Console.WriteLine("Could not find web package by GUID '" + guid + "'");
                return(false);
            }

            var existing = TryGetInstalledPackage(guid);

            if (existing != null && existing.CompareVersionAgainst(webManifest) != InstallState.Outdated)
            {
                //Console.WriteLine("Installed package is already greater or equal version, skipping install.");

                if (existing.IsDisabled)
                {
                    return(TryEnablePackage(guid));
                }

                return(true);
            }

            if (webManifest.dependencies != null && webManifest.dependencies.Length > 0)
            {
                int i     = 1;
                int count = webManifest.dependencies.Length;
                foreach (var dependency in webManifest.dependencies)
                {
                    MefinoGUI.SetProgressMessage($"Downloading dependency {i} of {count}: {dependency}");

                    if (!TryInstallWebPackage(dependency))
                    {
                        var msgResult = MessageBox.Show("Installing dependency '" + dependency + "' failed!\n\nContinue anyway?", "Dependency failed!", MessageBoxButtons.OKCancel);
                        if (msgResult == DialogResult.OK)
                        {
                            continue;
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    i++;
                }
            }

            // check that the package itself wasn't one of the dependencies.
            existing = TryGetInstalledPackage(guid);
            if (existing != null && existing.CompareVersionAgainst(webManifest) != InstallState.Outdated)
            {
                return(true);
            }

            MefinoGUI.SetProgressMessage($"Downloading package '{webManifest.GUID}'");
            MefinoApp.SendAsyncProgress(0);

            if (!DownloadAndInstallPackage(webManifest))
            {
                MessageBox.Show("Failed to download and install " + guid + "!");
                RefreshInstalledPackages();
                return(false);
            }

            RefreshInstalledPackages();

            OnPackageInstalled?.Invoke(webManifest);

            if (andEnable)
            {
                return(TryEnablePackage(guid));
            }
            else
            {
                return(true);
            }
        }