From a7181f6973d2f615bf8c79b094a6996cd1b453ca Mon Sep 17 00:00:00 2001 From: BookerLiu Date: Thu, 13 Apr 2023 16:39:24 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20=E5=87=8F=E5=B0=91everything?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=8D=A1=E9=A1=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Control/Other/SearchResControl.xaml | 198 ++++++++ Control/Other/SearchResControl.xaml.cs | 282 ++++++++++++ .../PannelCard/RightCardControl.xaml | 169 +------ .../PannelCard/RightCardControl.xaml.cs | 424 +----------------- Converts/Visibility2BooleanConverter.cs | 10 +- GeekDesk.csproj | 8 + MainWindow.xaml | 2 + MainWindow.xaml.cs | 216 ++++++--- Plugins/EveryThing/EveryThingUtil.cs | 27 +- Util/ProcessUtil.cs | 245 ++++++++++ 10 files changed, 930 insertions(+), 651 deletions(-) create mode 100644 Control/Other/SearchResControl.xaml create mode 100644 Control/Other/SearchResControl.xaml.cs create mode 100644 Util/ProcessUtil.cs diff --git a/Control/Other/SearchResControl.xaml b/Control/Other/SearchResControl.xaml new file mode 100644 index 0000000..b4af5f9 --- /dev/null +++ b/Control/Other/SearchResControl.xaml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Control/Other/SearchResControl.xaml.cs b/Control/Other/SearchResControl.xaml.cs new file mode 100644 index 0000000..d81c144 --- /dev/null +++ b/Control/Other/SearchResControl.xaml.cs @@ -0,0 +1,282 @@ +using GeekDesk.Constant; +using GeekDesk.Plugins.EveryThing; +using GeekDesk.Util; +using GeekDesk.ViewModel; +using GeekDesk.ViewModel.Temp; +using HandyControl.Controls; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; + +namespace GeekDesk.Control.Other +{ + /// + /// SearchResControl.xaml 的交互逻辑 + /// + public partial class SearchResControl : UserControl + { + public SearchResControl(ObservableCollection iconList) + { + this.DataContext = iconList; + InitializeComponent(); + } + + + + public void SearchListBoxIndexAdd() + { + //控制移动后 鼠标即使在图标上也不显示popup + RunTimeStatus.MOUSE_MOVE_COUNT = 0; + MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = false; + + if (SearchListBox.Items.Count > 0) + { + if (SearchListBox.SelectedIndex < SearchListBox.Items.Count - 1) + { + SearchListBox.SelectedIndex += 1; + } + } + } + + public void SearchListBoxIndexSub() + { + //控制移动后 鼠标即使在图标上也不显示popup + RunTimeStatus.MOUSE_MOVE_COUNT = 0; + MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = false; + + if (SearchListBox.Items.Count > 0) + { + if (SearchListBox.SelectedIndex > 0) + { + SearchListBox.SelectedIndex -= 1; + } + } + } + + public void StartupSelectionItem() + { + if (SearchListBox.SelectedItem != null) + { + IconInfo icon = SearchListBox.SelectedItem as IconInfo; + if (icon.AdminStartUp) + { + ProcessUtil.StartIconApp(icon, IconStartType.ADMIN_STARTUP); + } + else + { + ProcessUtil.StartIconApp(icon, IconStartType.DEFAULT_STARTUP); + } + } + } + + private void SearchListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) + { + SearchListBox.ScrollIntoView(SearchListBox.SelectedItem); + } + + + + /// + /// 查询结果ICON鼠标移动事件 + /// + /// + /// + private void SearchIcon_MouseMove(object sender, MouseEventArgs e) + { + //控制首次刷新搜索结果后, 鼠标首次移动后显示popup + RunTimeStatus.MOUSE_MOVE_COUNT++; + + //防止移动后不刷新popup content + IconInfo info = (sender as Panel).Tag as IconInfo; + MainWindow.mainWindow.RightCard.MyPoptipContent.Text = info.Content; + MainWindow.mainWindow.RightCard.MyPoptip.VerticalOffset = 30; + + if (RunTimeStatus.MOUSE_MOVE_COUNT > 1 && !RunTimeStatus.ICONLIST_MOUSE_WHEEL) + { + MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = true; + } + } + + /// + /// 查询结果 ICON 鼠标进入事件 + /// + /// + /// + private void SearchIcon_MouseEnter(object sender, MouseEventArgs e) + { + + //显示popup + RunTimeStatus.MOUSE_ENTER_ICON = true; + if (!RunTimeStatus.ICONLIST_MOUSE_WHEEL) + { + new Thread(() => + { + this.Dispatcher.BeginInvoke(new Action(() => + { + IconInfo info = (sender as Panel).Tag as IconInfo; + MainWindow.mainWindow.RightCard.MyPoptipContent.Text = info.Content; + MainWindow.mainWindow.RightCard.MyPoptip.VerticalOffset = 30; + Thread.Sleep(100); + if (!RunTimeStatus.ICONLIST_MOUSE_WHEEL && RunTimeStatus.MOUSE_MOVE_COUNT > 1) + { + MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = true; + } + })); + }).Start(); + } + } + + /// + /// 查询结果ICON鼠标离开事件 + /// + /// + /// + private void SearchIcon_MouseLeave(object sender, MouseEventArgs e) + { + RunTimeStatus.MOUSE_ENTER_ICON = false; + MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = false; + } + + /// + /// 搜索结果icon 列表鼠标滚轮预处理时间 + /// 主要使用自定义popup解决卡顿问题解决卡顿问题 + /// + /// + /// + private void VerticalIconList_PreviewMouseWheel(object sender, MouseWheelEventArgs e) + { + //控制在滚动时不显示popup 否则会在低GPU性能机器上造成卡顿 + MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = false; + if (RunTimeStatus.ICONLIST_MOUSE_WHEEL) + { + RunTimeStatus.MOUSE_WHEEL_WAIT_MS = 500; + } + else + { + RunTimeStatus.ICONLIST_MOUSE_WHEEL = true; + + new Thread(() => + { + while (RunTimeStatus.MOUSE_WHEEL_WAIT_MS > 0) + { + Thread.Sleep(1); + RunTimeStatus.MOUSE_WHEEL_WAIT_MS -= 1; + } + if (RunTimeStatus.MOUSE_ENTER_ICON) + { + this.Dispatcher.BeginInvoke(new Action(() => + { + MainWindow.mainWindow.RightCard.MyPoptip.IsOpen = true; + })); + } + RunTimeStatus.MOUSE_WHEEL_WAIT_MS = 100; + RunTimeStatus.ICONLIST_MOUSE_WHEEL = false; + }).Start(); + } + } + + + private void Icon_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + if (MainWindow.appData.AppConfig.DoubleOpen) + { + IconClick(sender, e); + } + } + + private void Icon_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) + { + if (!MainWindow.appData.AppConfig.DoubleOpen) + { + IconClick(sender, e); + } + } + + /// + /// 图标点击事件 + /// + /// + /// + private void IconClick(object sender, MouseButtonEventArgs e) + { + if (MainWindow.appData.AppConfig.DoubleOpen && e.ClickCount >= 2) + { + IconInfo icon = (IconInfo)((Panel)sender).Tag; + if (icon.AdminStartUp) + { + ProcessUtil.StartIconApp(icon, IconStartType.ADMIN_STARTUP); + } + else + { + ProcessUtil.StartIconApp(icon, IconStartType.DEFAULT_STARTUP); + } + } + else if (!MainWindow.appData.AppConfig.DoubleOpen && e.ClickCount == 1) + { + IconInfo icon = (IconInfo)((Panel)sender).Tag; + if (icon.AdminStartUp) + { + ProcessUtil.StartIconApp(icon, IconStartType.ADMIN_STARTUP); + } + else + { + ProcessUtil.StartIconApp(icon, IconStartType.DEFAULT_STARTUP); + } + } + + } + + + private static volatile bool EveryThingRuning = false; + private void VerticalCard_ScrollChanged(object sender, ScrollChangedEventArgs e) + { + if (MainWindow.appData.AppConfig.EnableEveryThing == true && EveryThingUtil.HasNext()) + { + HandyControl.Controls.ScrollViewer sv = sender as HandyControl.Controls.ScrollViewer; + if (sv.ExtentHeight - (sv.ActualHeight + sv.VerticalOffset) < 100 + && EveryThingUtil.HasNext() + && !EveryThingRuning) + { + EveryThingRuning = true; + MainWindow.mainWindow.RightCard.Loading_RightCard.Visibility = Visibility.Visible; + string[] split = MainWindow.mainWindow.TotalMsgBtn.Content.ToString().Split(' '); + long count = Convert.ToInt64(split[0]); + + ObservableCollection resList = this.DataContext as ObservableCollection; + + ThreadPool.QueueUserWorkItem(state => + { + ObservableCollection searchRes = EveryThingUtil.NextPage(); + this.Dispatcher.Invoke(() => + { + count += searchRes.Count; + MainWindow.mainWindow.TotalMsgBtn.Content = count + " of " + split[split.Length - 1]; + foreach (IconInfo info in searchRes) + { + resList.Add(info); + } + MainWindow.mainWindow.RightCard.Loading_RightCard.Visibility = Visibility.Collapsed; + EveryThingRuning = false; + }); + }); + + } + } + } + + } +} diff --git a/Control/UserControls/PannelCard/RightCardControl.xaml b/Control/UserControls/PannelCard/RightCardControl.xaml index 5e8bea0..395c73a 100644 --- a/Control/UserControls/PannelCard/RightCardControl.xaml +++ b/Control/UserControls/PannelCard/RightCardControl.xaml @@ -11,7 +11,6 @@ xmlns:component="clr-namespace:GeekDesk.CustomComponent.VirtualizingWrapPanel" xmlns:xf="clr-namespace:XamlFlair;assembly=XamlFlair.WPF" xmlns:ot="clr-namespace:GeekDesk.Control.Other" - xmlns:viewmodel="clr-namespace:GeekDesk.ViewModel" d:DataContext="{d:DesignInstance Type=viewmodel:AppData}" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" > @@ -162,7 +161,6 @@ @@ -280,164 +278,31 @@ + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + diff --git a/Control/UserControls/PannelCard/RightCardControl.xaml.cs b/Control/UserControls/PannelCard/RightCardControl.xaml.cs index 3d54f10..81db405 100644 --- a/Control/UserControls/PannelCard/RightCardControl.xaml.cs +++ b/Control/UserControls/PannelCard/RightCardControl.xaml.cs @@ -131,11 +131,11 @@ namespace GeekDesk.Control.UserControls.PannelCard IconInfo icon = (IconInfo)((Panel)sender).Tag; if (icon.AdminStartUp) { - StartIconApp(icon, IconStartType.ADMIN_STARTUP); + ProcessUtil.StartIconApp(icon, IconStartType.ADMIN_STARTUP); } else { - StartIconApp(icon, IconStartType.DEFAULT_STARTUP); + ProcessUtil.StartIconApp(icon, IconStartType.DEFAULT_STARTUP); } } else if (!appData.AppConfig.DoubleOpen && e.ClickCount == 1) @@ -143,11 +143,11 @@ namespace GeekDesk.Control.UserControls.PannelCard IconInfo icon = (IconInfo)((Panel)sender).Tag; if (icon.AdminStartUp) { - StartIconApp(icon, IconStartType.ADMIN_STARTUP); + ProcessUtil.StartIconApp(icon, IconStartType.ADMIN_STARTUP); } else { - StartIconApp(icon, IconStartType.DEFAULT_STARTUP); + ProcessUtil.StartIconApp(icon, IconStartType.DEFAULT_STARTUP); } } @@ -161,7 +161,7 @@ namespace GeekDesk.Control.UserControls.PannelCard private void IconAdminStart(object sender, RoutedEventArgs e) { IconInfo icon = (IconInfo)((MenuItem)sender).Tag; - StartIconApp(icon, IconStartType.ADMIN_STARTUP); + ProcessUtil.StartIconApp(icon, IconStartType.ADMIN_STARTUP); } /// @@ -172,227 +172,7 @@ namespace GeekDesk.Control.UserControls.PannelCard private void ShowInExplore(object sender, RoutedEventArgs e) { IconInfo icon = (IconInfo)((MenuItem)sender).Tag; - StartIconApp(icon, IconStartType.SHOW_IN_EXPLORE); - } - - private void StartIconApp(IconInfo icon, IconStartType type, bool useRelativePath = false) - { - try - { - using (Process p = new Process()) - { - string startArg = icon.StartArg; - - if (startArg != null && Constants.SYSTEM_ICONS.ContainsKey(startArg)) - { - StartSystemApp(startArg, type); - } - else - { - string path; - if (useRelativePath) - { - string fullPath = Path.Combine(Constants.APP_DIR, icon.RelativePath); - path = Path.GetFullPath(fullPath); - } - else - { - path = icon.Path; - } - p.StartInfo.FileName = path; - if (!StringUtil.IsEmpty(startArg)) - { - p.StartInfo.Arguments = startArg; - } - if (icon.IconType == IconType.OTHER) - { - if (!File.Exists(path) && !Directory.Exists(path)) - { - //如果没有使用相对路径 那么使用相对路径启动一次 - if (!useRelativePath) - { - StartIconApp(icon, type, true); - return; - } - else - { - HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!"); - return; - } - } - p.StartInfo.WorkingDirectory = path.Substring(0, path.LastIndexOf("\\")); - switch (type) - { - case IconStartType.ADMIN_STARTUP: - //p.StartInfo.Arguments = "1";//启动参数 - p.StartInfo.Verb = "runas"; - //p.StartInfo.CreateNoWindow = false; //设置显示窗口 - p.StartInfo.UseShellExecute = true;//不使用操作系统外壳程序启动进程 - //p.StartInfo.ErrorDialog = false; - if (appData.AppConfig.AppHideType == AppHideType.START_EXE && !RunTimeStatus.LOCK_APP_PANEL) - { - //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 - if (appData.AppConfig.MarginHide) - { - if (!MarginHide.IsMargin()) - { - MainWindow.HideApp(); - } - } - else - { - MainWindow.HideApp(); - } - - } - break;// c#好像不能case穿透 - case IconStartType.DEFAULT_STARTUP: - if (appData.AppConfig.AppHideType == AppHideType.START_EXE && !RunTimeStatus.LOCK_APP_PANEL) - { - //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 - if (appData.AppConfig.MarginHide) - { - if (!MarginHide.IsMargin()) - { - MainWindow.HideApp(); - } - } - else - { - MainWindow.HideApp(); - } - } - break; - case IconStartType.SHOW_IN_EXPLORE: - p.StartInfo.FileName = "Explorer.exe"; - p.StartInfo.Arguments = "/e,/select," + icon.Path; - break; - } - } - else - { - if (appData.AppConfig.AppHideType == AppHideType.START_EXE && !RunTimeStatus.LOCK_APP_PANEL) - { - //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 - if (appData.AppConfig.MarginHide) - { - if (!MarginHide.IS_HIDE) - { - MainWindow.HideApp(); - } - } - else - { - MainWindow.HideApp(); - } - } - } - p.Start(); - if (useRelativePath) - { - //如果使用相对路径启动成功 那么重新设置程序绝对路径 - icon.Path = path; - } - } - } - icon.Count++; - - //隐藏搜索框 - if (RunTimeStatus.SEARCH_BOX_SHOW) - { - MainWindow.mainWindow.HidedSearchBox(); - } - } - catch (Exception e) - { - if (!useRelativePath) - { - StartIconApp(icon, type, true); - } - else - { - HandyControl.Controls.Growl.WarningGlobal("程序启动失败(可能为不支持的启动方式)!"); - LogUtil.WriteErrorLog(e, "程序启动失败:path=" + icon.Path + ",type=" + type); - } - } - } - - - - private void StartSystemApp(string startArg, IconStartType type) - { - if (type == IconStartType.SHOW_IN_EXPLORE) - { - Growl.WarningGlobal("系统项目不支持打开文件位置操作!"); - return; - } - switch (startArg) - { - case "Calculator": - Process.Start("calc.exe"); - break; - case "Computer": - Process.Start("explorer.exe"); - break; - case "GroupPolicy": - Process.Start("gpedit.msc"); - break; - case "Notepad": - Process.Start("notepad"); - break; - case "Network": - Process.Start("ncpa.cpl"); - break; - case "RecycleBin": - Process.Start("shell:RecycleBinFolder"); - break; - case "Registry": - Process.Start("regedit.exe"); - break; - case "Mstsc": - if (type == IconStartType.ADMIN_STARTUP) - { - Process.Start("mstsc", "-admin"); - } - else - { - Process.Start("mstsc"); - } - break; - case "Control": - Process.Start("Control"); - break; - case "CMD": - if (type == IconStartType.ADMIN_STARTUP) - { - using (Process process = new Process()) - { - process.StartInfo.FileName = "cmd.exe"; - process.StartInfo.Verb = "runas"; - process.Start(); - } - } - else - { - Process.Start("cmd"); - } - break; - case "Services": - Process.Start("services.msc"); - break; - } - //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 - if (appData.AppConfig.MarginHide) - { - if (!MarginHide.IS_HIDE) - { - MainWindow.HideApp(); - } - } - else - { - MainWindow.HideApp(); - } + ProcessUtil.StartIconApp(icon, IconStartType.SHOW_IN_EXPLORE); } /// @@ -778,56 +558,7 @@ namespace GeekDesk.Control.UserControls.PannelCard } } - public void SearchListBoxIndexAdd() - { - //控制移动后 鼠标即使在图标上也不显示popup - RunTimeStatus.MOUSE_MOVE_COUNT = 0; - MyPoptip.IsOpen = false; - - if (SearchListBox.Items.Count > 0) - { - if (SearchListBox.SelectedIndex < SearchListBox.Items.Count - 1) - { - SearchListBox.SelectedIndex += 1; - } - } - } - - public void SearchListBoxIndexSub() - { - //控制移动后 鼠标即使在图标上也不显示popup - RunTimeStatus.MOUSE_MOVE_COUNT = 0; - MyPoptip.IsOpen = false; - - if (SearchListBox.Items.Count > 0) - { - if (SearchListBox.SelectedIndex > 0) - { - SearchListBox.SelectedIndex -= 1; - } - } - } - - public void StartupSelectionItem() - { - if (SearchListBox.SelectedItem != null) - { - IconInfo icon = SearchListBox.SelectedItem as IconInfo; - if (icon.AdminStartUp) - { - StartIconApp(icon, IconStartType.ADMIN_STARTUP); - } - else - { - StartIconApp(icon, IconStartType.DEFAULT_STARTUP); - } - } - } - - private void SearchListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - SearchListBox.ScrollIntoView(SearchListBox.SelectedItem); - } + private void PDDialog_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { @@ -937,105 +668,6 @@ namespace GeekDesk.Control.UserControls.PannelCard } - /// - /// 搜索结果icon 列表鼠标滚轮预处理时间 - /// 主要使用自定义popup解决卡顿问题解决卡顿问题 - /// - /// - /// - private void VerticalIconList_PreviewMouseWheel(object sender, MouseWheelEventArgs e) - { - //控制在滚动时不显示popup 否则会在低GPU性能机器上造成卡顿 - MyPoptip.IsOpen = false; - if (RunTimeStatus.ICONLIST_MOUSE_WHEEL) - { - RunTimeStatus.MOUSE_WHEEL_WAIT_MS = 500; - } - else - { - RunTimeStatus.ICONLIST_MOUSE_WHEEL = true; - - new Thread(() => - { - while (RunTimeStatus.MOUSE_WHEEL_WAIT_MS > 0) - { - Thread.Sleep(1); - RunTimeStatus.MOUSE_WHEEL_WAIT_MS -= 1; - } - if (RunTimeStatus.MOUSE_ENTER_ICON) - { - this.Dispatcher.BeginInvoke(new Action(() => - { - MyPoptip.IsOpen = true; - })); - } - RunTimeStatus.MOUSE_WHEEL_WAIT_MS = 100; - RunTimeStatus.ICONLIST_MOUSE_WHEEL = false; - }).Start(); - } - } - - /// - /// 查询结果 ICON 鼠标进入事件 - /// - /// - /// - private void SearchIcon_MouseEnter(object sender, MouseEventArgs e) - { - - //显示popup - RunTimeStatus.MOUSE_ENTER_ICON = true; - if (!RunTimeStatus.ICONLIST_MOUSE_WHEEL) - { - new Thread(() => - { - this.Dispatcher.BeginInvoke(new Action(() => - { - IconInfo info = (sender as Panel).Tag as IconInfo; - MyPoptipContent.Text = info.Content; - MyPoptip.VerticalOffset = 30; - Thread.Sleep(100); - if (!RunTimeStatus.ICONLIST_MOUSE_WHEEL && RunTimeStatus.MOUSE_MOVE_COUNT > 1) - { - MyPoptip.IsOpen = true; - } - })); - }).Start(); - } - } - - /// - /// 查询结果ICON鼠标离开事件 - /// - /// - /// - private void SearchIcon_MouseLeave(object sender, MouseEventArgs e) - { - RunTimeStatus.MOUSE_ENTER_ICON = false; - MyPoptip.IsOpen = false; - } - - /// - /// 查询结果ICON鼠标移动事件 - /// - /// - /// - private void SearchIcon_MouseMove(object sender, MouseEventArgs e) - { - //控制首次刷新搜索结果后, 鼠标首次移动后显示popup - RunTimeStatus.MOUSE_MOVE_COUNT++; - - //防止移动后不刷新popup content - IconInfo info = (sender as Panel).Tag as IconInfo; - MyPoptipContent.Text = info.Content; - MyPoptip.VerticalOffset = 30; - - if (RunTimeStatus.MOUSE_MOVE_COUNT > 1 && !RunTimeStatus.ICONLIST_MOUSE_WHEEL) - { - MyPoptip.IsOpen = true; - } - } - /// /// menu结果ICON鼠标移动事件 /// @@ -1049,48 +681,6 @@ namespace GeekDesk.Control.UserControls.PannelCard MyPoptip.VerticalOffset = 30; } - private void VerticalCard_ScrollChanged(object sender, ScrollChangedEventArgs e) - { - if (appData.AppConfig.EnableEveryThing == true && EveryThingUtil.HasNext()) - { - HandyControl.Controls.ScrollViewer sv = sender as HandyControl.Controls.ScrollViewer; - if (sv.ExtentHeight - (sv.ActualHeight + sv.VerticalOffset) < 200 && EveryThingUtil.HasNext()) - { - string[] split = MainWindow.mainWindow.TotalMsgBtn.Content.ToString().Split(' '); - long count = Convert.ToInt64(split[0]); - ObservableCollection iconBakList = EveryThingUtil.NextPage(); - count += iconBakList.Count; - - this.Dispatcher.Invoke(() => - { - MainWindow.mainWindow.TotalMsgBtn.Content = count + " of " + split[split.Length - 1]; - foreach (IconInfo icon in iconBakList) - { - if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return; - SearchIconList.IconList.Add(icon); - } - }); - //异步加载图标 - if (iconBakList != null && iconBakList.Count > 0) - { - ThreadPool.QueueUserWorkItem(state => - { - foreach (IconInfo icon in iconBakList) - { - if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return; - this.Dispatcher.Invoke(() => - { - icon.BitmapImage_NoWrite = ImageUtil.GetBitmapIconByUnknownPath(icon.Path); - }); - } - }); - } - - } - } - } - - } } diff --git a/Converts/Visibility2BooleanConverter.cs b/Converts/Visibility2BooleanConverter.cs index 3d941c8..c32e508 100644 --- a/Converts/Visibility2BooleanConverter.cs +++ b/Converts/Visibility2BooleanConverter.cs @@ -9,14 +9,14 @@ namespace GeekDesk.Converts { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if ((Visibility)value == Visibility.Visible) + if (parameter == null) { - return true; - } - else + return (Visibility)value == Visibility.Visible; + } else { - return false; + return !((Visibility)value == Visibility.Visible); } + } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/GeekDesk.csproj b/GeekDesk.csproj index 1c671d0..c5f9d2f 100644 --- a/GeekDesk.csproj +++ b/GeekDesk.csproj @@ -200,6 +200,9 @@ IconInfoUrlDialog.xaml + + SearchResControl.xaml + OtherControl.xaml @@ -315,6 +318,7 @@ + @@ -369,6 +373,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff --git a/MainWindow.xaml b/MainWindow.xaml index ab250c8..de1d33d 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -11,6 +11,7 @@ xmlns:cvt="clr-namespace:GeekDesk.Converts" x:Name="AppWindow" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:viewmodel="clr-namespace:GeekDesk.ViewModel" + xmlns:my="clr-namespace:GeekDesk.Util" d:DataContext="{d:DesignInstance Type=viewmodel:AppData}" Title="GeekDesk_Main_8400A17AEEF7C029" MinWidth="600" @@ -196,6 +197,7 @@ + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 1de0ddf..5073c46 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -1,4 +1,5 @@ using GeekDesk.Constant; +using GeekDesk.Control.Other; using GeekDesk.Control.UserControls.Config; using GeekDesk.Control.UserControls.PannelCard; using GeekDesk.Control.Windows; @@ -124,24 +125,30 @@ namespace GeekDesk RightCard.MyPoptip.IsOpen = false; string inputText = SearchBox.Text.ToLower(); - RightCard.VerticalUFG.Visibility = Visibility.Collapsed; if (!string.IsNullOrEmpty(inputText)) { RunTimeStatus.EVERYTHING_SEARCH_DELAY_TIME = 300; if (!RunTimeStatus.EVERYTHING_NEW_SEARCH) { RunTimeStatus.EVERYTHING_NEW_SEARCH = true; + object obj = RightCard.VerticalCard.Content; + if (obj != null) + { + SearchResControl control = obj as SearchResControl; + control.VerticalUFG.Visibility = Visibility.Collapsed; + } SearchDelay(); } } else { - new Thread(() => + //清空查询结果 + object obj = RightCard.VerticalCard.Content; + if (obj != null) { - this.Dispatcher.Invoke(() => - { - SearchIconList.RemoveAll(); - }); - }).Start(); + SearchResControl control = obj as SearchResControl; + control.VerticalUFG.Visibility = Visibility.Collapsed; + control.SearchListBox.Items.Clear(); + } } } @@ -162,77 +169,149 @@ namespace GeekDesk this.Dispatcher.Invoke(() => { - if (SearchIconList.IconList.Count > 0) - { - SearchIconList.RemoveAll(); - } - string inputText = SearchBox.Text.ToLower().Trim(); - int count = 0; - //GeekDesk数据搜索 - ObservableCollection menuList = appData.MenuList; - foreach (MenuInfo menu in menuList) + new Thread(() => { - ObservableCollection iconList = menu.IconList; - foreach (IconInfo icon in iconList) + ObservableCollection resList = new ObservableCollection(); + + DateTime bf = DateTime.Now; + ObservableCollection iconBakList = EveryThingUtil.Search(inputText); + + foreach (IconInfo icon in iconBakList) { - if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return; - string pyName = Pinyin.GetInitials(icon.Name).ToLower(); - if (icon.Name.Contains(inputText) || pyName.Contains(inputText)) + resList.Add(icon); + } + + DateTime af = DateTime.Now; + + //GeekDesk数据搜索 + ObservableCollection menuList = appData.MenuList; + foreach (MenuInfo menu in menuList) + { + ObservableCollection iconList = menu.IconList; + foreach (IconInfo icon in iconList) { - SearchIconList.IconList.Add(icon); - count++; + if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return; + string pyName = Pinyin.GetInitials(icon.Name).ToLower(); + if (icon.Name.Contains(inputText) || pyName.Contains(inputText)) + { + resList.Add(icon); + } } } - } + Console.WriteLine("查询耗时:{0}ms.", af.Subtract(bf).TotalMilliseconds); - - if (appData.AppConfig.EnableEveryThing == true) - { - new Thread(() => + this.Dispatcher.Invoke(() => { - //EveryThing全盘搜索 - ObservableCollection iconBakList = EveryThingUtil.Search(inputText); - count += iconBakList.Count; - this.Dispatcher.Invoke(() => - { - TotalMsgBtn.Visibility = Visibility.Visible; - TotalMsgBtn.Content = count + " of " + Convert.ToInt64(EveryThingUtil.Everything_GetNumResults()); - foreach (IconInfo icon in iconBakList) - { - if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return; - SearchIconList.IconList.Add(icon); - } - }); - - //异步加载图标 - if (iconBakList != null && iconBakList.Count > 0) - { - new Thread(() => - { - foreach (IconInfo icon in iconBakList) - { - if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return; - this.Dispatcher.Invoke(() => - { - icon.BitmapImage_NoWrite = ImageUtil.GetBitmapIconByUnknownPath(icon.Path); - }, DispatcherPriority.SystemIdle); - } - }).Start(); - } - }).Start(); - } + SearchResControl control = new SearchResControl(resList); + bf = DateTime.Now; + RightCard.VerticalCard.Content = control; + //显示加载效果 + RightCard.Loading_RightCard.Visibility = Visibility.Collapsed; + af = DateTime.Now; + Console.WriteLine("渲染耗时:{0}ms.", af.Subtract(bf).TotalMilliseconds); + }); + }).Start(); + - if (RightCard.SearchListBox.Items.Count > 0) - { - RightCard.SearchListBox.SelectedIndex = 0; - } - RightCard.VerticalUFG.Visibility = Visibility.Visible; + ////异步加载图标 + //if (iconBakList != null && iconBakList.Count > 0) + //{ + // new Thread(() => + // { + + // }).Start(); + //} + + }); + + //EveryThing全盘搜索 + + + + + + + + + //this.Dispatcher.Invoke(() => + //{ + // if (SearchIconList.IconList.Count > 0) + // { + // SearchIconList.RemoveAll(); + // } + + // string inputText = SearchBox.Text.ToLower().Trim(); + + // int count = 0; + // //GeekDesk数据搜索 + // ObservableCollection menuList = appData.MenuList; + // foreach (MenuInfo menu in menuList) + // { + // ObservableCollection iconList = menu.IconList; + // foreach (IconInfo icon in iconList) + // { + // if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return; + // string pyName = Pinyin.GetInitials(icon.Name).ToLower(); + // if (icon.Name.Contains(inputText) || pyName.Contains(inputText)) + // { + // SearchIconList.IconList.Add(icon); + // count++; + // } + // } + // } + + + // if (appData.AppConfig.EnableEveryThing == true) + // { + // new Thread(() => + // { + // //EveryThing全盘搜索 + // ObservableCollection iconBakList = EveryThingUtil.Search(inputText); + // count += iconBakList.Count; + // this.Dispatcher.Invoke(() => + // { + // TotalMsgBtn.Visibility = Visibility.Visible; + // TotalMsgBtn.Content = count + " of " + Convert.ToInt64(EveryThingUtil.Everything_GetNumResults()); + // foreach (IconInfo icon in iconBakList) + // { + // if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return; + // SearchIconList.IconList.Add(icon); + // } + // }); + + // //异步加载图标 + // if (iconBakList != null && iconBakList.Count > 0) + // { + // new Thread(() => + // { + // foreach (IconInfo icon in iconBakList) + // { + // if (RunTimeStatus.EVERYTHING_NEW_SEARCH) return; + // this.Dispatcher.Invoke(() => + // { + // icon.BitmapImage_NoWrite = ImageUtil.GetBitmapIconByUnknownPath(icon.Path); + // }, DispatcherPriority.SystemIdle); + // } + // }).Start(); + // } + // }).Start(); + // } + + + + // //if (RightCard.SearchListBox.Items.Count > 0) + // //{ + // // RightCard.SearchListBox.SelectedIndex = 0; + // //} + // //RightCard.VerticalUFG.Visibility = Visibility.Visible; + //}); + }).Start(); } @@ -880,15 +959,18 @@ namespace GeekDesk { if (e.Key == Key.Down || e.Key == Key.Tab) { - RightCard.SearchListBoxIndexAdd(); + SearchResControl res = RightCard.VerticalCard.Content as SearchResControl; + res.SearchListBoxIndexAdd(); } else if (e.Key == Key.Up) { - RightCard.SearchListBoxIndexSub(); + SearchResControl res = RightCard.VerticalCard.Content as SearchResControl; + res.SearchListBoxIndexSub(); } else if (e.Key == Key.Enter) { - RightCard.StartupSelectionItem(); + SearchResControl res = RightCard.VerticalCard.Content as SearchResControl; + res.StartupSelectionItem(); } } } diff --git a/Plugins/EveryThing/EveryThingUtil.cs b/Plugins/EveryThing/EveryThingUtil.cs index 4208cad..329318d 100644 --- a/Plugins/EveryThing/EveryThingUtil.cs +++ b/Plugins/EveryThing/EveryThingUtil.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; +using System.Drawing; using System.Linq; using System.Text; using System.Threading; @@ -92,19 +93,25 @@ namespace GeekDesk.Plugins.EveryThing public static void DisableEveryThing() { - if (IsByGeekDesk) + try { - if (Environment.Is64BitOperatingSystem) + if (IsByGeekDesk) { - EveryThing64.Everything_Exit(); - } else - { - EveryThing32.Everything_Exit(); + if (Environment.Is64BitOperatingSystem) + { + EveryThing64.Everything_Exit(); + } + else + { + EveryThing32.Everything_Exit(); + } } + if (exeProcess != null) exeProcess.Kill(); + if (serviceProcess != null) serviceProcess.Kill(); + } catch (Exception e) + { + LogUtil.WriteErrorLog(e); } - if (exeProcess != null) exeProcess.Kill(); - if (serviceProcess != null) serviceProcess.Kill(); - } @@ -179,7 +186,7 @@ namespace GeekDesk.Plugins.EveryThing { Path_NoWrite = filePath, LnkPath_NoWrite = tempPath, - BitmapImage_NoWrite = null, + BitmapImage_NoWrite = ImageUtil.GetBitmapIconByUnknownPath(filePath), StartArg_NoWrite = FileUtil.GetArgByLnk(tempPath), Name_NoWrite = name, }; diff --git a/Util/ProcessUtil.cs b/Util/ProcessUtil.cs new file mode 100644 index 0000000..9581de5 --- /dev/null +++ b/Util/ProcessUtil.cs @@ -0,0 +1,245 @@ +using GeekDesk.Constant; +using GeekDesk.ViewModel; +using HandyControl.Controls; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GeekDesk.Util +{ + public class ProcessUtil + { + + + public static void StartIconApp(IconInfo icon, IconStartType type, bool useRelativePath = false) + { + App.Current.Dispatcher.Invoke(() => + { + + try + { + using (Process p = new Process()) + { + string startArg = icon.StartArg; + + if (startArg != null && Constants.SYSTEM_ICONS.ContainsKey(startArg)) + { + StartSystemApp(startArg, type); + } + else + { + string path; + if (useRelativePath) + { + string fullPath = Path.Combine(Constants.APP_DIR, icon.RelativePath); + path = Path.GetFullPath(fullPath); + } + else + { + path = icon.Path; + } + p.StartInfo.FileName = path; + if (!StringUtil.IsEmpty(startArg)) + { + p.StartInfo.Arguments = startArg; + } + if (icon.IconType == IconType.OTHER) + { + if (!File.Exists(path) && !Directory.Exists(path)) + { + //如果没有使用相对路径 那么使用相对路径启动一次 + if (!useRelativePath) + { + StartIconApp(icon, type, true); + return; + } + else + { + HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!"); + return; + } + } + p.StartInfo.WorkingDirectory = path.Substring(0, path.LastIndexOf("\\")); + switch (type) + { + case IconStartType.ADMIN_STARTUP: + //p.StartInfo.Arguments = "1";//启动参数 + p.StartInfo.Verb = "runas"; + //p.StartInfo.CreateNoWindow = false; //设置显示窗口 + p.StartInfo.UseShellExecute = true;//不使用操作系统外壳程序启动进程 + //p.StartInfo.ErrorDialog = false; + if (MainWindow.appData.AppConfig.AppHideType == AppHideType.START_EXE && !RunTimeStatus.LOCK_APP_PANEL) + { + //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 + if (MainWindow.appData.AppConfig.MarginHide) + { + if (!MarginHide.IsMargin()) + { + MainWindow.HideApp(); + } + } + else + { + MainWindow.HideApp(); + } + + } + break;// c#好像不能case穿透 + case IconStartType.DEFAULT_STARTUP: + if (MainWindow.appData.AppConfig.AppHideType == AppHideType.START_EXE && !RunTimeStatus.LOCK_APP_PANEL) + { + //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 + if (MainWindow.appData.AppConfig.MarginHide) + { + if (!MarginHide.IsMargin()) + { + MainWindow.HideApp(); + } + } + else + { + MainWindow.HideApp(); + } + } + break; + case IconStartType.SHOW_IN_EXPLORE: + p.StartInfo.FileName = "Explorer.exe"; + p.StartInfo.Arguments = "/e,/select," + icon.Path; + break; + } + } + else + { + if (MainWindow.appData.AppConfig.AppHideType == AppHideType.START_EXE && !RunTimeStatus.LOCK_APP_PANEL) + { + //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 + if (MainWindow.appData.AppConfig.MarginHide) + { + if (!MarginHide.IS_HIDE) + { + MainWindow.HideApp(); + } + } + else + { + MainWindow.HideApp(); + } + } + } + p.Start(); + if (useRelativePath) + { + //如果使用相对路径启动成功 那么重新设置程序绝对路径 + icon.Path = path; + } + } + } + icon.Count++; + + //隐藏搜索框 + if (RunTimeStatus.SEARCH_BOX_SHOW) + { + MainWindow.mainWindow.HidedSearchBox(); + } + } + catch (Exception e) + { + if (!useRelativePath) + { + StartIconApp(icon, type, true); + } + else + { + HandyControl.Controls.Growl.WarningGlobal("程序启动失败(可能为不支持的启动方式)!"); + LogUtil.WriteErrorLog(e, "程序启动失败:path=" + icon.Path + ",type=" + type); + } + } + }); + } + + + + private static void StartSystemApp(string startArg, IconStartType type) + { + if (type == IconStartType.SHOW_IN_EXPLORE) + { + Growl.WarningGlobal("系统项目不支持打开文件位置操作!"); + return; + } + switch (startArg) + { + case "Calculator": + Process.Start("calc.exe"); + break; + case "Computer": + Process.Start("explorer.exe"); + break; + case "GroupPolicy": + Process.Start("gpedit.msc"); + break; + case "Notepad": + Process.Start("notepad"); + break; + case "Network": + Process.Start("ncpa.cpl"); + break; + case "RecycleBin": + Process.Start("shell:RecycleBinFolder"); + break; + case "Registry": + Process.Start("regedit.exe"); + break; + case "Mstsc": + if (type == IconStartType.ADMIN_STARTUP) + { + Process.Start("mstsc", "-admin"); + } + else + { + Process.Start("mstsc"); + } + break; + case "Control": + Process.Start("Control"); + break; + case "CMD": + if (type == IconStartType.ADMIN_STARTUP) + { + using (Process process = new Process()) + { + process.StartInfo.FileName = "cmd.exe"; + process.StartInfo.Verb = "runas"; + process.Start(); + } + } + else + { + Process.Start("cmd"); + } + break; + case "Services": + Process.Start("services.msc"); + break; + } + //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 + if (MainWindow.appData.AppConfig.MarginHide) + { + if (!MarginHide.IS_HIDE) + { + MainWindow.HideApp(); + } + } + else + { + MainWindow.HideApp(); + } + } + + + + } +}