diff --git a/src/Paket.Bootstrapper/GitHubDownloadStrategy.cs b/src/Paket.Bootstrapper/GitHubDownloadStrategy.cs index 3b188b3b48..a880b2f9bd 100644 --- a/src/Paket.Bootstrapper/GitHubDownloadStrategy.cs +++ b/src/Paket.Bootstrapper/GitHubDownloadStrategy.cs @@ -22,26 +22,39 @@ public GitHubDownloadStrategy(PrepareWebClientDelegate prepareWebClient, Prepare public string GetLatestVersion(bool ignorePrerelease) { - string latestVersion = ""; using (var client = new WebClient()) { - const string releasesUrl = "https://github.com/fsprojects/Paket/releases"; - PrepareWebClient(client, releasesUrl); - - var data = client.DownloadString(releasesUrl); - var start = 0; - while (latestVersion == "") - { - start = data.IndexOf("Paket/tree/", start) + 11; - var end = data.IndexOf("\"", start); - latestVersion = data.Substring(start, end - start); - if (latestVersion.Contains("-") && ignorePrerelease) - latestVersion = ""; - } + if (ignorePrerelease) + return GetLatestStable(client); + else + return GetLatestPrerelease(client); } + } + + private string GetLatestPrerelease(WebClient client) + { + const string releases = "https://github.com/fsprojects/Paket/releases"; + // get the first release on this page + var latestVersion = ""; + var start = 0; + PrepareWebClient(client, releases); + var data = client.DownloadString(releases); + start = data.IndexOf("Paket/tree/", start) + 11; + var end = data.IndexOf("\"", start); + latestVersion = data.Substring(start, end - start); return latestVersion; } + private string GetLatestStable(WebClient client) + { + const string latest = "https://github.com/fsprojects/Paket/releases/latest"; + PrepareWebClient(client, latest); + var data = client.DownloadString(latest); + var title = data.Substring(data.IndexOf("") + 7, (data.IndexOf("") + 8 - data.IndexOf("") + 7)); // grabs everything in the <title> tag + var version = title.Split(' ')[1]; // Release, 1.34.0, etc, etc, etc <-- the release number is the second part fo this split string + return version; + } + public void DownloadVersion(string latestVersion, string target, bool silent) { var url = String.Format("https://github.com/fsprojects/Paket/releases/download/{0}/paket.exe", latestVersion);