コード例 #1
0
        /// <summary>
        /// True if there are manual changes and we overwrote the profile, otherwise false.
        /// If true, it will also set that as the active profile.</summary>
        private static bool DoManualChangesOverwrite(MefinoProfile active)
        {
            if (IsProfileDifferentToEnabledPackages(active))
            {
                List <string> uninstalled = new List <string>();
                foreach (var pkg in active.packages)
                {
                    if (LocalPackageManager.TryGetInstalledPackage(pkg) == null)
                    {
                        uninstalled.Add(pkg);
                    }
                }
                if (uninstalled.Any())
                {
                    var msg = "";
                    foreach (var entry in uninstalled)
                    {
                        msg += $"\n{entry}";
                    }

                    var msgResult = MessageBox.Show($"The following packages from the profile '{active.name}' are no longer installed:" +
                                                    $"\n{msg}" +
                                                    $"\n\n" +
                                                    $"Do you want to reinstall them?",
                                                    "Missing packages!",
                                                    MessageBoxButtons.YesNo);
                    if (msgResult == DialogResult.Yes)
                    {
                        foreach (var entry in uninstalled)
                        {
                            LocalPackageManager.TryInstallWebPackage(entry, true);
                        }
                    }
                }

                active.packages.Clear();
                active.packages.AddRange(LocalPackageManager.s_enabledPackages.Keys);

                SetChangesSinceSave(true);
                SetActiveProfile(active, true);

                return(true);
            }

            return(false);
        }
コード例 #2
0
        internal PackageManifest GetPackageFromRow(DataGridViewCellEventArgs e)
        {
            if (e == null || e.ColumnIndex < 0 || e.RowIndex < 0)
            {
                return(null);
            }

            var row = _packageList.Rows[e.RowIndex];

            var guid    = $"{row.Cells[2].Value} {row.Cells[0].Value}";
            var package = LocalPackageManager.TryGetInstalledPackage(guid);

            if (package == null)
            {
                Console.WriteLine($"ERROR! could not get package: '{package}'");
                return(null);
            }

            return(package);
        }
コード例 #3
0
        public static MefinoProfile FromJson(string jsonString)
        {
            MefinoProfile ret = null;

            try
            {
                var json = JsonReader.Parse(jsonString);

                ret = new MefinoProfile
                {
                    name = json[nameof(name)].AsString
                };

                if (json[nameof(packages)].AsJsonArray is JsonArray array)
                {
                    ret.packages.AddRange(array.Select(it => it.AsString));
                }

                // verify all GUIDs.
                for (int i = ret.packages.Count - 1; i >= 0; i--)
                {
                    var guid = ret.packages[i];

                    if (!WebManifestManager.s_webManifests.ContainsKey(guid) &&
                        LocalPackageManager.TryGetInstalledPackage(guid) == null)
                    {
                        // GUID in package list does not exist, locally or online!
                        ret.packages.RemoveAt(i);
                    }
                }

                return(ret);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception parsing Profile from json!");
                Console.WriteLine(ex);
                return(ret);
            }
        }
コード例 #4
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);
                    }
                }
            }
        }