UpdateThread.cs 2.0 KB

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