Ejemplo n.º 1
0
        public void Install(IVsExtensionManager manager, IInstalledExtension currentExtention, IInstallableExtension updatedExtension)
        {
            manager.Disable(currentExtention);
            manager.Uninstall(currentExtention);
            manager.Install(updatedExtension, false);

            var newlyInstalledVersion = manager.GetInstalledExtension(updatedExtension.Header.Identifier);
            if (newlyInstalledVersion.IsNotNull())
            {
                manager.Enable(newlyInstalledVersion);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if ((this.package as VSPackage).TargetExtensionIdentifier is string tei && !string.IsNullOrWhiteSpace(tei))
            {
                if (_extManager.TryGetInstalledExtension(tei, out IInstalledExtension ext))
                {
                    _extManager.Disable(ext);
                    (this.package as VSPackage).IsInDisableCycle = true;
                }
            }
    private RestartReason Install(IInstalledExtension currentExtension, IInstallableExtension updatedExtension)
    {
        //Uninstall old extension
        _extensionManager.Disable(currentExtension);
        _extensionManager.Uninstall(currentExtension);
        //Install new version
        var restartReason = _extensionManager.Install(updatedExtension, false);
        //Enable the newly installed version of the extension
        var newlyInstalledVersion = _extensionManager.GetInstalledExtension(updatedExtension.Header.Identifier);

        if (newlyInstalledVersion != null)
        {
            _extensionManager.Enable(newlyInstalledVersion);
        }
        return(restartReason);
    }
Ejemplo n.º 4
0
        public static RestartReason CheckForUpdates(string identifier, string updateUrl)
        {
            // Don't check for updates on non-DEPLOY builds; the URLs don't work and it seems
            // undesirable anyway.
#if DEPLOY
            IVsExtensionManager extensionManager   = Package.GetGlobalService(typeof(SVsExtensionManager)) as IVsExtensionManager;
            IInstalledExtension installedExtension = extensionManager.GetInstalledExtension(identifier);
            if (installedExtension == null)
            {
                throw new Exception(String.Format("Unable to find extension: {0}", identifier));
            }

            RepositoryEntry entry = new RepositoryEntry();
            entry.DownloadUrl = updateUrl;

            IVsExtensionRepository repository      = Package.GetGlobalService(typeof(SVsExtensionRepository)) as IVsExtensionRepository;
            IInstallableExtension  latestExtension = repository.Download(entry);

            if (latestExtension.Header.Version > installedExtension.Header.Version)
            {
                RestartReason reason = RestartReason.None;
                reason |= extensionManager.Disable(installedExtension);
                extensionManager.Uninstall(installedExtension);

                try {
                    reason |= extensionManager.Install(latestExtension, /*perMachine*/ false);

                    // Enable the new one.
                    IInstalledExtension latestInstalledExtension = extensionManager.GetInstalledExtension(latestExtension.Header.Identifier);
                    reason |= extensionManager.Enable(latestInstalledExtension);
                    return(reason);
                } catch {
                    // Revert the uninstallation.
                    extensionManager.RevertUninstall(installedExtension);
                    extensionManager.Enable(installedExtension);
                    throw;
                }
            }
#endif
            return(RestartReason.None);
        }
Ejemplo n.º 5
0
        private void DownloadAndInstall()
        {
            IEnumerable <IInstalledExtension> extensions = Commands.GetExtensions(_manager);

            foreach (IInstalledExtension extension in extensions)
            {
                if (!Settings.IsEnabled(extension.Header.Identifier))
                {
                    continue;
                }

                IInstallableExtension update;
                bool updateAvailable = _checker.CheckForUpdate(extension, out update);

                if (updateAvailable && update != null)
                {
                    _manager.Disable(extension);
                    _manager.Uninstall(extension);
                    _manager.InstallAsync(update, false);
                }
            }
        }