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

            string    downloadPath = GetAssetDownloadsPath();
            Exception exception;

            if (!ProductUpgrader.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);
        }
示例#2
0
 public static bool TryCreateUpgrader(
     ITracer tracer,
     PhysicalFileSystem fileSystem,
     bool dryRun,
     bool noVerify,
     out ProductUpgrader newUpgrader,
     out string error)
 {
     // Prefer to use the NuGet upgrader if it is configured. If the NuGet upgrader is not configured,
     // then try to use the GitHubUpgrader.
     if (NuGetUpgrader.TryCreate(tracer, fileSystem, dryRun, noVerify, out NuGetUpgrader nuGetUpgrader, out bool isConfigured, out error))
     {
         // We were successfully able to load a NuGetUpgrader - use that.
         newUpgrader = nuGetUpgrader;
         return(true);
     }
示例#3
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  = ProductUpgrader.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);
        }
        public static bool TryCreateUpgrader(
            ITracer tracer,
            PhysicalFileSystem fileSystem,
            LocalGVFSConfig gvfsConfig,
            ICredentialStore credentialStore,
            bool dryRun,
            bool noVerify,
            out ProductUpgrader newUpgrader,
            out string error)
        {
            Dictionary <string, string> entries;

            if (!gvfsConfig.TryGetAllConfig(out entries, out error))
            {
                newUpgrader = null;
                return(false);
            }

            bool containsUpgradeFeedUrl     = entries.ContainsKey(GVFSConstants.LocalGVFSConfig.UpgradeFeedUrl);
            bool containsUpgradePackageName = entries.ContainsKey(GVFSConstants.LocalGVFSConfig.UpgradeFeedPackageName);
            bool containsOrgInfoServerUrl   = entries.ContainsKey(GVFSConstants.LocalGVFSConfig.OrgInfoServerUrl);

            if (containsUpgradeFeedUrl || containsUpgradePackageName)
            {
                // We are configured for NuGet - determine if we are using OrgNuGetUpgrader or not
                if (containsOrgInfoServerUrl)
                {
                    if (OrgNuGetUpgrader.TryCreate(
                            tracer,
                            fileSystem,
                            gvfsConfig,
                            new HttpClient(),
                            credentialStore,
                            dryRun,
                            noVerify,
                            out OrgNuGetUpgrader orgNuGetUpgrader,
                            out error))
                    {
                        // We were successfully able to load a NuGetUpgrader - use that.
                        newUpgrader = orgNuGetUpgrader;
                        return(true);
                    }
                    else
                    {
                        tracer.RelatedError($"{nameof(TryCreateUpgrader)}: Could not create organization based upgrader. {error}");
                        newUpgrader = null;
                        return(false);
                    }
                }
                else
                {
                    if (NuGetUpgrader.TryCreate(
                            tracer,
                            fileSystem,
                            gvfsConfig,
                            credentialStore,
                            dryRun,
                            noVerify,
                            out NuGetUpgrader nuGetUpgrader,
                            out bool isConfigured,
                            out error))
                    {
                        // We were successfully able to load a NuGetUpgrader - use that.
                        newUpgrader = nuGetUpgrader;
                        return(true);
                    }