/SparkleShare/SparkleAboutController.cs

http://github.com/hbons/SparkleShare · 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. using System;
  17. using System.Net;
  18. using System.Threading;
  19. namespace SparkleShare {
  20. public class SparkleAboutController {
  21. public event Action ShowWindowEvent = delegate { };
  22. public event Action HideWindowEvent = delegate { };
  23. public event UpdateLabelEventDelegate UpdateLabelEvent = delegate { };
  24. public delegate void UpdateLabelEventDelegate (string text);
  25. public readonly string WebsiteLinkAddress = "http://www.sparkleshare.org/";
  26. public readonly string CreditsLinkAddress = "http://github.com/hbons/SparkleShare/blob/master/legal/Authors.txt";
  27. public readonly string ReportProblemLinkAddress = "http://www.github.com/hbons/SparkleShare/issues";
  28. public readonly string DebugLogLinkAddress = "file://" + Program.Controller.Config.LogFilePath;
  29. public string RunningVersion;
  30. public SparkleAboutController ()
  31. {
  32. RunningVersion = SparkleLib.SparkleBackend.Version;
  33. Program.Controller.ShowAboutWindowEvent += delegate {
  34. ShowWindowEvent ();
  35. new Thread (() => CheckForNewVersion ()).Start ();
  36. };
  37. }
  38. public void WindowClosed ()
  39. {
  40. HideWindowEvent ();
  41. }
  42. private void CheckForNewVersion ()
  43. {
  44. UpdateLabelEvent ("Checking for updates...");
  45. Thread.Sleep (500);
  46. WebClient web_client = new WebClient ();
  47. Uri uri = new Uri ("http://www.sparkleshare.org/version");
  48. try {
  49. string latest_version = web_client.DownloadString (uri).Trim ();
  50. if (new Version (latest_version) > new Version (RunningVersion))
  51. UpdateLabelEvent ("A newer version (" + latest_version + ") is available!");
  52. else
  53. UpdateLabelEvent ("You are running the latest version.");
  54. } catch {
  55. UpdateLabelEvent ("Version check failed.");
  56. }
  57. }
  58. }
  59. }