Пример #1
0
        /// <summary>
        /// Try to load a NuGetUpgrader from config settings.
        /// <isConfigured>Flag to indicate whether the system is configured to use a NuGetUpgrader.
        /// A NuGetUpgrader can be set as the Upgrader to use, but it might not be properly configured.
        /// </isConfigured>
        /// <Returns>True if able to load a properly configured NuGetUpgrader<Returns>
        /// </summary>
        public static bool TryCreate(
            ITracer tracer,
            PhysicalFileSystem fileSystem,
            LocalGSDConfig gvfsConfig,
            ICredentialStore credentialStore,
            bool dryRun,
            bool noVerify,
            out NuGetUpgrader nuGetUpgrader,
            out bool isConfigured,
            out string error)
        {
            NuGetUpgraderConfig upgraderConfig = new NuGetUpgraderConfig(tracer, gvfsConfig);

            nuGetUpgrader = null;
            isConfigured  = false;

            if (!upgraderConfig.TryLoad(out error))
            {
                nuGetUpgrader = null;
                return(false);
            }

            if (!(isConfigured = upgraderConfig.IsConfigured(out error)))
            {
                return(false);
            }

            // At this point, we have determined that the system is set up to use
            // the NuGetUpgrader

            if (!upgraderConfig.IsReady(out error))
            {
                return(false);
            }

            nuGetUpgrader = new NuGetUpgrader(
                ProcessHelper.GetCurrentProcessVersion(),
                tracer,
                fileSystem,
                dryRun,
                noVerify,
                upgraderConfig,
                ProductUpgraderInfo.GetAssetDownloadsPath(),
                credentialStore);

            return(true);
        }
Пример #2
0
        public override bool TryRunInstaller(InstallActionWrapper installActionWrapper, out string error)
        {
            string localError = null;
            int    installerExitCode;
            bool   installSuccessful = true;

            using (ITracer activity = this.tracer.StartActivity(nameof(this.TryRunInstaller), EventLevel.Informational))
            {
                InstallActionInfo currentInstallAction = null;
                try
                {
                    string platformKey = GSDPlatform.Instance.Name;

                    if (!this.TryRecursivelyDeleteInstallerDirectory(out error))
                    {
                        return(false);
                    }

                    if (!this.noVerify)
                    {
                        if (!this.nuGetFeed.VerifyPackage(this.DownloadedPackagePath))
                        {
                            error = "Package signature validation failed. Check the upgrade logs for more details.";
                            activity.RelatedError(error);
                            this.fileSystem.DeleteFile(this.DownloadedPackagePath);
                            return(false);
                        }
                    }

                    this.UnzipPackage();
                    this.installManifest = InstallManifest.FromJsonFile(Path.Combine(this.ExtractedInstallerPath, ContentDirectoryName, InstallManifestFileName));
                    if (!this.installManifest.PlatformInstallManifests.TryGetValue(platformKey, out InstallManifestPlatform platformInstallManifest) ||
                        platformInstallManifest == null)
                    {
                        activity.RelatedError($"Extracted InstallManifest from JSON, but there was no entry for {platformKey}.");
                        error = $"No entry in the manifest for the current platform ({platformKey}). Please verify the upgrade package.";
                        return(false);
                    }

                    activity.RelatedInfo($"Extracted InstallManifest from JSON. InstallActions: {platformInstallManifest.InstallActions.Count}");

                    foreach (InstallActionInfo entry in platformInstallManifest.InstallActions)
                    {
                        currentInstallAction = entry;
                        string installerBasePath = Path.Combine(this.ExtractedInstallerPath, ContentDirectoryName);

                        string args = entry.Args ?? string.Empty;

                        // Replace tokens on args
                        string processedArgs = NuGetUpgrader.ReplaceArgTokens(args, this.UpgradeInstanceId, ProductUpgraderInfo.GetLogDirectoryPath(), $"\"{installerBasePath}\"");

                        activity.RelatedInfo(
                            "Running install action: Name: {0}, Version: {1}, InstallerPath: {2}, Command: {3}, RawArgs: {4}, ProcessedArgs: {5}",
                            entry.Name,
                            entry.Version,
                            entry.InstallerRelativePath ?? string.Empty,
                            entry.Command ?? string.Empty,
                            args,
                            processedArgs);

                        string progressMessage = string.IsNullOrWhiteSpace(entry.Version) ?
                                                 $"Running {entry.Name}" :
                                                 $"Running {entry.Name} (version {entry.Version})";

                        installActionWrapper(
                            () =>
                        {
                            if (!this.dryRun)
                            {
                                if (!string.IsNullOrEmpty(entry.Command))
                                {
                                    this.RunInstaller(entry.Command, processedArgs, out installerExitCode, out localError);
                                }
                                else
                                {
                                    string installerPath = Path.Combine(installerBasePath, entry.InstallerRelativePath);
                                    this.RunInstaller(installerPath, processedArgs, out installerExitCode, out localError);
                                }
                            }
                            else
                            {
                                // We add a sleep here to ensure
                                // the message for this install
                                // action is written to the
                                // console.  Even though the
                                // message is written with a delay
                                // of 0, the messages are not
                                // always written out.  If / when
                                // we can ensure that the message
                                // is written out to console, then
                                // we can remove this sleep.
                                Thread.Sleep(1500);
                                installerExitCode = 0;
                            }

                            installSuccessful = installerExitCode == 0;

                            return(installSuccessful);
                        },
                            progressMessage);

                        if (!installSuccessful)
                        {
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    localError        = ex.Message;
                    installSuccessful = false;
                }

                if (!installSuccessful)
                {
                    string installActionName = string.IsNullOrEmpty(currentInstallAction?.Name) ?
                                               "installer" :
                                               currentInstallAction.Name;

                    error = string.IsNullOrEmpty(localError) ?
                            $"The {installActionName} failed, but no error message was provided by the failing command." :
                            $"The {installActionName} failed with the following error: {localError}";

                    activity.RelatedError($"Could not complete all install actions. The following error was encountered: {error}");
                    return(false);
                }
                else
                {
                    activity.RelatedInfo($"Install actions completed successfully.");
                    error = null;
                    return(true);
                }
            }
        }