优化everything功能

This commit is contained in:
BookerLiu
2023-04-14 13:48:50 +08:00
parent a7181f6973
commit 41799251af
7 changed files with 155 additions and 71 deletions

View File

@@ -199,7 +199,7 @@ namespace GeekDesk.Control.UserControls.Config
EveryThingUtil.EnableEveryThing(0);
} else
{
EveryThingUtil.DisableEveryThing();
EveryThingUtil.DisableEveryThing(true);
}
}
}

View File

@@ -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();

View File

@@ -13,6 +13,7 @@
xmlns:ot="clr-namespace:GeekDesk.Control.Other"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
AllowDrop="True"
>
<UserControl.Resources>
<!--右侧栏样式动画-->
@@ -280,7 +281,7 @@
<hc:Card x:Name="VerticalCard"
Visibility="Visible"
Visibility="Collapsed"
BorderThickness="1"
Effect="{DynamicResource EffectShadow2}"
Margin="5,0,5,5" Grid.ColumnSpan="2"
@@ -303,6 +304,7 @@
Opacity="0.8"
DotDiameter="10"
Margin="-50,-150,0,0"
Visibility="Collapsed"/>
Visibility="Collapsed"
/>
</Grid>
</UserControl>

View File

@@ -108,6 +108,7 @@
<HintPath>packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" />
<Reference Include="System.Diagnostics.DiagnosticSource, Version=4.0.5.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Diagnostics.DiagnosticSource.4.7.1\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
@@ -131,6 +132,7 @@
<HintPath>packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Remoting" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>

View File

@@ -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<IconInfo> resList = new ObservableCollection<IconInfo>();
DateTime bf = DateTime.Now;
ObservableCollection<IconInfo> iconBakList = EveryThingUtil.Search(inputText);
foreach (IconInfo icon in iconBakList)
if (appData.AppConfig.EnableEveryThing == true)
{
resList.Add(icon);
ObservableCollection<IconInfo> iconBakList = EveryThingUtil.Search(inputText);
foreach (IconInfo icon in iconBakList)
{
resList.Add(icon);
}
}
DateTime af = DateTime.Now;
//GeekDesk数据搜索
ObservableCollection<MenuInfo> 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();
}

View File

@@ -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) { }
}

View File

@@ -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();
}
}
}