示例#1
0
        private bool TryRunInstallerForAsset(string assetId, out int installerExitCode, out string error)
        {
            error             = null;
            installerExitCode = 0;

            bool   installerIsRun = false;
            string path;
            string installerArgs;

            if (this.TryGetLocalInstallerPath(assetId, out path, out installerArgs))
            {
                string logFilePath = GVFSEnlistment.GetNewLogFileName(ProductUpgraderInfo.GetLogDirectoryPath(), Path.GetFileNameWithoutExtension(path));
                string args        = installerArgs + " /Log=" + logFilePath;
                this.RunInstaller(path, args, out installerExitCode, out error);

                if (installerExitCode != 0 && string.IsNullOrEmpty(error))
                {
                    error = assetId + " installer failed. Error log: " + logFilePath;
                }

                installerIsRun = true;
            }
            else
            {
                error = "Could not find downloaded installer for " + assetId;
            }

            return(installerIsRun);
        }
示例#2
0
        protected virtual bool TryDownloadAsset(Asset asset, out string errorMessage)
        {
            errorMessage = null;

            string    downloadPath = ProductUpgraderInfo.GetAssetDownloadsPath();
            Exception exception;

            if (!GitHubUpgrader.TryCreateDirectory(downloadPath, out exception))
            {
                errorMessage = exception.Message;
                this.TraceException(exception, nameof(this.TryDownloadAsset), $"Error creating download directory {downloadPath}.");
                return(false);
            }

            string    localPath = Path.Combine(downloadPath, asset.Name);
            WebClient webClient = new WebClient();

            try
            {
                webClient.DownloadFile(asset.DownloadURL, localPath);
                asset.LocalPath = localPath;
            }
            catch (WebException webException)
            {
                errorMessage = "Download error: " + exception.Message;
                this.TraceException(webException, nameof(this.TryDownloadAsset), $"Error downloading asset {asset.Name}.");
                return(false);
            }

            return(true);
        }
示例#3
0
        private bool TryRunInstallerForAsset(string assetId, out int installerExitCode, out string error)
        {
            error             = null;
            installerExitCode = 0;

            bool   installerIsRun = false;
            string path;
            string installerArgs;

            if (this.TryGetLocalInstallerPath(assetId, out path, out installerArgs))
            {
                if (!this.dryRun)
                {
                    string logFilePath = GVFSEnlistment.GetNewLogFileName(
                        ProductUpgraderInfo.GetLogDirectoryPath(),
                        Path.GetFileNameWithoutExtension(path),
                        this.UpgradeInstanceId,
                        this.fileSystem);

                    string args     = installerArgs + " /Log=" + logFilePath;
                    string certCN   = null;
                    string issuerCN = null;
                    switch (assetId)
                    {
                    case GVFSAssetId:
                    {
                        certCN   = GVFSSigner;
                        issuerCN = GVFSCertIssuer;
                        break;
                    }

                    case GitAssetId:
                    {
                        certCN   = GitSigner;
                        issuerCN = GitCertIssuer;
                        break;
                    }
                    }

                    this.RunInstaller(path, args, certCN, issuerCN, out installerExitCode, out error);

                    if (installerExitCode != 0 && string.IsNullOrEmpty(error))
                    {
                        error = assetId + " installer failed. Error log: " + logFilePath;
                    }
                }

                installerIsRun = true;
            }
            else
            {
                error = "Could not find downloaded installer for " + assetId;
            }

            return(installerIsRun);
        }
示例#4
0
        public GitHubUpgrader(string currentVersion, ITracer tracer)
        {
            this.installedVersion = new Version(currentVersion);
            this.fileSystem       = new PhysicalFileSystem();
            this.tracer           = tracer;

            string upgradesDirectoryPath = ProductUpgraderInfo.GetUpgradesDirectoryPath();

            this.fileSystem.CreateDirectory(upgradesDirectoryPath);
        }
示例#5
0
 /// <summary>
 /// Deletes any previously downloaded installers in the Upgrader Download directory.
 /// This can include old installers which were downloaded, but user never installed
 /// using gvfs upgrade and GVFS is now up to date already.
 /// </summary>
 public static void DeleteAllInstallerDownloads(ITracer tracer = null)
 {
     try
     {
         RecursiveDelete(ProductUpgraderInfo.GetAssetDownloadsPath());
     }
     catch (Exception ex)
     {
         if (tracer != null)
         {
             tracer.RelatedError($"{nameof(DeleteAllInstallerDownloads)}: Could not remove directory: {ProductUpgraderInfo.GetAssetDownloadsPath()}.{ex.ToString()}");
         }
     }
 }
示例#6
0
        public GitHubUpgrader(
            string currentVersion,
            ITracer tracer,
            PhysicalFileSystem fileSystem,
            GitHubUpgraderConfig upgraderConfig,
            bool dryRun   = false,
            bool noVerify = false)
            : base(currentVersion, tracer, dryRun, noVerify, fileSystem)
        {
            this.Config = upgraderConfig;

            string upgradesDirectoryPath = ProductUpgraderInfo.GetUpgradesDirectoryPath();

            this.fileSystem.CreateDirectory(upgradesDirectoryPath);
        }
示例#7
0
        // TrySetupToolsDirectory -
        // Copies GVFS Upgrader tool and its dependencies to a temporary location in ProgramData.
        // Reason why this is needed - When GVFS.Upgrader.exe is run from C:\ProgramFiles\GVFS folder
        // upgrade installer that is downloaded and run will fail. This is because it cannot overwrite
        // C:\ProgramFiles\GVFS\GVFS.Upgrader.exe that is running. Moving GVFS.Upgrader.exe along with
        // its dependencies to a temporary location inside ProgramData and running GVFS.Upgrader.exe
        // from this temporary location helps avoid this problem.
        public virtual bool TrySetupToolsDirectory(out string upgraderToolPath, out string error)
        {
            string    rootDirectoryPath  = ProductUpgraderInfo.GetUpgradesDirectoryPath();
            string    toolsDirectoryPath = Path.Combine(rootDirectoryPath, ToolsDirectory);
            Exception exception;

            if (TryCreateDirectory(toolsDirectoryPath, out exception))
            {
                string currentPath = ProcessHelper.GetCurrentProcessLocation();
                error = null;
                foreach (string name in UpgraderToolAndLibs)
                {
                    string toolPath        = Path.Combine(currentPath, name);
                    string destinationPath = Path.Combine(toolsDirectoryPath, name);
                    try
                    {
                        File.Copy(toolPath, destinationPath, overwrite: true);
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        error = string.Join(
                            Environment.NewLine,
                            "File copy error - " + e.Message,
                            $"Make sure you have write permissions to directory {rootDirectoryPath} and run {GVFSConstants.UpgradeVerbMessages.GVFSUpgradeConfirm} again.");
                        this.TraceException(e, nameof(this.TrySetupToolsDirectory), $"Error copying {toolPath} to {destinationPath}.");
                        break;
                    }
                    catch (IOException e)
                    {
                        error = "File copy error - " + e.Message;
                        this.TraceException(e, nameof(this.TrySetupToolsDirectory), $"Error copying {toolPath} to {destinationPath}.");
                        break;
                    }
                }

                upgraderToolPath = string.IsNullOrEmpty(error) ? Path.Combine(toolsDirectoryPath, UpgraderToolName) : null;
                return(string.IsNullOrEmpty(error));
            }

            upgraderToolPath = null;
            error            = exception.Message;
            this.TraceException(exception, nameof(this.TrySetupToolsDirectory), $"Error creating upgrade tools directory {toolsDirectoryPath}.");
            return(false);
        }
示例#8
0
 public void DeleteAllInstallerDownloads()
 {
     try
     {
         this.fileSystem.DeleteDirectory(GetAssetDownloadsPath());
     }
     catch (Exception ex)
     {
         if (this.tracer != null)
         {
             this.tracer.RelatedError($"{nameof(this.DeleteAllInstallerDownloads)}: Could not remove directory: {ProductUpgraderInfo.GetAssetDownloadsPath()}.{ex.ToString()}");
         }
     }
 }
示例#9
0
 private bool IsGVFSAsset(Asset asset)
 {
     return(this.AssetInstallerNameCompare(asset, ProductUpgraderInfo.PossibleGVFSInstallerNamePrefixes().ToArray()));
 }