mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-24 23:49:40 +01:00
System Plugin File Structure change.
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins.Program.ProgramSources
|
||||
{
|
||||
[global::System.ComponentModel.Browsable(false)]
|
||||
public class AppPathsProgramSource: AbstractProgramSource
|
||||
{
|
||||
public AppPathsProgramSource()
|
||||
{
|
||||
this.BonusPoints = -10;
|
||||
}
|
||||
|
||||
public AppPathsProgramSource(ProgramSource source)
|
||||
: this()
|
||||
{
|
||||
this.BonusPoints = source.BonusPoints;
|
||||
}
|
||||
|
||||
public override List<Program> LoadPrograms()
|
||||
{
|
||||
var list = new List<Program>();
|
||||
ReadAppPaths(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths", list);
|
||||
ReadAppPaths(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths", list); //TODO: need test more on 64-bit
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private void ReadAppPaths(string rootpath, List<Program> list)
|
||||
{
|
||||
using (var root = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(rootpath))
|
||||
{
|
||||
if (root == null) return;
|
||||
foreach (var item in root.GetSubKeyNames())
|
||||
{
|
||||
using (var key = root.OpenSubKey(item))
|
||||
{
|
||||
object path = key.GetValue("");
|
||||
if (path is string && global::System.IO.File.Exists((string)path))
|
||||
{
|
||||
var entry = CreateEntry((string)path);
|
||||
entry.ExecuteName = item;
|
||||
list.Add(entry);
|
||||
}
|
||||
|
||||
key.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return typeof(AppPathsProgramSource).Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins.Program.ProgramSources
|
||||
{
|
||||
[global::System.ComponentModel.Browsable(false)]
|
||||
public class CommonStartMenuProgramSource : FileSystemProgramSource
|
||||
{
|
||||
[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;
|
||||
|
||||
private static string getPath()
|
||||
{
|
||||
StringBuilder commonStartMenuPath = new StringBuilder(560);
|
||||
SHGetSpecialFolderPath(IntPtr.Zero, commonStartMenuPath, CSIDL_COMMON_PROGRAMS, false);
|
||||
|
||||
return commonStartMenuPath.ToString();
|
||||
}
|
||||
|
||||
public CommonStartMenuProgramSource()
|
||||
: base(getPath())
|
||||
{
|
||||
}
|
||||
|
||||
public CommonStartMenuProgramSource(ProgramSource source)
|
||||
: this()
|
||||
{
|
||||
this.BonusPoints = source.BonusPoints;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return typeof(CommonStartMenuProgramSource).Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins.Program.ProgramSources {
|
||||
//TODO: Create Deep Version that grabs all subfolders like FileSystemProgramSource
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class FileSystemFolderSourceShallow : FileSystemProgramSource {
|
||||
//private static Dictionary<string, DirectoryInfo[]> parentDirectories = new Dictionary<string, DirectoryInfo[]>();
|
||||
|
||||
|
||||
public FileSystemFolderSourceShallow(string baseDirectory)
|
||||
: base(baseDirectory) { }
|
||||
|
||||
public FileSystemFolderSourceShallow(ProgramSource source)
|
||||
: base(source) { }
|
||||
|
||||
public override List<Program> LoadPrograms() {
|
||||
List<Program> list = new List<Program>();
|
||||
|
||||
foreach (var Folder in Directory.GetDirectories(BaseDirectory)) {
|
||||
list.Add(CreateEntry(Folder));
|
||||
}
|
||||
|
||||
|
||||
foreach (string file in Directory.GetFiles(base.BaseDirectory)) {
|
||||
if (Suffixes.Any(o => file.EndsWith("." + o))) {
|
||||
list.Add(CreateEntry(file));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public override string ToString() {
|
||||
return typeof(UserStartMenuProgramSource).Name;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public class FolderSource : IProgramSource {
|
||||
private PluginInitContext context;
|
||||
public string Location { get; set; }
|
||||
public int BonusPoints { get; set; }
|
||||
|
||||
public FolderSource(string Location) {
|
||||
this.Location = Location;
|
||||
}
|
||||
|
||||
public List<Program> LoadPrograms() {
|
||||
List<Result> results = new List<Result>();
|
||||
|
||||
if (Directory.Exists(Location)) {
|
||||
// show all child directory
|
||||
if (Location.EndsWith("\\") || Location.EndsWith("/")) {
|
||||
var dirInfo = new DirectoryInfo(Location);
|
||||
var dirs = dirInfo.GetDirectories();
|
||||
|
||||
var parentDirKey = Location.TrimEnd('\\', '/');
|
||||
if (!parentDirectories.ContainsKey(parentDirKey))
|
||||
parentDirectories.Add(parentDirKey, dirs);
|
||||
|
||||
foreach (var dir in dirs) {
|
||||
if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
|
||||
continue;
|
||||
|
||||
var dirPath = dir.FullName;
|
||||
Result result = new Result {
|
||||
Title = dir.Name,
|
||||
IcoPath = "Images/folder.png",
|
||||
Action = (c) => {
|
||||
context.ChangeQuery(dirPath);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
results.Add(result);
|
||||
}
|
||||
|
||||
if (results.Count == 0) {
|
||||
Result result = new Result {
|
||||
Title = "Open this directory",
|
||||
SubTitle = "No files in this directory",
|
||||
IcoPath = "Images/folder.png",
|
||||
Action = (c) => {
|
||||
Process.Start(Location);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
results.Add(result);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Result result = new Result {
|
||||
Title = "Open this directory",
|
||||
SubTitle = string.Format("path: {0}", Location),
|
||||
Score = 50,
|
||||
IcoPath = "Images/folder.png",
|
||||
Action = (c) => {
|
||||
Process.Start(Location);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
results.Add(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// change to search in current directory
|
||||
var parentDir = Path.GetDirectoryName(Location);
|
||||
if (!string.IsNullOrEmpty(parentDir) && results.Count == 0) {
|
||||
parentDir = parentDir.TrimEnd('\\', '/');
|
||||
if (parentDirectories.ContainsKey(parentDir)) {
|
||||
|
||||
var dirs = parentDirectories[parentDir];
|
||||
var queryFileName = Path.GetFileName(Location).ToLower();
|
||||
var fuzzy = FuzzyMatcher.Create(queryFileName);
|
||||
foreach (var dir in dirs) {
|
||||
if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
|
||||
continue;
|
||||
|
||||
var matchResult = fuzzy.Evaluate(dir.Name);
|
||||
if (!matchResult.Success)
|
||||
continue;
|
||||
|
||||
var dirPath = dir.FullName;
|
||||
Result result = new Result {
|
||||
Title = dir.Name,
|
||||
IcoPath = "Images/folder.png",
|
||||
Score = matchResult.Score,
|
||||
Action = (c) => {
|
||||
context.ChangeQuery(dirPath);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
results.Add(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
throw new Exception("Debug this!");
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins.Program.ProgramSources
|
||||
{
|
||||
public class FileSystemProgramSource : AbstractProgramSource
|
||||
{
|
||||
public string BaseDirectory;
|
||||
public List<string> Suffixes = new List<string>() { "lnk", "exe", "appref-ms" };
|
||||
|
||||
public FileSystemProgramSource(string baseDirectory)
|
||||
{
|
||||
BaseDirectory = baseDirectory;
|
||||
}
|
||||
|
||||
public FileSystemProgramSource(string baseDirectory, List<string> suffixes)
|
||||
: this(baseDirectory)
|
||||
{
|
||||
Suffixes = suffixes;
|
||||
}
|
||||
|
||||
public FileSystemProgramSource(ProgramSource source)
|
||||
: this(source.Location)
|
||||
{
|
||||
this.BonusPoints = source.BonusPoints;
|
||||
}
|
||||
|
||||
public override List<Program> LoadPrograms()
|
||||
{
|
||||
List<Program> list = new List<Program>();
|
||||
GetAppFromDirectory(BaseDirectory, list);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private void GetAppFromDirectory(string path, List<Program> list)
|
||||
{
|
||||
foreach (string file in Directory.GetFiles(path))
|
||||
{
|
||||
if (Suffixes.Any(o => file.EndsWith("." + o)))
|
||||
{
|
||||
Program p = CreateEntry(file);
|
||||
list.Add(p);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var subDirectory in Directory.GetDirectories(path))
|
||||
{
|
||||
GetAppFromDirectory(subDirectory, list);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return typeof(FileSystemProgramSource).Name + ":" + this.BaseDirectory;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins.Program.ProgramSources
|
||||
{
|
||||
public class PortableAppsProgramSource : AbstractProgramSource
|
||||
{
|
||||
public string BaseDirectory;
|
||||
|
||||
public PortableAppsProgramSource(string baseDirectory)
|
||||
{
|
||||
BaseDirectory = baseDirectory;
|
||||
}
|
||||
|
||||
public PortableAppsProgramSource(ProgramSource source)
|
||||
: this(source.Location)
|
||||
{
|
||||
this.BonusPoints = source.BonusPoints;
|
||||
}
|
||||
|
||||
public override List<Program> LoadPrograms()
|
||||
{
|
||||
List<Program> list = new List<Program>();
|
||||
var ini = new IniParser.Parser.IniDataParser();
|
||||
ini.Configuration.AllowDuplicateKeys = true;
|
||||
|
||||
string menuSettingsPath = Path.Combine(BaseDirectory, @"PortableApps.com\Data\PortableAppsMenu.ini");
|
||||
|
||||
IniParser.Model.KeyDataCollection appsRenamed = null, appsRecategorized = null, appsHidden = null;
|
||||
if (File.Exists(menuSettingsPath))
|
||||
{
|
||||
var menuSettings = ini.Parse(File.ReadAllText(menuSettingsPath, Encoding.Default));
|
||||
appsRenamed = menuSettings["AppsRenamed"];
|
||||
appsRecategorized = menuSettings["AppsRecategorized"];
|
||||
appsHidden = menuSettings["AppsHidden"];
|
||||
}
|
||||
if (appsRenamed == null) appsRenamed = new IniParser.Model.KeyDataCollection();
|
||||
if (appsRecategorized == null) appsRecategorized = new IniParser.Model.KeyDataCollection();
|
||||
if (appsHidden == null) appsHidden = new IniParser.Model.KeyDataCollection();
|
||||
|
||||
foreach (var appDir in Directory.GetDirectories(BaseDirectory))
|
||||
{
|
||||
var appDirName = Path.GetDirectoryName(appDir);
|
||||
var appInfoPath = Path.Combine(appDir, @"App\AppInfo\appinfo.ini");
|
||||
var appInfoValid = false;
|
||||
|
||||
if (File.Exists(appInfoPath))
|
||||
{
|
||||
var appInfo = ini.Parse(File.ReadAllText(appInfoPath, Encoding.Default));
|
||||
var appName = appInfo["Details"]["Name"] ?? appDirName;
|
||||
var control = appInfo["Control"];
|
||||
int count;
|
||||
if (Int32.TryParse(control["Icons"], out count))
|
||||
{
|
||||
appInfoValid = true;
|
||||
for (int i = 1; i <= count; i++)
|
||||
{
|
||||
string cmdline, name, icon;
|
||||
cmdline = control[String.Format("Start{0}", i)];
|
||||
name = control[String.Format("Name{0}", i)];
|
||||
icon = control[String.Format("ExtractIcon{0}", i)];
|
||||
|
||||
if (i == 1)
|
||||
{
|
||||
if (cmdline == null) cmdline = control["Start"];
|
||||
if (cmdline == null) continue;
|
||||
|
||||
if (name == null) name = appName;
|
||||
if (icon == null) icon = control["ExtractIcon"];
|
||||
if (icon == null && !File.Exists(icon = Path.Combine(appDir, @"App\AppInfo\appicon.ico"))) icon = null;
|
||||
}
|
||||
|
||||
if (cmdline == null) continue;
|
||||
if (name == null) name = String.Format("{0} #{1}", appName, i);
|
||||
if (icon == null) icon = Path.Combine(appDir, String.Format(@"App\AppInfo\appicon{0}.ico", i));
|
||||
|
||||
cmdline = Path.Combine(appDir, cmdline);
|
||||
var menuKey = (appDirName + @"\" + cmdline).ToLower();
|
||||
|
||||
var renamed = appsRenamed[menuKey];
|
||||
if (renamed != null)
|
||||
name = renamed;
|
||||
|
||||
var hidden = appsHidden[menuKey] == "true";
|
||||
|
||||
if (!hidden)
|
||||
{
|
||||
Program p = new Program()
|
||||
{
|
||||
Title = name,
|
||||
IcoPath = icon,
|
||||
ExecutePath = cmdline
|
||||
};
|
||||
list.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!appInfoValid)
|
||||
{
|
||||
foreach (var item in Directory.GetFiles(appDir, "*.exe", SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
var menuKey = Path.GetFullPath(item).Substring(Path.GetFullPath(BaseDirectory).Length + 1).ToLower();
|
||||
|
||||
if (appsHidden[menuKey] != "true")
|
||||
{
|
||||
var p = CreateEntry(item);
|
||||
var renamed = appsRenamed[menuKey];
|
||||
if (renamed != null)
|
||||
p.Title = renamed;
|
||||
|
||||
list.Add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return typeof(PortableAppsProgramSource).Name + ":" + this.BaseDirectory;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins.Program.ProgramSources
|
||||
{
|
||||
[global::System.ComponentModel.Browsable(false)]
|
||||
public class UserStartMenuProgramSource : FileSystemProgramSource
|
||||
{
|
||||
public UserStartMenuProgramSource()
|
||||
: base(Environment.GetFolderPath(Environment.SpecialFolder.Programs))
|
||||
{
|
||||
}
|
||||
|
||||
public UserStartMenuProgramSource(ProgramSource source)
|
||||
: this()
|
||||
{
|
||||
this.BonusPoints = source.BonusPoints;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return typeof(UserStartMenuProgramSource).Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user