1
0

UpdateThread.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using GeekDesk.Constant;
  2. using GeekDesk.Util;
  3. using GeekDesk.ViewModel;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Configuration;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. namespace GeekDesk.Thread
  13. {
  14. public class UpdateThread
  15. {
  16. private static AppConfig appConfig = MainWindow.appData.AppConfig;
  17. public static void Update()
  18. {
  19. System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(UpdateApp))
  20. {
  21. IsBackground = true
  22. };
  23. t.Start();
  24. }
  25. private static void UpdateApp()
  26. {
  27. try
  28. {
  29. string updateUrl;
  30. string nowVersion = ConfigurationManager.AppSettings["Version"];
  31. switch (appConfig.UpdateType)
  32. {
  33. case UpdateType.GitHub:
  34. updateUrl = ConfigurationManager.AppSettings["GitHubUpdateUrl"];
  35. break;
  36. default:
  37. updateUrl = ConfigurationManager.AppSettings["GiteeUpdateUrl"];
  38. break;
  39. }
  40. string updateInfo = HttpUtil.Get(updateUrl);
  41. if (!StringUtil.IsEmpty(updateInfo))
  42. {
  43. JObject jo = JObject.Parse(updateInfo);
  44. string onlineVersion = jo["version"].ToString();
  45. if (onlineVersion.CompareTo(nowVersion) > 0)
  46. {
  47. //检测到版本更新
  48. }
  49. }
  50. } catch (Exception)
  51. {
  52. }
  53. }
  54. }
  55. }