예제 #1
0
        private void InstallIfNeeded(IVsShell shellService)
        {
            if (shellService == null)
            {
                ShellDialogs.Error(this, Resources.ErrorMessage_ShellServiceUnavailable);
                return;
            }

            ThreadHelper.ThrowIfNotOnUIThread();
            shellService.GetProperty((int)__VSSPROPID2.VSSPROPID_VisualStudioDir, out object documentsDirObj);
            string           documentsDir     = documentsDirObj.ToString();
            string           targetPath       = Path.Combine(documentsDir, "Visualizers");
            InstallationInfo installedVersion = InstallationManager.GetInstallationInfo(targetPath);
            InstallationInfo availableVersion = InstallationManager.AvailableVersion;

            if (installedVersion.Installed && (installedVersion.Version == null || installedVersion.Version >= availableVersion.Version))
            {
                return;
            }

            InstallationManager.Install(targetPath, out string error, out string warning);
            if (error != null)
            {
                ShellDialogs.Error(this, Res.ErrorMessageFailedToInstall(targetPath, error));
            }
            else if (warning != null)
            {
                ShellDialogs.Warning(this, Res.WarningMessageInstallationFinishedWithWarning(targetPath, warning));
            }
            else if (installedVersion.Installed && installedVersion.Version != null)
            {
                ShellDialogs.Info(this, Res.InfoMessageUpgradeFinished(installedVersion.Version, availableVersion.Version, targetPath));
            }
            else
            {
                ShellDialogs.Info(this, Res.InfoMessageInstallationFinished(availableVersion.Version, targetPath));
            }
        }