2014-12-15 22:58:49 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2016-01-07 05:34:42 +08:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Microsoft.Win32;
|
2015-11-01 06:40:11 +08:00
|
|
|
|
using Wox.Infrastructure.Logger;
|
2014-03-19 02:06:51 +08:00
|
|
|
|
|
2015-01-03 15:20:34 +08:00
|
|
|
|
namespace Wox.Plugin.Program.ProgramSources
|
2014-03-19 02:06:51 +08:00
|
|
|
|
{
|
2014-12-15 22:58:49 +08:00
|
|
|
|
[Serializable]
|
2016-01-07 05:34:42 +08:00
|
|
|
|
[Browsable(false)]
|
2015-11-01 06:40:11 +08:00
|
|
|
|
public class AppPathsProgramSource : AbstractProgramSource
|
2014-03-19 02:06:51 +08:00
|
|
|
|
{
|
|
|
|
|
public AppPathsProgramSource()
|
|
|
|
|
{
|
2015-11-01 06:40:11 +08:00
|
|
|
|
BonusPoints = -10;
|
2014-03-19 02:06:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-01 06:40:11 +08:00
|
|
|
|
public AppPathsProgramSource(ProgramSource source) : this()
|
2014-03-19 04:05:27 +08:00
|
|
|
|
{
|
2015-11-01 06:40:11 +08:00
|
|
|
|
BonusPoints = source.BonusPoints;
|
2014-03-19 04:05:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-19 02:06:51 +08:00
|
|
|
|
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)
|
|
|
|
|
{
|
2016-01-07 05:34:42 +08:00
|
|
|
|
using (var root = Registry.LocalMachine.OpenSubKey(rootpath))
|
2014-03-19 02:06:51 +08:00
|
|
|
|
{
|
|
|
|
|
if (root == null) return;
|
|
|
|
|
foreach (var item in root.GetSubKeyNames())
|
|
|
|
|
{
|
2015-11-01 06:40:11 +08:00
|
|
|
|
try
|
2014-03-19 02:06:51 +08:00
|
|
|
|
{
|
2015-11-01 06:40:11 +08:00
|
|
|
|
using (var key = root.OpenSubKey(item))
|
2014-03-20 04:15:05 +08:00
|
|
|
|
{
|
2015-11-01 06:40:11 +08:00
|
|
|
|
string path = key.GetValue("") as string;
|
2015-11-08 19:31:44 +08:00
|
|
|
|
if (string.IsNullOrEmpty(path)) continue;
|
2015-11-01 06:40:11 +08:00
|
|
|
|
|
|
|
|
|
// fix path like this ""\"C:\\folder\\executable.exe\"""
|
|
|
|
|
const int begin = 0;
|
|
|
|
|
int end = path.Length - 1;
|
|
|
|
|
const char quotationMark = '"';
|
|
|
|
|
if (path[begin] == quotationMark && path[end] == quotationMark)
|
|
|
|
|
{
|
|
|
|
|
path = path.Substring(begin + 1, path.Length - 2);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 05:34:42 +08:00
|
|
|
|
if (!File.Exists(path)) continue;
|
2015-11-01 06:40:11 +08:00
|
|
|
|
var entry = CreateEntry(path);
|
2016-04-24 20:35:21 +08:00
|
|
|
|
entry.ExecutableName = item;
|
2016-04-23 06:03:32 +08:00
|
|
|
|
entry.Source = this;
|
2014-03-20 04:15:05 +08:00
|
|
|
|
list.Add(entry);
|
|
|
|
|
}
|
2015-11-01 06:40:11 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2016-05-16 00:03:06 +08:00
|
|
|
|
Log.Exception(e);
|
2014-03-19 02:06:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-19 20:16:20 +08:00
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return typeof(AppPathsProgramSource).Name;
|
|
|
|
|
}
|
2014-03-19 02:06:51 +08:00
|
|
|
|
}
|
|
|
|
|
}
|