protected override void DownloadVersionCore(string latestVersion, string target, PaketHashFile hashfile) { string url = String.Format(Constants.PaketNupkgDownloadUrlTemplate, latestVersion); ConsoleImpl.WriteInfo("Starting download from {0}", url); var tmpFile = BootstrapperHelper.GetTempFile("paketnupkg"); WebRequestProxy.DownloadFile(url, tmpFile); string packageName = Path.GetFileName(url); var randomFullPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); FileSystemProxy.CreateDirectory(randomFullPath); string packagePath = Path.Combine(randomFullPath, packageName); FileSystemProxy.CopyFile(tmpFile, packagePath, true); FileSystemProxy.DeleteFile(tmpFile); var installAsTool = new InstallKind.InstallAsTool(FileSystemProxy); installAsTool.Run(randomFullPath, target, latestVersion); FileSystemProxy.DeleteDirectory(randomFullPath, true); }
protected override void DownloadVersionCore(string latestVersion, string target, PaketHashFile hashfile) { var apiHelper = new NugetApiHelper(PaketNugetPackageName, NugetSource); const string paketNupkgFile = "paket.latest.nupkg"; const string paketNupkgFileTemplate = "paket.{0}.nupkg"; var paketDownloadUrl = apiHelper.GetLatestPackage(); var paketFile = paketNupkgFile; if (!String.IsNullOrWhiteSpace(latestVersion)) { paketDownloadUrl = apiHelper.GetSpecificPackageVersion(latestVersion); paketFile = String.Format(paketNupkgFileTemplate, latestVersion); } var randomFullPath = Path.Combine(Folder, Path.GetRandomFileName()); FileSystemProxy.CreateDirectory(randomFullPath); var paketPackageFile = Path.Combine(randomFullPath, paketFile); if (FileSystemProxy.DirectoryExists(NugetSource)) { if (String.IsNullOrWhiteSpace(latestVersion)) { latestVersion = GetLatestVersion(false); } var sourcePath = Path.Combine(NugetSource, String.Format(paketNupkgFileTemplate, latestVersion)); ConsoleImpl.WriteInfo("Starting download from {0}", sourcePath); FileSystemProxy.CopyFile(sourcePath, paketPackageFile); } else { ConsoleImpl.WriteInfo("Starting download from {0}", paketDownloadUrl); try { WebRequestProxy.DownloadFile(paketDownloadUrl, paketPackageFile); } catch (WebException webException) { if (webException.Status == WebExceptionStatus.ProtocolError && !string.IsNullOrEmpty(latestVersion)) { var response = (HttpWebResponse)webException.Response; if (response.StatusCode == HttpStatusCode.NotFound) { throw new WebException(String.Format("Version {0} wasn't found (404)", latestVersion), webException); } if (response.StatusCode == HttpStatusCode.BadRequest) { // For cases like "The package version is not a valid semantic version" throw new WebException(String.Format("Unable to get version '{0}': {1}", latestVersion, response.StatusDescription), webException); } } Console.WriteLine(webException.ToString()); throw; } } if (this.AsTool) { var installAsTool = new InstallKind.InstallAsTool(FileSystemProxy); installAsTool.Run(randomFullPath, target, latestVersion); } else { FileSystemProxy.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.exe"); FileSystemProxy.CopyFile(paketSourceFile, target, true); } FileSystemProxy.DeleteDirectory(randomFullPath, true); }