/SparkleShare/SparkleAboutController.cs
C# | 78 lines | 44 code | 19 blank | 15 comment | 1 complexity | b51d91b4f901f32501475f3596a6d22e MD5 | raw file
1// SparkleShare, a collaboration and sharing tool. 2// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com> 3// 4// This program is free software: you can redistribute it and/or modify 5// it under the terms of the GNU General Public License as published by 6// the Free Software Foundation, either version 3 of the License, or 7// (at your option) any later version. 8// 9// This program is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13// 14// You should have received a copy of the GNU General Public License 15// along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 18using System; 19using System.Net; 20using System.Threading; 21 22namespace SparkleShare { 23 24 public class SparkleAboutController { 25 26 public event Action ShowWindowEvent = delegate { }; 27 public event Action HideWindowEvent = delegate { }; 28 29 public event UpdateLabelEventDelegate UpdateLabelEvent = delegate { }; 30 public delegate void UpdateLabelEventDelegate (string text); 31 32 public readonly string WebsiteLinkAddress = "http://www.sparkleshare.org/"; 33 public readonly string CreditsLinkAddress = "http://github.com/hbons/SparkleShare/blob/master/legal/Authors.txt"; 34 public readonly string ReportProblemLinkAddress = "http://www.github.com/hbons/SparkleShare/issues"; 35 public readonly string DebugLogLinkAddress = "file://" + Program.Controller.Config.LogFilePath; 36 37 public string RunningVersion; 38 39 40 public SparkleAboutController () 41 { 42 RunningVersion = SparkleLib.SparkleBackend.Version; 43 44 Program.Controller.ShowAboutWindowEvent += delegate { 45 ShowWindowEvent (); 46 new Thread (() => CheckForNewVersion ()).Start (); 47 }; 48 } 49 50 51 public void WindowClosed () 52 { 53 HideWindowEvent (); 54 } 55 56 57 private void CheckForNewVersion () 58 { 59 UpdateLabelEvent ("Checking for updates..."); 60 Thread.Sleep (500); 61 62 WebClient web_client = new WebClient (); 63 Uri uri = new Uri ("http://www.sparkleshare.org/version"); 64 65 try { 66 string latest_version = web_client.DownloadString (uri).Trim (); 67 68 if (new Version (latest_version) > new Version (RunningVersion)) 69 UpdateLabelEvent ("A newer version (" + latest_version + ") is available!"); 70 else 71 UpdateLabelEvent ("You are running the latest version."); 72 73 } catch { 74 UpdateLabelEvent ("Version check failed."); 75 } 76 } 77 } 78}