Exemple #1
0
        /// <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);
        }
Exemple #2
0
        /// <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);
                }
            }
        }