UpdateWindow.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.Diagnostics;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Imaging;
  19. using System.Windows.Shapes;
  20. namespace GeekDesk.Control.Windows
  21. {
  22. /// <summary>
  23. /// UpdateWindow.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class UpdateWindow : Window
  26. {
  27. private static AppConfig appConfig = MainWindow.appData.AppConfig;
  28. private static string githubUrl = "";
  29. private static string giteeUrl = "";
  30. private UpdateWindow(JObject jo)
  31. {
  32. try
  33. {
  34. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  35. InitializeComponent();
  36. DataHandle(jo);
  37. }
  38. catch (Exception)
  39. {
  40. }
  41. }
  42. /// <summary>
  43. /// 移动窗口
  44. /// </summary>
  45. /// <param name="sender"></param>
  46. /// <param name="e"></param>
  47. private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
  48. {
  49. if (e.LeftButton == MouseButtonState.Pressed)
  50. {
  51. DragMove();
  52. }
  53. }
  54. private void DataHandle(JObject jo)
  55. {
  56. Title.Text = StringUtil.IsEmpty(jo["title"]) ? "" : jo["title"].ToString();
  57. SubTitle.Text = StringUtil.IsEmpty(jo["subTitle"]) ? "" : jo["subTitle"].ToString();
  58. MsgTitle.Text = StringUtil.IsEmpty(jo["msgTitle"]) ? "" : jo["msgTitle"].ToString();
  59. JArray ja = JArray.Parse(StringUtil.IsEmpty(jo["msg"]) ? "[]" : jo["msg"].ToString());
  60. githubUrl = StringUtil.IsEmpty(jo["githubUrl"]) ? ConfigurationManager.AppSettings["GitHubUrl"] : jo["githubUrl"].ToString();
  61. giteeUrl = StringUtil.IsEmpty(jo["giteeUrl"]) ? ConfigurationManager.AppSettings["GiteeUrl"] : jo["giteeUrl"].ToString();
  62. string msg = "";
  63. for (int i=0; i<ja.Count; i++)
  64. {
  65. msg += "•" + ja[i].ToString() + "\n";
  66. }
  67. Msg.Text = msg;
  68. }
  69. private void Close_Click(object sender, RoutedEventArgs e)
  70. {
  71. this.Close();
  72. }
  73. private void Confirm_Click(object sender, RoutedEventArgs e)
  74. {
  75. string packageUrl;
  76. switch (appConfig.UpdateType)
  77. {
  78. case UpdateType.GitHub:
  79. packageUrl = githubUrl;
  80. break;
  81. default:
  82. packageUrl = giteeUrl;
  83. break;
  84. }
  85. Process.Start(packageUrl);
  86. this.Close();
  87. }
  88. private static System.Windows.Window window = null;
  89. public static void Show(JObject jo)
  90. {
  91. if (window == null || !window.Activate())
  92. {
  93. window = new UpdateWindow(jo);
  94. }
  95. window.Show();
  96. }
  97. }
  98. }