private void webUpdateCheck_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (this.webUpdateCheck.Url.Equals(this.getUpdateUri())) {
HtmlElement he = this.webUpdateCheck.Document.GetElementById("download");
if (he != null) {
Version ignore = null;
Version compareTo = this.screensaver.version;
//he.Get
Version update;
try {
update = new Version(he.GetAttribute("data-version"));
} catch (Exception ex) {
this.screensaver.showInfoOnMonitors("Error detecting latest version" + Environment.NewLine + ex.Message, true, true);
return;
}
if (this.getPersistantBool("ignoreUpdate")) {
try {
ignore = new Version(this.getPersistantString("ignoreVersion"));
} catch (Exception) { }
if (ignore != null && compareTo.CompareTo(ignore) < 0) {
compareTo = ignore;
}
}
if (!this.getPersistantBool("betaVersion")) {
// Revision number = 0 for alpha release,
// Revision number != 0 indicates beta / release candidate version
update = new Version(update.Major, update.Minor, update.Build);
}
this.newVersionAvailable = (compareTo.CompareTo(update) < 0);
if (this.newVersionAvailable) {
if (this.downloadUpdates) {
string downloadedUpdateLocalPath = Path.Combine(Constants.getUpdateFolder(), Path.GetFileName(he.GetAttribute("href")));
if (!File.Exists(downloadedUpdateLocalPath) || !Utils.VerifyMD5(downloadedUpdateLocalPath, he.GetAttribute("data-md5"))) {
if (File.Exists(downloadedUpdateLocalPath)) File.Delete(downloadedUpdateLocalPath);
this.showUpdateInfo("<div class='downloadProgress'><div class='downloadLabel'>Downloading update: " + update.ToString() + "</div><div class='downloadProgress' style='width: 0%'></div>");
Directory.CreateDirectory(Path.GetDirectoryName(downloadedUpdateLocalPath));//.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Constants.DownloadFolder));
WebClient client = new WebClient();
client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgress);
client.DownloadFileAsync(new Uri(he.GetAttribute("href")), downloadedUpdateLocalPath);
return;
} else {
this.DownloadFileCompleted(this, null);
}
} else {
this.showUpdateInfo("Update available<br/><a href='" + he.GetAttribute("href") + "'>Download RPS " + he.GetAttribute("data-version-text") + "</a>");
}
} else if (this.screensaver.showUpdateStatus) {
this.screensaver.showAllUpToDate();
}
}
}
}