public void SelfUpdate(string latestVersion) { var executingAssembly = Assembly.GetExecutingAssembly(); string exePath = executingAssembly.Location; var localVersion = FileSystemProxy.GetLocalFileVersion(exePath); if (localVersion.StartsWith(latestVersion)) { ConsoleImpl.WriteDebug("Bootstrapper is up to date. Nothing to do."); return; } var url = String.Format("https://github.com/fsprojects/Paket/releases/download/{0}/paket.bootstrapper.exe", latestVersion); ConsoleImpl.WriteDebug("Starting download of bootstrapper from {0}", url); string renamedPath = BootstrapperHelper.GetTempFile("oldBootstrapper"); string tmpDownloadPath = BootstrapperHelper.GetTempFile("newBootstrapper"); WebRequestProxy.DownloadFile(url, tmpDownloadPath); try { FileSystemProxy.MoveFile(exePath, renamedPath); FileSystemProxy.MoveFile(tmpDownloadPath, exePath); ConsoleImpl.WriteDebug("Self update of bootstrapper was successful."); } catch (Exception) { ConsoleImpl.WriteDebug("Self update failed. Resetting bootstrapper."); FileSystemProxy.MoveFile(renamedPath, exePath); throw; } }
public string GetLatestVersion(bool ignorePrerelease) { var targetVersion = string.Empty; try { targetVersion = _fileProxy.GetLocalFileVersion(_target); } catch (FileNotFoundException) { targetVersion = string.Empty; } if (!IsOlderThanMaxFileAge()) { ConsoleImpl.WriteDebug("Don't look for new version, as last version is not older than {0} minutes", _maxFileAgeOfPaketExeInMinutes); return(targetVersion); } var latestVersion = _effectiveStrategy.GetLatestVersion(ignorePrerelease); if (latestVersion == targetVersion) { TouchTarget(_target); } return(latestVersion); }
public void DownloadVersion(string latestVersion, string target) { var url = String.Format(Constants.PaketExeDownloadUrlTemplate, latestVersion); ConsoleImpl.WriteDebug("Starting download from {0}", url); var tmpFile = BootstrapperHelper.GetTempFile("paket"); WebRequestProxy.DownloadFile(url, tmpFile); FileSystemProxy.CopyFile(tmpFile, target, true); FileSystemProxy.DeleteFile(tmpFile); }
private void TouchTarget(string target) { try { _fileProxy.Touch(target); } catch (FileNotFoundException) { ConsoleImpl.WriteDebug("Could not update the timestamps. File {0} not found!", _target); } catch (Exception) { ConsoleImpl.WriteDebug("Could not update the timestamps."); } }
public void DownloadVersion(string latestVersion, string target) { var url = String.Format(Constants.PaketExeDownloadUrlTemplate, latestVersion); ConsoleImpl.WriteDebug("Starting download from {0}", url); var tmpFile = BootstrapperHelper.GetTempFile("paket"); using (var fileStream = FileProxy.Create(tmpFile)) { WebRequestProxy.DownloadFile(url, fileStream, HttpBufferSize); } FileProxy.Copy(tmpFile, target, true); FileProxy.Delete(tmpFile); }
public void DownloadVersion(string latestVersion, string target) { 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()); DirectoryProxy.CreateDirectory(randomFullPath); var paketPackageFile = Path.Combine(randomFullPath, paketFile); if (DirectoryProxy.Exists(NugetSource)) { if (String.IsNullOrWhiteSpace(latestVersion)) { latestVersion = GetLatestVersion(false); } var sourcePath = Path.Combine(NugetSource, String.Format(paketNupkgFileTemplate, latestVersion)); ConsoleImpl.WriteDebug("Starting download from {0}", sourcePath); FileProxy.Copy(sourcePath, paketPackageFile); } else { ConsoleImpl.WriteDebug("Starting download from {0}", paketDownloadUrl); WebRequestProxy.DownloadFile(paketDownloadUrl, paketPackageFile); } FileProxy.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.exe"); FileProxy.Copy(paketSourceFile, target, true); DirectoryProxy.Delete(randomFullPath, true); }
public void DownloadVersion(string latestVersion, string target) { var cached = Path.Combine(_paketCacheDir, latestVersion, "paket.exe"); if (!FileSystemProxy.FileExists(cached)) { ConsoleImpl.WriteDebug("Version {0} not found in cache.", latestVersion); EffectiveStrategy.DownloadVersion(latestVersion, target); FileSystemProxy.CreateDirectory(Path.GetDirectoryName(cached)); FileSystemProxy.CopyFile(target, cached); } else { ConsoleImpl.WriteDebug("Copying version {0} from cache.", latestVersion); FileSystemProxy.CopyFile(cached, target, true); } }
public string GetLatestVersion(bool ignorePrerelease) { try { return(EffectiveStrategy.GetLatestVersion(ignorePrerelease)); } catch (WebException) { if (FallbackStrategy == null) { var latestVersion = GetLatestVersionInCache(ignorePrerelease); ConsoleImpl.WriteDebug("Unable to look up the latest version online, the cache contains version {0}.", latestVersion); return(latestVersion); } throw; } }
public void SelfUpdate(string latestVersion) { string target = Assembly.GetExecutingAssembly().Location; var localVersion = FileProxy.GetLocalFileVersion(target); if (localVersion.StartsWith(latestVersion)) { ConsoleImpl.WriteDebug("Bootstrapper is up to date. Nothing to do."); return; } var apiHelper = new NugetApiHelper(PaketBootstrapperNugetPackageName, NugetSource); const string paketNupkgFile = "paket.bootstrapper.latest.nupkg"; const string paketNupkgFileTemplate = "paket.bootstrapper.{0}.nupkg"; var getLatestFromNugetUrl = apiHelper.GetLatestPackage(); var paketDownloadUrl = getLatestFromNugetUrl; var paketFile = paketNupkgFile; if (!String.IsNullOrWhiteSpace(latestVersion)) { paketDownloadUrl = apiHelper.GetSpecificPackageVersion(latestVersion); paketFile = String.Format(paketNupkgFileTemplate, latestVersion); } var randomFullPath = Path.Combine(Folder, Path.GetRandomFileName()); DirectoryProxy.CreateDirectory(randomFullPath); var paketPackageFile = Path.Combine(randomFullPath, paketFile); if (DirectoryProxy.Exists(NugetSource)) { if (String.IsNullOrWhiteSpace(latestVersion)) { latestVersion = GetLatestVersion(false); } var sourcePath = Path.Combine(NugetSource, String.Format(paketNupkgFileTemplate, latestVersion)); ConsoleImpl.WriteDebug("Starting download from {0}", sourcePath); FileProxy.Copy(sourcePath, paketPackageFile); } else { ConsoleImpl.WriteDebug("Starting download from {0}", paketDownloadUrl); WebRequestProxy.DownloadFile(paketDownloadUrl, paketPackageFile); } FileProxy.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.bootstrapper.exe"); var renamedPath = BootstrapperHelper.GetTempFile("oldBootstrapper"); try { FileProxy.FileMove(target, renamedPath); FileProxy.FileMove(paketSourceFile, target); ConsoleImpl.WriteDebug("Self update of bootstrapper was successful."); } catch (Exception) { ConsoleImpl.WriteDebug("Self update failed. Resetting bootstrapper."); FileProxy.FileMove(renamedPath, target); throw; } DirectoryProxy.Delete(randomFullPath, true); }
public void DownloadVersion(string latestVersion, string target) { 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.WriteDebug("Starting download from {0}", sourcePath); FileSystemProxy.CopyFile(sourcePath, paketPackageFile); } else { ConsoleImpl.WriteDebug("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($"Version {latestVersion} wasn't found (404)", webException); } if (response.StatusCode == HttpStatusCode.BadRequest) { // For cases like "The package version is not a valid semantic version" throw new WebException($"Unable to get version '{latestVersion}': {response.StatusDescription }", webException); } } Console.WriteLine(webException.ToString()); throw; } } FileSystemProxy.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.exe"); FileSystemProxy.CopyFile(paketSourceFile, target, true); FileSystemProxy.DeleteDirectory(randomFullPath, true); }