Example #1
0
        public void PerformInstallation(PluginUpdates updates, MainForm XrmToolBoxAppForm)
        {
            if (updates.Plugins.Any(p => p.RequireRestart))
            {
                XmlSerializerHelper.SerializeToFile(updates, Path.Combine(applicationFolder, "Update.xml"));

                if (DialogResult.Yes == MessageBox.Show(
                    "This application needs to restart to install updated plugins (or new plugins that share some files with already installed plugins). Click Yes to restart this application now",
                    "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    Application.Restart();
                }
            }
            else
            {
                XrmToolBoxAppForm.EnableNewPluginsWatching(false);

                foreach (var pu in updates.Plugins)
                {
                    try
                    {
                        // Can install plugin directly
                        var destinationDirectory = Path.GetDirectoryName(pu.Destination);
                        if (!Directory.Exists(destinationDirectory))
                        {
                            Directory.CreateDirectory(destinationDirectory);
                        }
                        File.Copy(pu.Source, pu.Destination, true);
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show(this,
                            "An error occured while copying files: " + error.Message +
                            "\r\n\r\nCopy has been aborted", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                // Refresh plugins list when installation is done
                XrmToolBoxAppForm.ReloadPluginsList();
                RefreshPluginsList();
                CalculateCacheFolderSize();
                MessageBox.Show("Installation done!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

                XrmToolBoxAppForm.EnableNewPluginsWatching(true);
            }
        }
Example #2
0
        public PluginUpdates PrepareInstallationPackages(List<XtbNuGetPackage> xtbPackages)
        {
            var pus = new PluginUpdates {PreviousProcessId = Process.GetCurrentProcess().Id};

            foreach (var xtbPackage in xtbPackages)
            {

                if (xtbPackage.Action == PackageInstallAction.Unavailable)
                {
                    if (xtbPackage.Package.ProjectUrl != null &&
                        !string.IsNullOrEmpty(xtbPackage.Package.ProjectUrl.ToString()))
                    {
                        if (DialogResult.Yes ==
                            MessageBox.Show(
                                $"{xtbPackage.Package.Title}\nis incompatible with this version of XrmToolBox.\nOpen project URL?",
                                "Incompatible plugin", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation))
                        {
                            Process.Start(xtbPackage.Package.ProjectUrl.ToString());
                        }
                    }
                    else
                    {
                        MessageBox.Show(
                            $"{xtbPackage.Package.Title}\nis incompatible with this version of XrmToolBox.",
                            "Incompatible plugin", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    continue;
                }
                manager.InstallPackage(xtbPackage.Package, true, false);

                var packageFolder = Path.Combine(nugetPluginsFolder,
                    xtbPackage.Package.Id + "." + xtbPackage.Package.Version);

                foreach (var fi in xtbPackage.Package.GetFiles())
                {
                    var destinationFile = Path.Combine(applicationFolder, fi.EffectivePath);

                    // XrmToolBox restart is required when a plugin has to be
                    // updated or when a new plugin shares files with other
                    // plugin(s) already installed
                    if (xtbPackage.RequiresXtbRestart)
                    {
                        pus.Plugins.Add(new PluginUpdate
                        {
                            Source = Path.Combine(packageFolder, fi.Path),
                            Destination = destinationFile,
                            RequireRestart = true
                        });
                    }
                    else if (xtbPackage.Action == PackageInstallAction.Install)
                    {
                        pus.Plugins.Add(new PluginUpdate
                        {
                            Source = Path.Combine(packageFolder, fi.Path),
                            Destination = destinationFile,
                            RequireRestart = false
                        });
                    }
                }
            }

            return pus;
        }
Example #3
0
        private void tsbInstall_Click(object sender, EventArgs e)
        {
            if (lvPlugins.CheckedItems.Count == 0)
                return;

            ((MainForm)Owner).EnableNewPluginsWatching(false);

            var pus = new PluginUpdates { PreviousProcessId = Process.GetCurrentProcess().Id };

            foreach (ListViewItem item in lvPlugins.CheckedItems.Cast<ListViewItem>().Where(l => l.Tag is XtbNuGetPackage))
            {
                var xtbPackage = (XtbNuGetPackage)item.Tag;

                if (xtbPackage.Action == PackageInstallAction.Unavailable)
                {
                    if (xtbPackage.Package.ProjectUrl != null && !string.IsNullOrEmpty(xtbPackage.Package.ProjectUrl.ToString()))
                    {
                        if (DialogResult.Yes == MessageBox.Show($"{xtbPackage.Package.Title}\nis incompatible with this version of XrmToolBox.\nOpen project URL?", "Incompatible plugin", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation))
                        {
                            Process.Start(xtbPackage.Package.ProjectUrl.ToString());
                        }
                    }
                    else
                    {
                        MessageBox.Show($"{xtbPackage.Package.Title}\nis incompatible with this version of XrmToolBox.", "Incompatible plugin", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    continue;
                }
                manager.InstallPackage(xtbPackage.Package, true, false);

                var packageFolder = Path.Combine(nugetPluginsFolder, xtbPackage.Package.Id + "." + xtbPackage.Package.Version);

                foreach (var fi in xtbPackage.Package.GetFiles())
                {
                    var destinationFile = Path.Combine(applicationFolder, fi.EffectivePath);

                    // XrmToolBox restart is required when a plugin has to be
                    // updated or when a new plugin shares files with other
                    // plugin(s) already installed
                    if (xtbPackage.RequiresXtbRestart)
                    {
                        pus.Plugins.Add(new PluginUpdate
                        {
                            Source = Path.Combine(packageFolder, fi.Path),
                            Destination = destinationFile
                        });
                    }
                    else if (xtbPackage.Action == PackageInstallAction.Install)
                    {
                        try
                        {
                            // Can install plugin directly
                            var destinationDirectory = Path.GetDirectoryName(destinationFile);
                            if (!Directory.Exists(destinationDirectory))
                            {
                                Directory.CreateDirectory(destinationDirectory);
                            }
                            File.Copy(Path.Combine(packageFolder, fi.Path), destinationFile, true);
                        }
                        catch (Exception error)
                        {
                            MessageBox.Show(this,
                                "An error occured while copying files: " + error.Message +
                                "\r\n\r\nCopy has been aborted", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                }
            }

            if (pus.Plugins.Count > 0)
            {
                XmlSerializerHelper.SerializeToFile(pus, Path.Combine(applicationFolder, "Update.xml"));

                if (DialogResult.Yes == MessageBox.Show(
                    "This application needs to restart to install updated plugins (or new plugins that share some files with already installed plugins). Click Yes to restart this application now",
                    "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    Application.Restart();
                }
            }
            else
            {
                // Refresh plugins list when installation is done
                ((MainForm)Owner).ReloadPluginsList();
                RefreshPluginsList();
                MessageBox.Show("Installation done!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

             ((MainForm)Owner).EnableNewPluginsWatching(true);
        }