Ejemplo n.º 1
0
        private static void Cmd_DisableAll(string[] obj)
        {
            if (!LocalPackageManager.s_enabledPackages.Any())
            {
                return;
            }

            LocalPackageManager.DisableAllPackages();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Enable all packages in this profile, and disable all other packages.
        /// </summary>
        public void EnableProfile()
        {
            if (this.packages == null || this.packages.Count == 0)
            {
                if (LocalPackageManager.s_enabledPackages.Any())
                {
                    LocalPackageManager.DisableAllPackages();
                }
                return;
            }

            // Try enable all packages (does nothing if already OK)
            // its possible our 'packages' list will change during this process, so copy it now.
            //var copy = packages.ToList();
            List <string> missing = new List <string>();

            for (int i = 0; i < packages.Count; i++)
            {
                var pkg = packages[i];
                if (LocalPackageManager.TryGetInstalledPackage(pkg) == null)
                {
                    missing.Add(pkg);
                }
                else
                {
                    if (!LocalPackageManager.TryEnablePackage(pkg))
                    {
                        LocalPackageManager.TryDisablePackage(pkg, true);
                        packages.Remove(pkg);
                    }
                }
            }

            if (missing.Any())
            {
                string miss = "";
                foreach (var entry in missing)
                {
                    miss += $"\n{entry}";
                }

                var msgResult = MessageBox.Show($"The following packages in your profile are missing and need to be re-installed:" +
                                                $"\n{miss}" +
                                                $"\n\n" +
                                                $"Do you want to re-install them?",
                                                "Missing packages!",
                                                MessageBoxButtons.YesNo);
                if (msgResult == DialogResult.Yes)
                {
                    foreach (var entry in missing)
                    {
                        LocalPackageManager.TryInstallWebPackage(entry);
                    }
                }
            }

            // Disable currently enabled packages which are not in this profile
            if (LocalPackageManager.s_enabledPackages.Any())
            {
                for (int i = LocalPackageManager.s_enabledPackages.Count - 1; i >= 0; i--)
                {
                    var pkg = LocalPackageManager.s_enabledPackages.ElementAt(i);

                    if (!packages.Any(it => it == pkg.Key))
                    {
                        LocalPackageManager.TryDisablePackage(pkg.Key, true);
                    }
                }
            }
        }