diff --git a/Control/UserControls/Config/OtherControl.xaml.cs b/Control/UserControls/Config/OtherControl.xaml.cs index a1a886d..2e95c18 100644 --- a/Control/UserControls/Config/OtherControl.xaml.cs +++ b/Control/UserControls/Config/OtherControl.xaml.cs @@ -199,7 +199,7 @@ namespace GeekDesk.Control.UserControls.Config EveryThingUtil.EnableEveryThing(0); } else { - EveryThingUtil.DisableEveryThing(); + EveryThingUtil.DisableEveryThing(true); } } } diff --git a/Control/UserControls/PannelCard/LeftCardControl.xaml.cs b/Control/UserControls/PannelCard/LeftCardControl.xaml.cs index f0d1abb..555a25e 100644 --- a/Control/UserControls/PannelCard/LeftCardControl.xaml.cs +++ b/Control/UserControls/PannelCard/LeftCardControl.xaml.cs @@ -244,7 +244,7 @@ namespace GeekDesk.Control.UserControls.PannelCard object obj = MenuListBox.ItemContainerGenerator.ContainerFromIndex(MenuListBox.SelectedIndex); SetListBoxItemEvent((ListBoxItem)obj); Lbi_Selected(obj, null); - HandyControl.Controls.Growl.Success("菜单关联成功, 后台加载列表!", "MainWindowGrowl"); + HandyControl.Controls.Growl.Success("菜单关联成功, 加载列表中, 稍后重新进入此菜单可查看列表!", "MainWindowGrowl"); FileWatcher.LinkMenuWatcher(menuInfo); new Thread(() => @@ -260,10 +260,11 @@ namespace GeekDesk.Control.UserControls.PannelCard } this.Dispatcher.Invoke(() => { - foreach (IconInfo iconInfo in iconList) - { - menuInfo.IconList.Add(iconInfo); - } + menuInfo.IconList = iconList; + //foreach (IconInfo iconInfo in iconList) + //{ + // menuInfo.IconList = iconList; + //} }); }).Start(); diff --git a/Control/UserControls/PannelCard/RightCardControl.xaml b/Control/UserControls/PannelCard/RightCardControl.xaml index 395c73a..b6e1da2 100644 --- a/Control/UserControls/PannelCard/RightCardControl.xaml +++ b/Control/UserControls/PannelCard/RightCardControl.xaml @@ -13,6 +13,7 @@ xmlns:ot="clr-namespace:GeekDesk.Control.Other" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800" + AllowDrop="True" > @@ -280,7 +281,7 @@ + Visibility="Collapsed" + /> diff --git a/GeekDesk.csproj b/GeekDesk.csproj index c5f9d2f..f99f8b2 100644 --- a/GeekDesk.csproj +++ b/GeekDesk.csproj @@ -108,6 +108,7 @@ packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + packages\System.Diagnostics.DiagnosticSource.4.7.1\lib\net46\System.Diagnostics.DiagnosticSource.dll @@ -131,6 +132,7 @@ packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 5073c46..d3082e7 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -131,6 +131,8 @@ namespace GeekDesk if (!RunTimeStatus.EVERYTHING_NEW_SEARCH) { RunTimeStatus.EVERYTHING_NEW_SEARCH = true; + //显示搜索结果列表 + RightCard.VisibilitySearchCard(Visibility.Visible); object obj = RightCard.VerticalCard.Content; if (obj != null) { @@ -175,16 +177,15 @@ namespace GeekDesk { ObservableCollection resList = new ObservableCollection(); - DateTime bf = DateTime.Now; - ObservableCollection iconBakList = EveryThingUtil.Search(inputText); - - foreach (IconInfo icon in iconBakList) + if (appData.AppConfig.EnableEveryThing == true) { - resList.Add(icon); + ObservableCollection iconBakList = EveryThingUtil.Search(inputText); + foreach (IconInfo icon in iconBakList) + { + resList.Add(icon); + } } - DateTime af = DateTime.Now; - //GeekDesk数据搜索 ObservableCollection menuList = appData.MenuList; foreach (MenuInfo menu in menuList) @@ -200,17 +201,17 @@ namespace GeekDesk } } } - Console.WriteLine("查询耗时:{0}ms.", af.Subtract(bf).TotalMilliseconds); this.Dispatcher.Invoke(() => { + if (appData.AppConfig.EnableEveryThing == true) + { + TotalMsgBtn.Visibility = Visibility.Visible; + } 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(); @@ -338,9 +339,8 @@ namespace GeekDesk SearchBox.Width = 0; TotalMsgBtn.Content = "0 of 0"; TotalMsgBtn.Visibility = Visibility.Hidden; + RightCard.VerticalCard.Content = null; RightCard.VisibilitySearchCard(Visibility.Collapsed); - - SearchIconList.RemoveAll(); }); }).Start(); } diff --git a/Plugins/EveryThing/EveryThingUtil.cs b/Plugins/EveryThing/EveryThingUtil.cs index 329318d..bfea1b8 100644 --- a/Plugins/EveryThing/EveryThingUtil.cs +++ b/Plugins/EveryThing/EveryThingUtil.cs @@ -3,11 +3,14 @@ using GeekDesk.Plugins.EveryThing.Constant; using GeekDesk.Util; using GeekDesk.ViewModel; using System; +using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Configuration.Install; using System.Diagnostics; using System.Drawing; using System.Linq; +using System.ServiceProcess; using System.Text; using System.Threading; using System.Threading.Tasks; @@ -17,69 +20,58 @@ namespace GeekDesk.Plugins.EveryThing public class EveryThingUtil { - //检查是否是由GeekDesk启动的EveryThing - private static bool IsByGeekDesk = true; //每次加载20条 private static long pageCount = 20; private static UInt32 ui = 0; - private static Process serviceProcess = null; - private static Process exeProcess = null; - - public static void EnableEveryThing(int delayTime = 2000) { string pluginsPath = Constants.PLUGINS_PATH; bool Is64Bit = Environment.Is64BitOperatingSystem; string everyThingPath = pluginsPath + "/EveryThing/" + (Is64Bit ? 64 : 32) + "/EveryThing.exe"; - + string installUtilPath = "C:\\Windows\\Microsoft.NET\\Framework"+ (Is64Bit ? "64" : "") + "\\v4.0.30319\\InstallUtil.exe"; new Thread(() => { try { Thread.Sleep(delayTime); - //判断EveryThing服务是否已启动 - bool enabled = false; - Process[] processList = Process.GetProcesses(); - foreach (System.Diagnostics.Process process in processList) + //判断EveryThing服务是否存在 + ServiceController sc = GetService("Everything"); + if (sc != null) { - if (process.ProcessName.ToUpper().Equals("EVERYTHING")) + //判断是否启动 + if (sc.Status != ServiceControllerStatus.StartPending + && sc.Status != ServiceControllerStatus.Running) { - enabled = true; - IsByGeekDesk = false; - break; + //启动服务 + EveryThingService(ServiceType.START); } - } - if (!enabled) + } else { - //启动服务 - serviceProcess = new Process(); - serviceProcess.StartInfo.FileName = everyThingPath; - serviceProcess.StartInfo.UseShellExecute = true; - serviceProcess.StartInfo.Verb = "runas"; - serviceProcess.StartInfo.Arguments = " -svc"; - serviceProcess.Start(); + //安装服务 + EveryThingService(ServiceType.INSTALL); } Thread.Sleep(2000); - processList = Process.GetProcesses(); - //启动程序 - exeProcess = new Process(); - exeProcess.StartInfo.FileName = everyThingPath; - exeProcess.Start(); - int waitTime = 5000; - while (true && waitTime > 0) + if (GetService("Everything") != null) { - Thread.Sleep(100); - waitTime -= 100; - exeProcess.CloseMainWindow(); + //启动程序 + Process exeProcess = new Process(); + exeProcess.StartInfo.FileName = everyThingPath; + exeProcess.Start(); + int waitTime = 5000; + while (true && waitTime > 0) + { + Thread.Sleep(100); + waitTime -= 100; + exeProcess.CloseMainWindow(); + } } - } catch (Exception e) { @@ -89,29 +81,84 @@ namespace GeekDesk.Plugins.EveryThing } + enum ServiceType + { + START, + STOP, + INSTALL, + UNINSTALL + } + private static void EveryThingService(ServiceType type) + { + string pluginsPath = Constants.PLUGINS_PATH; + bool Is64Bit = Environment.Is64BitOperatingSystem; + string everyThingPath = pluginsPath + "/EveryThing/" + (Is64Bit ? 64 : 32) + "/EveryThing.exe"; + string installUtilPath = "C:\\Windows\\Microsoft.NET\\Framework" + (Is64Bit ? "64" : "") + "\\v4.0.30319\\InstallUtil.exe"; + + Process p = new Process(); + p.StartInfo.FileName = everyThingPath; + string arg; + switch(type) + { + default: + arg = "-start-service"; + break; + case ServiceType.STOP: + arg = "-stop-service"; + break; + case ServiceType.INSTALL: + arg = "-install-service"; + break; + case ServiceType.UNINSTALL: + arg = "-uninstall-service"; + break; + } + p.StartInfo.Arguments = arg; + p.Start(); + } - public static void DisableEveryThing() + public static ServiceController GetService(string serviceName) + { + ServiceController[] services = ServiceController.GetServices(); + foreach (ServiceController s in services) + { + if (s.ServiceName.ToLower().Equals(serviceName.ToLower())) + { + return s; + } + } + return null; + } + + + + + public static void DisableEveryThing(bool uninstall = false) { try { - if (IsByGeekDesk) + if (Environment.Is64BitOperatingSystem) { - if (Environment.Is64BitOperatingSystem) - { - EveryThing64.Everything_Exit(); - } - else - { - EveryThing32.Everything_Exit(); - } + EveryThing64.Everything_Exit(); + } + else + { + EveryThing32.Everything_Exit(); } - if (exeProcess != null) exeProcess.Kill(); - if (serviceProcess != null) serviceProcess.Kill(); - } catch (Exception e) - { - LogUtil.WriteErrorLog(e); } + catch (Exception e) { } + try + { + if (uninstall) + { + EveryThingService(ServiceType.UNINSTALL); + } else + { + EveryThingService(ServiceType.STOP); + } + } + catch (Exception e) { } } diff --git a/Util/ProcessUtil.cs b/Util/ProcessUtil.cs index 9581de5..278c935 100644 --- a/Util/ProcessUtil.cs +++ b/Util/ProcessUtil.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; @@ -240,6 +241,37 @@ namespace GeekDesk.Util } + [Flags] + private enum ProcessAccessFlags : uint + { + QueryLimitedInformation = 0x00001000 + } + + [DllImport("kernel32.dll", SetLastError = true)] + private static extern bool QueryFullProcessImageName( + [In] IntPtr hProcess, + [In] int dwFlags, + [Out] StringBuilder lpExeName, + ref int lpdwSize); + + [DllImport("kernel32.dll", SetLastError = true)] + private static extern IntPtr OpenProcess( + ProcessAccessFlags processAccess, + bool bInheritHandle, + int processId); + + public static String GetProcessFilename(Process p) + { + int capacity = 2000; + StringBuilder builder = new StringBuilder(capacity); + IntPtr ptr = OpenProcess(ProcessAccessFlags.QueryLimitedInformation, false, p.Id); + if (!QueryFullProcessImageName(ptr, 0, builder, ref capacity)) + { + return String.Empty; + } + return builder.ToString(); + } + } }