From 5b984af5d15da89a799e3a4cb02e315d47d28908 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Fri, 28 Aug 2015 10:54:05 -0500 Subject: [PATCH 1/2] rework github strategy to use a more direct method in the common case of just getting the latest version --- .../GitHubDownloadStrategy.cs | 38 ++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/Paket.Bootstrapper/GitHubDownloadStrategy.cs b/src/Paket.Bootstrapper/GitHubDownloadStrategy.cs index 3b188b3b48..3a3d47449e 100644 --- a/src/Paket.Bootstrapper/GitHubDownloadStrategy.cs +++ b/src/Paket.Bootstrapper/GitHubDownloadStrategy.cs @@ -22,24 +22,36 @@ public GitHubDownloadStrategy(PrepareWebClientDelegate prepareWebClient, Prepare public string GetLatestVersion(bool ignorePrerelease) { - string latestVersion = ""; + const string latest = "https://github.com/fsprojects/Paket/releases/latest"; + const string releases = "https://github.com/fsprojects/Paket/releases"; 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 == "") + if (ignorePrerelease) { - start = data.IndexOf("Paket/tree/", start) + 11; - var end = data.IndexOf("\"", start); - latestVersion = data.Substring(start, end - start); - if (latestVersion.Contains("-") && ignorePrerelease) - latestVersion = ""; + PrepareWebClient(client, latest); + var data = client.DownloadString(latest); + var title = data.Substring(data.IndexOf(""), (data.IndexOf("") + 8 - data.IndexOf(""))); // grabs everything in the <title> tag + var version = title.Split(' ')[1]; // <title>Release, 1.34.0, etc, etc, etc <-- the release number is the second part fo this split string + return version; + } + else + { + // have to iterate over the releases in the old manner. + var latestVersion = ""; + var start = 0; + PrepareWebClient(client, releases); + var data = client.DownloadString(releases); + 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 = ""; + } + return latestVersion; } } - return latestVersion; } public void DownloadVersion(string latestVersion, string target, bool silent) From f3c111aec30f1aae31acdb4435d2a25d03f26f83 Mon Sep 17 00:00:00 2001 From: Chet Husk <chet_husk@volusion.com> Date: Fri, 28 Aug 2015 13:23:44 -0500 Subject: [PATCH 2/2] refactor and cleanup different version retrieval --- .../GitHubDownloadStrategy.cs | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/Paket.Bootstrapper/GitHubDownloadStrategy.cs b/src/Paket.Bootstrapper/GitHubDownloadStrategy.cs index 3a3d47449e..a880b2f9bd 100644 --- a/src/Paket.Bootstrapper/GitHubDownloadStrategy.cs +++ b/src/Paket.Bootstrapper/GitHubDownloadStrategy.cs @@ -22,38 +22,39 @@ public GitHubDownloadStrategy(PrepareWebClientDelegate prepareWebClient, Prepare public string GetLatestVersion(bool ignorePrerelease) { - const string latest = "https://github.com/fsprojects/Paket/releases/latest"; - const string releases = "https://github.com/fsprojects/Paket/releases"; using (var client = new WebClient()) { if (ignorePrerelease) - { - PrepareWebClient(client, latest); - var data = client.DownloadString(latest); - var title = data.Substring(data.IndexOf("<title>"), (data.IndexOf("") + 8 - data.IndexOf(""))); // grabs everything in the <title> tag - var version = title.Split(' ')[1]; // <title>Release, 1.34.0, etc, etc, etc <-- the release number is the second part fo this split string - return version; - } + return GetLatestStable(client); else - { - // have to iterate over the releases in the old manner. - var latestVersion = ""; - var start = 0; - PrepareWebClient(client, releases); - var data = client.DownloadString(releases); - 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 = ""; - } - return latestVersion; - } + 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("<title>") + 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);