mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
Rename Wox.Plugin.System to Wox.Plugin.SystemPlugins
Finish moving ProgramSetting into featureBox
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins.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,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins.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,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins.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,133 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using IniParser;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins.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,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Wox.Infrastructure.Storage.UserSettings;
|
||||
|
||||
namespace Wox.Plugin.SystemPlugins.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