PowerToys/Wox.Plugin.SystemPlugins/Program/ProgramSources/AppPathsProgramSource.cs

57 lines
1.8 KiB
C#
Raw Normal View History

2014-03-30 11:16:44 +08:00
using System.Collections.Generic;
2014-03-23 16:17:41 +08:00
using Wox.Infrastructure.Storage.UserSettings;
2014-03-30 11:16:44 +08:00
namespace Wox.Plugin.SystemPlugins.Program.ProgramSources
{
[global::System.ComponentModel.Browsable(false)]
public class AppPathsProgramSource: AbstractProgramSource
{
public AppPathsProgramSource()
{
this.BonusPoints = -10;
}
2014-03-23 16:17:41 +08:00
public AppPathsProgramSource(ProgramSource source)
: this()
{
2014-03-19 20:16:20 +08:00
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))
2014-03-20 04:15:05 +08:00
{
var entry = CreateEntry((string)path);
entry.ExecuteName = item;
list.Add(entry);
}
key.Close();
}
}
}
}
2014-03-19 20:16:20 +08:00
public override string ToString()
{
return typeof(AppPathsProgramSource).Name;
}
}
}