if (!kyr.networkIsUp()) {
MessageBox.Show("You currently are not connected to the Internet.", "Cannot check for update");
return;
}
string msg = string.Empty;
string pathLastSuccessfullyCheckedForUpdate = Path.Combine(specFldrAppData, "lastUpdateCheck.txt");
if (System.IO.File.Exists(Path.Combine(specFldrAppData + "updateURL.txt"))) {
try {
updateToolStripMenuItem.Enabled = false;
Cursor = Cursors.WaitCursor;
this.Text = "Checking for update...";
string url = string.Empty;
using (StreamReader sr
= new StreamReader
(Path
.Combine(specFldrAppData
+ "updateURL.txt"))) { url = sr.ReadLine();
}
WebClient client
= new WebClient
(); try {
client.DownloadFile(url, specFldrAppData + "temp.txt");
} catch (Exception exFailedToObtain) {
MessageBox.Show("Unable to obtain update info from website at this time. Please try again later." +
Environment.NewLine + Environment.NewLine + exFailedToObtain.Message, "Try Again Later");
updateToolStripMenuItem.Enabled = true;
Cursor = Cursors.Default;
this.Text = appTitle;
return;
}
client
.DownloadProgressChanged += new DownloadProgressChangedEventHandler
(client_DownloadProgressChanged
); string downloadURL = string.Empty;
string[] parts;
using (StreamReader sr
= new StreamReader
(Path
.Combine(specFldrAppData,
"temp.txt"))) { parts = sr.ReadLine().Split('|');
string newest = parts[1].Trim();
parts = sr.ReadLine().Split('|');
downloadURL = parts[1].Trim();
pathToOnlineZippedInstaller = downloadURL;
parts = sr.ReadLine().Split('|');
expectedDownloadSize = Convert.ToInt32(parts[1]);
if (String.Compare(Application.ProductVersion.ToString(), newest) < 0) {
if (blnLoadedPrayerHasBeenModified) {
msg = "A loaded prayer has been modified. Discard it and download the available installer for an updated version of this application?";
if (DialogResult.No == MessageBox.Show(msg, "Discard modified prayer and download update?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) {
return;
}
} else {
clearMyPrayerFields();
}
if (blnWorkingOnNewPrayer) {
msg = "You're currently working on a new prayer. Discard it and download the available installer for an updated version of this application?";
if (DialogResult.No == MessageBox.Show(msg, "Discard modified prayer and download update?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)) {
return;
}
} else {
clearMyPrayerFields();
}
versionDownloading = "v" + newest;
this.Text = "Downloading newest version " + versionDownloading;
downloadProgress.Value = 0;
downloadFullpath = Path.Combine(pathToDesktop, Path.GetFileName(downloadURL));
tmrDownload.Enabled = true;
presentMyPrayersPanel();
myPrayersInterfaceToolStripMenuItem
.Checked = true; tmrDownload.Start();
_downloadUpdateBegins = DateTime.Now;
blnDownloadingUpdateInstaller = true;
client
.DownloadFileAsync(new Uri
(downloadURL
), downloadFullpath
); } else {
using (StreamWriter sw
= new StreamWriter
(pathLastSuccessfullyCheckedForUpdate
)) { sw.WriteLine(DateTime.Now.ToString());
}
this.Text = appTitle;
if (myPrayersInterfaceToolStripMenuItem
.Checked) { this.Text += " (\"My Prayers\" interface) ";
}
MessageBox.Show("You are using the most recent version of the program: " +
Application.ProductVersion.ToString(), "No update is currently available");
this.Text = appTitle;
}
}
} catch (Exception exUpdate) {
updateToolStripMenuItem.Enabled = true;
blnDownloadingUpdateInstaller = false;
Cursor = Cursors.Default;
string errMsg = exUpdate.Message;
if ((exUpdate.Message.Contains("outside the bounds")) || (exUpdate.Message.Contains("remote name could not be resolved"))) {
errMsg = "\"Prayer Minder\" was unable to connect to the download server to check for an available update at this time.";
}
MessageBox.Show(errMsg, "Error while seeking available program update");
}
finally {
}
} else {
MessageBox.Show("\"Prayer Minder\" couldn't retrieve the URL to look for updates. Please contact the programmer.", "Failed to obtain update info");
}
updateToolStripMenuItem.Enabled = true;
Cursor = Cursors.Default;
}