public string GetLatestVersion(bool ignorePrerelease) { IEnumerable <string> allVersions = null; if (DirectoryProxy.Exists(NugetSource)) { var paketPrefix = "paket."; allVersions = DirectoryProxy. EnumerateFiles(NugetSource, "paket.*.nupkg", SearchOption.TopDirectoryOnly). Select(x => Path.GetFileNameWithoutExtension(x)). // If the specified character isn't a digit, then the file // likely contains the bootstrapper or paket.core Where(x => x.Length > paketPrefix.Length && Char.IsDigit(x[paketPrefix.Length])). Select(x => x.Substring(paketPrefix.Length)); } else { var apiHelper = new NugetApiHelper(PaketNugetPackageName, NugetSource); var versionRequestUrl = apiHelper.GetAllPackageVersions(!ignorePrerelease); var versions = WebRequestProxy.DownloadString(versionRequestUrl); allVersions = versions. Trim('[', ']'). Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries). Select(x => x.Trim('"')); } var latestVersion = allVersions. Select(SemVer.Create). Where(x => !ignorePrerelease || (x.PreRelease == null)). OrderBy(x => x). LastOrDefault(x => !String.IsNullOrWhiteSpace(x.Original)); return(latestVersion != null ? latestVersion.Original : String.Empty); }
public void DownloadVersion(string latestVersion, string target, bool silent) { var apiHelper = new NugetApiHelper(PaketNugetPackageName, NugetSource); using (WebClient client = new WebClient()) { const string paketNupkgFile = "paket.latest.nupkg"; const string paketNupkgFileTemplate = "paket.{0}.nupkg"; var paketDownloadUrl = apiHelper.GetLatestPackage(); var paketFile = paketNupkgFile; if (latestVersion != String.Empty) { paketDownloadUrl = apiHelper.GetSpecificPackageVersion(latestVersion); paketFile = String.Format(paketNupkgFileTemplate, latestVersion); } var randomFullPath = Path.Combine(Folder, Path.GetRandomFileName()); Directory.CreateDirectory(randomFullPath); var paketPackageFile = Path.Combine(randomFullPath, paketFile); if (!silent) { Console.WriteLine("Starting download from {0}", paketDownloadUrl); } PrepareWebClient(client, paketDownloadUrl); client.DownloadFile(paketDownloadUrl, paketPackageFile); ZipFile.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.exe"); File.Copy(paketSourceFile, target, true); Directory.Delete(randomFullPath, true); } }
public void DownloadVersion(string latestVersion, string target, bool silent) { var apiHelper = new NugetApiHelper(PaketNugetPackageName, NugetSource); using (WebClient client = new WebClient()) { const string paketNupkgFile = "paket.latest.nupkg"; const string paketNupkgFileTemplate = "paket.{0}.nupkg"; var paketDownloadUrl = apiHelper.GetLatestPackage(); var paketFile = paketNupkgFile; if (latestVersion != String.Empty) { paketDownloadUrl = apiHelper.GetSpecificPackageVersion(latestVersion); paketFile = String.Format(paketNupkgFileTemplate, latestVersion); } var randomFullPath = Path.Combine(Folder, Path.GetRandomFileName()); Directory.CreateDirectory(randomFullPath); var paketPackageFile = Path.Combine(randomFullPath, paketFile); if (!silent) Console.WriteLine("Starting download from {0}", paketDownloadUrl); PrepareWebClient(client, paketDownloadUrl); client.DownloadFile(paketDownloadUrl, paketPackageFile); ZipFile.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.exe"); File.Copy(paketSourceFile, target, true); Directory.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()); 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 string GetLatestVersion(bool ignorePrerelease) { var apiHelper = new NugetApiHelper(PaketNugetPackageName); using (var client = new WebClient()) { var versionRequestUrl = apiHelper.GetAllPackageVersions(!ignorePrerelease); PrepareWebClient(client, versionRequestUrl); var versions = client.DownloadString(versionRequestUrl); var latestVersion = versions. Trim('[', ']'). Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries). Select(x => x.Trim('"')). Select(x => GetSemVer(x)). OrderBy(x => x). LastOrDefault(x => !String.IsNullOrWhiteSpace(x.Original)); return latestVersion != null ? latestVersion.Original : String.Empty; } }
public string GetLatestVersion(bool ignorePrerelease) { var apiHelper = new NugetApiHelper(PaketNugetPackageName, NugetSource); using (var client = new WebClient()) { var versionRequestUrl = apiHelper.GetAllPackageVersions(!ignorePrerelease); PrepareWebClient(client, versionRequestUrl); var versions = client.DownloadString(versionRequestUrl); var latestVersion = versions. Trim('[', ']'). Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries). Select(x => x.Trim('"')). Select(SemVer.Create). OrderBy(x => x). LastOrDefault(x => !String.IsNullOrWhiteSpace(x.Original)); return(latestVersion != null ? latestVersion.Original : String.Empty); } }
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 SelfUpdate(string latestVersion, bool silent) { var executingAssembly = Assembly.GetExecutingAssembly(); string target = executingAssembly.Location; var localVersion = BootstrapperHelper.GetLocalFileVersion(target); if (localVersion.StartsWith(latestVersion)) { if (!silent) Console.WriteLine("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()); Directory.CreateDirectory(randomFullPath); var paketPackageFile = Path.Combine(randomFullPath, paketFile); if (Directory.Exists(NugetSource)) { if (String.IsNullOrWhiteSpace(latestVersion)) latestVersion = this.GetLatestVersion(false); var sourcePath = Path.Combine(NugetSource, String.Format(paketNupkgFileTemplate, latestVersion)); if (!silent) Console.WriteLine("Starting download from {0}", sourcePath); File.Copy(sourcePath, paketPackageFile); } else { if (!silent) Console.WriteLine("Starting download from {0}", paketDownloadUrl); using (var client = new WebClient()) { PrepareWebClient(client, paketDownloadUrl); client.DownloadFile(paketDownloadUrl, paketPackageFile); } } ZipFile.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.bootstrapper.exe"); var renamedPath = Path.GetTempFileName(); try { BootstrapperHelper.FileMove(target, renamedPath); BootstrapperHelper.FileMove(paketSourceFile, target); if (!silent) Console.WriteLine("Self update of bootstrapper was successful."); } catch (Exception) { if (!silent) Console.WriteLine("Self update failed. Resetting bootstrapper."); BootstrapperHelper.FileMove(renamedPath, target); throw; } Directory.Delete(randomFullPath, true); }
public string GetLatestVersion(bool ignorePrerelease) { if (Directory.Exists(NugetSource)) { var paketPrefix = "paket."; var latestLocalVersion = Directory.EnumerateFiles(NugetSource, "paket.*.nupkg", SearchOption.TopDirectoryOnly). Select(x => Path.GetFileNameWithoutExtension(x)). // If the specified character isn't a digit, then the file // likely contains the bootstrapper or paket.core Where(x => x.Length > paketPrefix.Length && Char.IsDigit(x[paketPrefix.Length])). Select(x => x.Substring(paketPrefix.Length)). Select(SemVer.Create). Where(x => !ignorePrerelease || (x.PreRelease == null)). OrderBy(x => x). LastOrDefault(x => !String.IsNullOrWhiteSpace(x.Original)); return latestLocalVersion != null ? latestLocalVersion.Original : String.Empty; } else { var apiHelper = new NugetApiHelper(PaketNugetPackageName, NugetSource); using (var client = new WebClient()) { var versionRequestUrl = apiHelper.GetAllPackageVersions(!ignorePrerelease); PrepareWebClient(client, versionRequestUrl); var versions = client.DownloadString(versionRequestUrl); var latestVersion = versions. Trim('[', ']'). Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries). Select(x => x.Trim('"')). Select(SemVer.Create). OrderBy(x => x). LastOrDefault(x => !String.IsNullOrWhiteSpace(x.Original)); return latestVersion != null ? latestVersion.Original : String.Empty; } } }
protected override void DownloadVersionCore(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.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; } } FileSystemProxy.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.exe"); FileSystemProxy.CopyFile(paketSourceFile, target, true); FileSystemProxy.DeleteDirectory(randomFullPath, true); }
public void SelfUpdate(string latestVersion, bool silent) { var executingAssembly = Assembly.GetExecutingAssembly(); string target = executingAssembly.Location; var localVersion = BootstrapperHelper.GetLocalFileVersion(target); if (localVersion.StartsWith(latestVersion)) { if (!silent) { Console.WriteLine("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 (latestVersion != String.Empty) { paketDownloadUrl = apiHelper.GetSpecificPackageVersion(latestVersion); paketFile = String.Format(paketNupkgFileTemplate, latestVersion); } var randomFullPath = Path.Combine(Folder, Path.GetRandomFileName()); Directory.CreateDirectory(randomFullPath); var paketPackageFile = Path.Combine(randomFullPath, paketFile); if (!silent) { Console.WriteLine("Starting download from {0}", paketDownloadUrl); } using (var client = new WebClient()) { PrepareWebClient(client, paketDownloadUrl); client.DownloadFile(paketDownloadUrl, paketPackageFile); } ZipFile.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.bootstrapper.exe"); var renamedPath = Path.GetTempFileName(); try { BootstrapperHelper.FileMove(target, renamedPath); BootstrapperHelper.FileMove(paketSourceFile, target); if (!silent) { Console.WriteLine("Self update of bootstrapper was successful."); } } catch (Exception) { if (!silent) { Console.WriteLine("Self update failed. Resetting bootstrapper."); } BootstrapperHelper.FileMove(renamedPath, target); throw; } Directory.Delete(randomFullPath, true); }
protected override void DownloadVersionCore(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.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; } } FileSystemProxy.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.exe"); FileSystemProxy.CopyFile(paketSourceFile, target, true); FileSystemProxy.DeleteDirectory(randomFullPath, true); }
protected override void SelfUpdateCore(string latestVersion) { string target = Assembly.GetExecutingAssembly().Location; var localVersion = FileSystemProxy.GetLocalFileVersion(target); if (localVersion.StartsWith(latestVersion)) { ConsoleImpl.WriteInfo("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()); 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); WebRequestProxy.DownloadFile(paketDownloadUrl, paketPackageFile); } FileSystemProxy.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.bootstrapper.exe"); var renamedPath = BootstrapperHelper.GetTempFile("oldBootstrapper"); try { FileSystemProxy.MoveFile(target, renamedPath); FileSystemProxy.MoveFile(paketSourceFile, target); ConsoleImpl.WriteInfo("Self update of bootstrapper was successful."); } catch (Exception) { ConsoleImpl.WriteInfo("Self update failed. Resetting bootstrapper."); FileSystemProxy.MoveFile(renamedPath, target); throw; } FileSystemProxy.DeleteDirectory(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()); 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); }