mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-10 13:35:31 +02:00
fix program plugin doesn't work in XP issue.
This commit is contained in:
58
WinAlfred.Plugin.System/DirectoryIndicator.cs
Normal file
58
WinAlfred.Plugin.System/DirectoryIndicator.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace WinAlfred.Plugin.System
|
||||
{
|
||||
public class DirectoryIndicator : ISystemPlugin
|
||||
{
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
if (string.IsNullOrEmpty(query.RawQuery)) return results;
|
||||
|
||||
if (CheckIfDirectory(query.RawQuery))
|
||||
{
|
||||
Result result = new Result
|
||||
{
|
||||
Title = "Open this directory",
|
||||
SubTitle = string.Format("path: {0}", query.RawQuery),
|
||||
Score = 50,
|
||||
IcoPath = "Images/folder.png",
|
||||
Action = () => Process.Start(query.RawQuery)
|
||||
};
|
||||
results.Add(result);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private bool CheckIfDirectory(string path)
|
||||
{
|
||||
return Directory.Exists(path);
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "DirectoryIndicator";
|
||||
}
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return "DirectoryIndicator";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Win32;
|
||||
@@ -27,6 +28,12 @@ namespace WinAlfred.Plugin.System
|
||||
|
||||
List<Program> installedList = new List<Program>();
|
||||
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner,[Out] StringBuilder lpszPath, int nFolder, bool fCreate);
|
||||
const int CSIDL_COMMON_STARTMENU = 0x16; // \Windows\Start Menu\Programs
|
||||
const int CSIDL_COMMON_PROGRAMS = 0x17;
|
||||
|
||||
public List<Result> Query(Query query)
|
||||
{
|
||||
if (string.IsNullOrEmpty(query.RawQuery) || query.RawQuery.EndsWith(" ") || query.RawQuery.Length <= 1) return new List<Result>();
|
||||
@@ -64,7 +71,10 @@ namespace WinAlfred.Plugin.System
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
indexDirectory.Add(Environment.GetFolderPath(Environment.SpecialFolder.Programs));
|
||||
indexDirectory.Add(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\Microsoft\Windows\Start Menu\Programs");
|
||||
|
||||
StringBuilder commonStartMenuPath = new StringBuilder(560);
|
||||
SHGetSpecialFolderPath(IntPtr.Zero, commonStartMenuPath, CSIDL_COMMON_PROGRAMS, false);
|
||||
indexDirectory.Add(commonStartMenuPath.ToString());
|
||||
|
||||
GetAppFromStartMenu();
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="CMD.cs" />
|
||||
<Compile Include="Common\ChineseToPinYin.cs" />
|
||||
<Compile Include="DirectoryIndicator.cs" />
|
||||
<Compile Include="ISystemPlugin.cs" />
|
||||
<Compile Include="Programs.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
|
||||
Reference in New Issue
Block a user