about: cleanup

This commit is contained in:
Hylke Bons 2012-10-22 14:46:18 +01:00
parent df25a6c2a3
commit 94668c5a99

View file

@ -19,8 +19,6 @@ using System;
using System.Net; using System.Net;
using System.Threading; using System.Threading;
using SparkleLib;
namespace SparkleShare { namespace SparkleShare {
public class SparkleAboutController { public class SparkleAboutController {
@ -40,7 +38,7 @@ namespace SparkleShare {
public string RunningVersion { public string RunningVersion {
get { get {
return SparkleBackend.Version; return SparkleLib.SparkleBackend.Version;
} }
} }
@ -49,7 +47,7 @@ namespace SparkleShare {
{ {
Program.Controller.ShowAboutWindowEvent += delegate { Program.Controller.ShowAboutWindowEvent += delegate {
ShowWindowEvent (); ShowWindowEvent ();
CheckForNewVersion (); new Thread (() => CheckForNewVersion ()).Start ();
}; };
} }
@ -63,72 +61,20 @@ namespace SparkleShare {
private void CheckForNewVersion () private void CheckForNewVersion ()
{ {
CheckingForNewVersionEvent (); CheckingForNewVersionEvent ();
Thread.Sleep (500);
WebClient web_client = new WebClient (); WebClient web_client = new WebClient ();
Uri uri = new Uri ("http://www.sparkleshare.org/version"); Uri uri = new Uri ("http://www.sparkleshare.org/version");
web_client.DownloadStringCompleted += delegate (object o, DownloadStringCompletedEventArgs args) { try {
if (args.Error != null) string latest_version = web_client.DownloadString (uri);
return;
if (new Version (latest_version) > new Version (RunningVersion))
string latest_version_string = args.Result.Trim (); NewVersionEvent (latest_version);
Thread.Sleep (750);
if (UpdateRequired (RunningVersion, latest_version_string))
NewVersionEvent (latest_version_string);
else else
VersionUpToDateEvent (); VersionUpToDateEvent ();
}; } catch {
web_client.DownloadStringAsync (uri);
}
private bool UpdateRequired (string running_version_string, string latest_version_string)
{
if (running_version_string == null)
throw new ArgumentNullException ("running_version_string");
if (string.IsNullOrWhiteSpace (running_version_string))
throw new ArgumentException ("running_version_string");
if (latest_version_string == null)
throw new ArgumentNullException ("latest_version_string");
if (string.IsNullOrWhiteSpace (latest_version_string))
throw new ArgumentException ("latest_version_string");
int running_major;
int running_minor;
int running_micro;
try {
string [] running_split = running_version_string.Split ('.');
running_major = int.Parse (running_split [0]);
running_minor = int.Parse (running_split [1]);
running_micro = int.Parse (running_split [2]);
} catch (Exception e) {
throw new FormatException ("running_version_string", e);
} }
int latest_major;
int latest_minor;
int latest_micro;
try {
string [] latest_split = latest_version_string.Split ('.');
latest_major = int.Parse (latest_split [0]);
latest_minor = int.Parse (latest_split [1]);
latest_micro = int.Parse (latest_split [2]);
} catch (Exception e) {
throw new FormatException ("latest_version_string", e);
}
bool higher_major = latest_major > running_major;
bool higher_minor = latest_major == running_major && latest_minor > running_minor;
bool higher_micro = latest_major == running_major && latest_minor == running_minor && latest_micro > running_micro;
return (higher_major || higher_minor || higher_micro);
} }
} }
} }