public SectionResponseEnum Execute(PackageClass packageClass, ActionItem actionItem)
        {
            PackageClass pak = new PackageClass();

            pak = pak.ZipProvider.Load(actionItem.Params[Const_Loc].Value);
            if (pak == null)
            {
                return(SectionResponseEnum.Ok);
            }

            if (ItemProcessed != null)
            {
                ItemProcessed(this, new InstallEventArgs("Install extension " + pak.GeneralInfo.Name));
            }

            PackageClass installedPak = MpeInstaller.InstalledExtensions.Get(pak.GeneralInfo.Id);

            if (installedPak != null)
            {
                int i = installedPak.GeneralInfo.Version.CompareTo(pak.GeneralInfo.Version);
                if (installedPak.GeneralInfo.Version.CompareTo(pak.GeneralInfo.Version) >= 0)
                {
                    return(SectionResponseEnum.Ok);
                }
                installedPak.Silent        = true;
                installedPak.UnInstallInfo = new UnInstallInfoCollection(installedPak);
                installedPak.UnInstallInfo = installedPak.UnInstallInfo.Load();
                if (installedPak.UnInstallInfo == null)
                {
                    installedPak.UnInstallInfo = new UnInstallInfoCollection();
                }
                installedPak.UnInstall();
                pak.CopyGroupCheck(installedPak);
            }
            if (actionItem.Params[Const_Silent].GetValueAsBool())
            {
                pak.Silent = true;
            }
            pak.StartInstallWizard();
            return(SectionResponseEnum.Ok);
        }
Exemplo n.º 2
0
 private void UnInstall_Shown(object sender, EventArgs e)
 {
     Package.UnInstall();
     this.Close();
 }
        public SectionResponseEnum Execute(PackageClass packageClass, ActionItem actionItem)
        {
            // load extension from zip if provided
            PackageClass embeddedPackage = null;

            if (!string.IsNullOrEmpty(actionItem.Params[Const_Loc].Value))
            {
                embeddedPackage = new PackageClass().ZipProvider.Load(actionItem.Params[Const_Loc].Value);
                if (embeddedPackage == null && string.IsNullOrEmpty(actionItem.Params[Const_Guid].Value))
                {
                    return(SectionResponseEnum.Ok);
                }
            }

            // check if there is already an installed version with a higher version than the embedded
            PackageClass installedPak = MpeInstaller.InstalledExtensions.Get(embeddedPackage != null ? embeddedPackage.GeneralInfo.Id : actionItem.Params[Const_Guid].Value);

            if (installedPak != null && embeddedPackage != null && installedPak.GeneralInfo.Version.CompareTo(embeddedPackage.GeneralInfo.Version) >= 0)
            {
                return(SectionResponseEnum.Ok);
            }

            // download new version when none embedded and (none installed none or lower version than required installed)
            if (embeddedPackage == null && !string.IsNullOrEmpty(actionItem.Params[Const_Guid].Value) &&
                (installedPak == null ||
                 (!string.IsNullOrEmpty(actionItem.Params[Const_Version].Value) && installedPak.GeneralInfo.Version.CompareTo(VersionInfo.Parse(actionItem.Params[Const_Version].Value)) < 0)))
            {
                // we don't want incompatible versions
                MpeInstaller.KnownExtensions.HideByDependencies();
                PackageClass knownPackage = MpeInstaller.KnownExtensions.Get(actionItem.Params[Const_Guid].Value);
                if (knownPackage == null && (DateTime.Now - ApplicationSettings.Instance.LastUpdate).TotalHours > 12)
                {
                    // package unknown and last download of update info was over 12 hours ago -> update the list first
                    ExtensionUpdateDownloader.UpdateList(false, false, null, null);
                    // search for the package again - we don't want incompatible versions
                    MpeInstaller.KnownExtensions.HideByDependencies();
                    knownPackage = MpeInstaller.KnownExtensions.Get(actionItem.Params[Const_Guid].Value);
                }
                if (knownPackage != null)
                {
                    // make sure the package has at least the asked version
                    if (knownPackage.GeneralInfo.Version.CompareTo(new Version(actionItem.Params[Const_Version].Value)) >= 0)
                    {
                        // download extension package
                        string newPackageLoacation = ExtensionUpdateDownloader.GetPackageLocation(knownPackage, null, null);
                        if (File.Exists(newPackageLoacation))
                        {
                            embeddedPackage = new PackageClass().ZipProvider.Load(newPackageLoacation);
                        }
                    }
                }
            }

            if (embeddedPackage == null) // no package was embedded or downloaded
            {
                return(SectionResponseEnum.Ok);
            }

            if (ItemProcessed != null)
            {
                ItemProcessed(this, new InstallEventArgs("Install extension " + embeddedPackage.GeneralInfo.Name));
            }

            if (installedPak != null)
            {
                // uninstall previous version, if the new package has the setting to force uninstall of previous version on update
                if (embeddedPackage.GeneralInfo.Params[ParamNamesConst.FORCE_TO_UNINSTALL_ON_UPDATE].GetValueAsBool())
                {
                    installedPak.Silent        = true;
                    installedPak.UnInstallInfo = new UnInstallInfoCollection(installedPak);
                    installedPak.UnInstallInfo = installedPak.UnInstallInfo.Load();
                    if (installedPak.UnInstallInfo == null)
                    {
                        installedPak.UnInstallInfo = new UnInstallInfoCollection();
                    }
                    installedPak.UnInstall();
                    embeddedPackage.CopyGroupCheck(installedPak);
                    installedPak = null;
                }
            }

            embeddedPackage.Silent = actionItem.Params[Const_Silent].GetValueAsBool();
            if (embeddedPackage.StartInstallWizard())
            {
                if (installedPak != null)
                {
                    MpeCore.MpeInstaller.InstalledExtensions.Remove(installedPak);
                    MpeCore.MpeInstaller.Save();
                }
            }
            return(SectionResponseEnum.Ok);
        }