OtherControl.xaml.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using GeekDesk.Constant;
  2. using GeekDesk.MyThread;
  3. using GeekDesk.Util;
  4. using GeekDesk.ViewModel;
  5. using ShowSeconds;
  6. using System;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Management;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Input;
  13. namespace GeekDesk.Control.UserControls.Config
  14. {
  15. /// <summary>
  16. /// OtherControl.xaml 的交互逻辑
  17. /// </summary>
  18. public partial class OtherControl : UserControl
  19. {
  20. public OtherControl()
  21. {
  22. InitializeComponent();
  23. this.Loaded += OtherControl_Loaded;
  24. }
  25. private void OtherControl_Loaded(object sender, RoutedEventArgs e)
  26. {
  27. Sort_Check();
  28. }
  29. private void SelfStartUpBox_Click(object sender, RoutedEventArgs e)
  30. {
  31. AppConfig appConfig = MainWindow.appData.AppConfig;
  32. RegisterUtil.SetSelfStarting(appConfig.SelfStartUp, Constants.MY_NAME);
  33. }
  34. /// <summary>
  35. /// 移动窗口
  36. /// </summary>
  37. /// <param name="sender"></param>
  38. /// <param name="e"></param>
  39. private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
  40. {
  41. if (e.LeftButton == MouseButtonState.Pressed)
  42. {
  43. Window.GetWindow(this).DragMove();
  44. }
  45. }
  46. private void SortType_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  47. {
  48. RadioButton rb = sender as RadioButton;
  49. SortType type = (SortType)int.Parse(rb.Tag.ToString());
  50. SortType resType = type;
  51. switch (type)
  52. {
  53. case SortType.CUSTOM:
  54. break;
  55. case SortType.COUNT_UP:
  56. if (rb.IsChecked == true)
  57. {
  58. CountLowSort.IsChecked = true;
  59. CountUpSort.Visibility = Visibility.Collapsed;
  60. CountLowSort.Visibility = Visibility.Visible;
  61. resType = SortType.COUNT_LOW;
  62. }
  63. break;
  64. case SortType.COUNT_LOW:
  65. if (rb.IsChecked == true)
  66. {
  67. CountUpSort.IsChecked = true;
  68. CountLowSort.Visibility = Visibility.Collapsed;
  69. CountUpSort.Visibility = Visibility.Visible;
  70. resType = SortType.COUNT_UP;
  71. }
  72. break;
  73. case SortType.NAME_UP:
  74. if (rb.IsChecked == true)
  75. {
  76. NameLowSort.IsChecked = true;
  77. NameUpSort.Visibility = Visibility.Collapsed;
  78. NameLowSort.Visibility = Visibility.Visible;
  79. resType = SortType.NAME_LOW;
  80. }
  81. break;
  82. case SortType.NAME_LOW:
  83. if (rb.IsChecked == true)
  84. {
  85. NameUpSort.IsChecked = true;
  86. NameLowSort.Visibility = Visibility.Collapsed;
  87. NameUpSort.Visibility = Visibility.Visible;
  88. resType = SortType.NAME_UP;
  89. }
  90. break;
  91. }
  92. MainWindow.appData.AppConfig.IconSortType = resType;
  93. CommonCode.SortIconList();
  94. }
  95. private void Sort_Check()
  96. {
  97. if (NameLowSort.IsChecked == true)
  98. {
  99. NameUpSort.Visibility = Visibility.Collapsed;
  100. NameLowSort.Visibility = Visibility.Visible;
  101. }
  102. if (CountLowSort.IsChecked == true)
  103. {
  104. CountUpSort.Visibility = Visibility.Collapsed;
  105. CountLowSort.Visibility = Visibility.Visible;
  106. }
  107. }
  108. private void BakDataFile(object sender, RoutedEventArgs e)
  109. {
  110. CommonCode.BakAppData();
  111. }
  112. private void ShowSeconds_Click(object sender, RoutedEventArgs e)
  113. {
  114. if (MainWindow.appData.AppConfig.SecondsWindow == true)
  115. {
  116. //StartSecondsWindow();
  117. SecondsWindow.ShowWindow();
  118. }
  119. else
  120. {
  121. SecondsWindow.CloseWindow();
  122. //StopSecondsWindow();
  123. }
  124. }
  125. public static void StopSecondsWindow()
  126. {
  127. if (MessageUtil.CheckWindowIsRuning("ShowSeconds_Main_" + Constants.MY_UUID))
  128. {
  129. MessageUtil.SendMsgByWName(
  130. "ShowSeconds_Main_" + Constants.MY_UUID,
  131. "Shutdown"
  132. );
  133. }
  134. }
  135. public static void StartSecondsWindow()
  136. {
  137. try
  138. {
  139. using (var objOS = new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem"))
  140. {
  141. foreach (ManagementObject objMgmt in objOS.Get())
  142. {
  143. if (objMgmt.Properties["Caption"].Value != null)
  144. {
  145. string caption = objMgmt.Properties["Caption"].Value.ToString(); ;
  146. LogUtil.WriteLog("获取的系统版本号为:" + caption);
  147. if (caption.Contains("Windows 11"))
  148. {
  149. //找到ShowSeconds插件
  150. FileInfo fi = FileUtil.GetFileByNameWithDir("ShowSeconds.exe", Constants.PLUGINS_PATH);
  151. if (fi == null)
  152. {
  153. HandyControl.Controls.MessageBox.Show("未安装程序插件:ShowSeconds");
  154. }
  155. else
  156. {
  157. //检查是否在运行
  158. if (!MessageUtil.CheckWindowIsRuning("ShowSeconds_Main_" + Constants.MY_UUID))
  159. {
  160. using (Process p = new Process())
  161. {
  162. p.StartInfo.FileName = fi.FullName;
  163. p.StartInfo.WorkingDirectory = fi.FullName.Substring(0, fi.FullName.LastIndexOf("\\"));
  164. p.Start();
  165. }
  166. }
  167. }
  168. }
  169. }
  170. }
  171. }
  172. }
  173. catch (Exception ex) { }
  174. }
  175. }
  176. }