OtherControl.xaml.cs 7.2 KB

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