public bool GetLastVersion(string currentVersion)
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create (serverUrl + "/version");
// Set the Method property of the request to GET.
request.Method = "GET";
// Set the ContentType property of the WebRequest.
//request.ContentType = "application/x-www-form-urlencoded";
HttpWebResponse response;
try {
response = (HttpWebResponse) request.GetResponse();
} catch {
this.ResultMessage =
Catalog.GetString("Could not get last version.") + "\n" +
string.Format(Catalog.GetString("You are not connected to the Internet\nor {0} server is down."),
serverUrl);
return false;
}
string responseFromServer;
using (var sr = new StreamReader(response.GetResponseStream()))
{
responseFromServer = sr.ReadToEnd();
}
//this prints:
// {"stable": "1.4.9"}
//this.ResultMessage = "Last version published: " + responseFromServer;
string [] strFull = responseFromServer.Split(new char[] {':'});
int startPos = strFull[1].IndexOf('"') +1;
int endPos = strFull[1].LastIndexOf('"') -2;
string lastVersionPublished = strFull[1].Substring(startPos,endPos); //1.4.9
string updateStr = "";
if(currentVersion != lastVersionPublished)
updateStr = "\n\n" + Catalog.GetString("Update software at ") + "www.chronojump.org";
this.ResultMessage =
Catalog.GetString("Installed version is: ") + currentVersion + "\n" +
Catalog.GetString("Last version published: ") + lastVersionPublished +
updateStr;
//ChronojumpUpdated = (currentVersion == ResultMessage);
return true;
}