Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mjohne authored Nov 26, 2018
1 parent a3ae3fe commit 5a8270c
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 301 deletions.
166 changes: 102 additions & 64 deletions PlanetoidDB/CheckMpcorbDatForm.Designer.cs

Large diffs are not rendered by default.

48 changes: 47 additions & 1 deletion PlanetoidDB/CheckMpcorbDatForm.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.IO;
using System.Net;
using System.Windows.Forms;

namespace Planetoid_DB
Expand All @@ -22,7 +24,25 @@ public partial class CheckMpcorbDatForm : Form
/// <param name="e"></param>
private void CheckMpcorbDatForm_Load(object sender, EventArgs e)
{

Uri uriMPCORB = new Uri(uriString: Properties.Resources.strMpcorbUrl);
DateTime
datetimeFileLocal = DateTime.MinValue,
datetimeFileOnline = GetLastModified(uri: uriMPCORB);
if (!File.Exists(path: Properties.Resources.strFilenameMPCORB))
{
labelContentLengthValueLocal.Text = I10nStrings.strNoFileFoundText;
labelModifiedDateValueLocal.Text = I10nStrings.strNoFileFoundText;
}
else
{
FileInfo fileInfo = new FileInfo(fileName: Properties.Resources.strFilenameMPCORB);
datetimeFileLocal = fileInfo.LastWriteTime;
labelContentLengthValueLocal.Text = fileInfo.Length.ToString() + " " + I10nStrings.strBytesText;
labelModifiedDateValueLocal.Text = datetimeFileLocal.ToString();
}
labelContentLengthValueOnline.Text = GetContentLength(uri: uriMPCORB).ToString() + " " + I10nStrings.strBytesText;
labelModifiedDateValueOnline.Text = datetimeFileOnline.ToString();
labelIsUpdateNeeded.Text = datetimeFileOnline > datetimeFileLocal ? I10nStrings.strUpdateRecommendedText : I10nStrings.strNoUpdateNeededText;
}

/// <summary>
Expand Down Expand Up @@ -63,6 +83,32 @@ private void SetLabelText(string text)
labelHelp.Text = text;
}

/// <summary>
///
/// </summary>
/// <param name="uri"></param>
/// <returns></returns>
private DateTime GetLastModified(Uri uri)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestUri: uri);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
resp.Close();
return resp.LastModified;
}

/// <summary>
///
/// </summary>
/// <param name="uri"></param>
/// <returns></returns>
private long GetContentLength(Uri uri)
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestUri: uri);
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
resp.Close();
return Convert.ToInt64(value: resp.ContentLength);
}

#endregion

#region Click-Eventhandler
Expand Down
60 changes: 30 additions & 30 deletions PlanetoidDB/DatabaseInformationForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 24 additions & 45 deletions PlanetoidDB/DownloadUpdateForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using System.Windows.Forms;

namespace Planetoid_DB
Expand Down Expand Up @@ -46,7 +47,12 @@ private void DownloadUpdateForm_Load(object sender, EventArgs e)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DownloadUpdateForm_FormClosed(object sender, FormClosedEventArgs e) => this.Dispose();
private void DownloadUpdateForm_FormClosed(object sender, FormClosedEventArgs e)
{
webClient.CancelAsync();
webClient.Dispose();
this.Dispose();
}

/// <summary>
///
Expand Down Expand Up @@ -99,49 +105,6 @@ private void Completed(object sender, AsyncCompletedEventArgs e)
}
}

/// <summary>
///
/// </summary>
private void CheckMpcorbDat()
{
DateTime datetimeFileLocal = DateTime.MinValue;
DateTime datetimeFileOnline = GetLastModified(uri: uriMPCORB);
string strInfoMpcorbDatLocal = I10nStrings.strInfoMpcorbDatLocal + ":\n\r\n\r";
if (File.Exists(path: strFilenameMPCORB))
{
FileInfo fileInfo = new FileInfo(fileName: strFilenameMPCORB);
long fileSize = fileInfo.Length;
datetimeFileLocal = fileInfo.LastWriteTime;
datetimeFileOnline = GetLastModified(uri: uriMPCORB);
strInfoMpcorbDatLocal = strInfoMpcorbDatLocal + " " + I10nStrings.strUrlText + ": " + fileInfo.FullName;
strInfoMpcorbDatLocal = strInfoMpcorbDatLocal + "\n\r " + I10nStrings.strContenLenghtText + ": " + fileSize.ToString() + " " + I10nStrings.strBytesText;
strInfoMpcorbDatLocal = strInfoMpcorbDatLocal + "\n\r " + I10nStrings.strLastModifiedText + ": " + datetimeFileLocal;
}
else
{
strInfoMpcorbDatLocal = strInfoMpcorbDatLocal + " " + I10nStrings.strNoFileFoundText;
}

string strInfoMpcorbDatOnline = I10nStrings.strInfoMpcorbDatOnline + ":\n\r\n\r";
strInfoMpcorbDatOnline = strInfoMpcorbDatOnline + " " + I10nStrings.strUrlText + ": " + uriMPCORB;
strInfoMpcorbDatOnline = strInfoMpcorbDatOnline + "\n\r " + I10nStrings.strContenLenghtText + ": " + GetContentLength(uri: uriMPCORB).ToString() + " " + I10nStrings.strBytesText;
strInfoMpcorbDatOnline = strInfoMpcorbDatOnline + "\n\r " + I10nStrings.strLastModifiedText + ": " + datetimeFileOnline;

string strUpdate = "";
MessageBoxIcon mbi = MessageBoxIcon.None;
if (datetimeFileOnline > datetimeFileLocal)
{
strUpdate = I10nStrings.strUpdateAvailabletText;
mbi = MessageBoxIcon.Warning;
}
else
{
strUpdate = I10nStrings.strNoUpdateNeededText;
mbi = MessageBoxIcon.Information;
}
MessageBox.Show(text: strInfoMpcorbDatLocal + "\n\r\n\r" + strInfoMpcorbDatOnline + "\n\r\n\r" + strUpdate, caption: I10nStrings.strMpcorbDatInformationCaption, buttons: MessageBoxButtons.OK, icon: mbi);
}

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -195,6 +158,22 @@ private void SetLabelText(string text)
labelHelp.Text = text;
}

/// <summary>
///
/// </summary>
private void ShowMpcorbDatCheck()
{
if (!NetworkInterface.GetIsNetworkAvailable())
{
MessageBox.Show(text: I10nStrings.strNoInternetConnectionText, caption: I10nStrings.strErrorCaption, buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error);
}
else
{
CheckMpcorbDatForm formCeckMpcorbDat = new CheckMpcorbDatForm();
formCeckMpcorbDat.ShowDialog();
}
}

#region Enter-Eventhandler

/// <summary>
Expand Down Expand Up @@ -453,7 +432,7 @@ private void DownloadUpdateForm_FormClosing(object sender, FormClosingEventArgs
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCheckForUpdate_Click(object sender, EventArgs e) => CheckMpcorbDat();
private void ButtonCheckForUpdate_Click(object sender, EventArgs e) => ShowMpcorbDatCheck();

#endregion

Expand Down
Loading

0 comments on commit 5a8270c

Please sign in to comment.