Merge branch 'master' into dev

This commit is contained in:
bao-qian 2016-07-27 19:58:37 +01:00
commit 2bff13d9e1
38 changed files with 281 additions and 350 deletions

View file

@ -1,23 +1,21 @@
## English
Before you report any bugs try search existing issues
Try search existing issues before you open new one
1. Please specify Wox version
- If you checkout from master/dev branch, please specify **commit number**
2. Please describe the steps to **reproduce** the bug
3. Please provide Windows version
4. Please provide Exception info if you have.
5. Please provide **logs** from `%APPDATA%\Wox\Logs` if you have.
6. Please provide screenshot if you have
1. Wox version / commit number:
2. Steps to **reproduce** the bug:
3. Windows version:
4. Exception:
5. **whole** log file `%APPDATA%\Wox\Logs\version\date.txt`):
6. Screenshot (optional):
## 中文 / Chinese
报 bug 之前搜索一下已经有的 issue
提问之前搜索一下已经有的 issue
1. 请提供 Wox 版本
- 如果你是从 master/dev branch checkout 的,请提供 **commit number**
2. 请提供如何**重现** bug 的步骤
3. 请提供 Windows 版本
4. 如果有 Exception/Crash Report 的话,请一并提供
5. 如果有 **logs** `%APPDATA%\Wox\Logs`)的话,请一并提供
6. 如果有截图的话,请一并提供
1. Wox 版本 / commit number
2. 如何**重现** bug
3. Windows 版本:
4. Exception
5. **整个** log 文件 `%APPDATA%\Wox\Logs\version\date.txt`
6. 截图 (可选):

View file

@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="wox_plugin_everything_is_not_running">Everything läuft nicht</system:String>
<system:String x:Key="wox_plugin_everything_is_not_running">Everything Service läuft nicht</system:String>
<system:String x:Key="wox_plugin_everything_query_error">Everything Plugin hat einen Fehler (drücke Enter zum kopieren der Fehlernachricht)</system:String>
<system:String x:Key="wox_plugin_everything_copied">kopiert</system:String>
<system:String x:Key="wox_plugin_everything_canot_start">Kann {0} nicht starten</system:String>

View file

@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="wox_plugin_everything_is_not_running">Everything is not running</system:String>
<system:String x:Key="wox_plugin_everything_is_not_running">Everything Service is not running</system:String>
<system:String x:Key="wox_plugin_everything_query_error">Error while querying Everything</system:String>
<system:String x:Key="wox_plugin_everything_copied">Copied</system:String>
<system:String x:Key="wox_plugin_everything_canot_start">Cant start {0}</system:String>

View file

@ -2,7 +2,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="wox_plugin_everything_is_not_running">Program Everything nie jest uruchomiony</system:String>
<system:String x:Key="wox_plugin_everything_is_not_running">Everything Service nie jest uruchomiony</system:String>
<system:String x:Key="wox_plugin_everything_query_error">Wystąpił błąd podczas pobierania wyników z Everything</system:String>
<system:String x:Key="wox_plugin_everything_copied">Skopiowano</system:String>
<system:String x:Key="wox_plugin_everything_canot_start">Nie udało się uruchomić {0}</system:String>

View file

@ -2,14 +2,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="wox_plugin_everything_is_not_running">Everything没有运行</system:String>
<system:String x:Key="wox_plugin_everything_query_error">Everything插件发生了一个错误回车拷贝具体错误信息</system:String>
<system:String x:Key="wox_plugin_everything_is_not_running">Everything Service 没有运行</system:String>
<system:String x:Key="wox_plugin_everything_query_error">Everything 插件发生了一个错误(回车拷贝具体错误信息)</system:String>
<system:String x:Key="wox_plugin_everything_copied">拷贝成功</system:String>
<system:String x:Key="wox_plugin_everything_canot_start">不能启动 {0}</system:String>
<system:String x:Key="wox_plugin_everything_open_containing_folder">打开所属文件夹</system:String>
<system:String x:Key="wox_plugin_everything_plugin_name">Everything</system:String>
<system:String x:Key="wox_plugin_everything_plugin_description">利用Everything搜索磁盘文件</system:String>
<system:String x:Key="wox_plugin_everything_plugin_description">利用 Everything 搜索磁盘文件</system:String>
<system:String x:Key="wox_plugin_everything_use_location_as_working_dir">使用应用程序的位置为可执行的工作目录</system:String>
</ResourceDictionary>

View file

@ -2,14 +2,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib">
<system:String x:Key="wox_plugin_everything_is_not_running">Everything沒有運行</system:String>
<system:String x:Key="wox_plugin_everything_query_error">Everything插件發生了一個錯誤回車拷貝具體錯誤信息</system:String>
<system:String x:Key="wox_plugin_everything_is_not_running">Everything Service 沒有運行</system:String>
<system:String x:Key="wox_plugin_everything_query_error">Everything 插件發生了一個錯誤(回車拷貝具體錯誤信息)</system:String>
<system:String x:Key="wox_plugin_everything_copied">拷貝成功</system:String>
<system:String x:Key="wox_plugin_everything_canot_start">不能啟動 {0}</system:String>
<system:String x:Key="wox_plugin_everything_open_containing_folder">打開所屬文件夾</system:String>
<system:String x:Key="wox_plugin_everything_plugin_name">Everything</system:String>
<system:String x:Key="wox_plugin_everything_plugin_description">利用Everything搜索磁盤文件</system:String>
<system:String x:Key="wox_plugin_everything_plugin_description">利用 Everything 搜索磁盤文件</system:String>
<system:String x:Key="wox_plugin_everything_use_location_as_working_dir">使用应用程序的位置为可执行的工作目录</system:String>
</ResourceDictionary>

View file

@ -142,6 +142,7 @@ namespace Wox.Plugin.Everything
Helper.ValidateDataDirectory(bundledSDKDirectory, sdkDirectory);
var sdkPath = Path.Combine(sdkDirectory, DLL);
Constant.EverythingSDKPath = sdkPath;
LoadLibrary(sdkPath);
}

View file

@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Windows;
using System.Windows.Forms;
using Wox.Plugin.Program.ProgramSources;
namespace Wox.Plugin.Program
{
@ -9,7 +10,7 @@ namespace Wox.Plugin.Program
/// </summary>
public partial class AddProgramSource
{
private ProgramSource _editing;
private FileSystemProgramSource _editing;
private Settings _settings;
public AddProgramSource(Settings settings)
@ -20,7 +21,7 @@ namespace Wox.Plugin.Program
Directory.Focus();
}
public AddProgramSource(ProgramSource edit, Settings settings)
public AddProgramSource(FileSystemProgramSource edit, Settings settings)
{
_editing = edit;
_settings = settings;
@ -51,12 +52,11 @@ namespace Wox.Plugin.Program
if(_editing == null)
{
var source = new ProgramSource
var source = new FileSystemProgramSource
{
Location = Directory.Text,
MaxDepth = max,
Suffixes = Suffixes.Text.Split(ProgramSource.SuffixSeperator),
Type = "FileSystemProgramSource",
Enabled = true
};
_settings.ProgramSources.Add(source);

View file

@ -1,33 +1,31 @@
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Wox.Infrastructure.Logger;
namespace Wox.Plugin.Program
{
internal class FileChangeWatcher
internal static class FileChangeWatcher
{
private static bool isIndexing;
private static List<string> watchedPath = new List<string>();
private static readonly List<string> WatchedPath = new List<string>();
public static void AddWatch(string path, string[] programSuffixes, bool includingSubDirectory = true)
{
if (watchedPath.Contains(path)) return;
if (WatchedPath.Contains(path)) return;
if (!Directory.Exists(path))
{
Log.Warn($"FileChangeWatcher: {path} doesn't exist");
return;
}
watchedPath.Add(path);
WatchedPath.Add(path);
foreach (string fileType in programSuffixes)
{
FileSystemWatcher watcher = new FileSystemWatcher
{
Path = path,
IncludeSubdirectories = includingSubDirectory,
Filter = string.Format("*.{0}", fileType),
Filter = $"*.{fileType}",
EnableRaisingEvents = true
};
watcher.Changed += FileChanged;
@ -39,15 +37,10 @@ namespace Wox.Plugin.Program
private static void FileChanged(object source, FileSystemEventArgs e)
{
if (!isIndexing)
Task.Run(() =>
{
Task.Run(() =>
{
Main.IndexPrograms();
isIndexing = false;
});
}
Main.IndexPrograms();
});
}
}
}

View file

@ -14,16 +14,7 @@ namespace Wox.Plugin.Program
{
public class Main : ISettingProvider, IPlugin, IPluginI18n, IContextMenu, ISavable
{
private static object lockObject = new object();
private static List<Program> _programs = new List<Program>();
private static List<IProgramSource> _sources = new List<IProgramSource>();
private static readonly Dictionary<string, Type> SourceTypes = new Dictionary<string, Type>
{
{"FileSystemProgramSource", typeof(FileSystemProgramSource)},
{"CommonStartMenuProgramSource", typeof(CommonStartMenuProgramSource)},
{"UserStartMenuProgramSource", typeof(UserStartMenuProgramSource)},
{"AppPathsProgramSource", typeof(AppPathsProgramSource)}
};
private PluginInitContext _context;
@ -36,8 +27,15 @@ namespace Wox.Plugin.Program
{
_settingsStorage = new PluginJsonStorage<Settings>();
_settings = _settingsStorage.Load();
_cacheStorage = new BinaryStorage<ProgramIndexCache>();
_cache = _cacheStorage.Load();
Stopwatch.Debug("Preload programs", () =>
{
_cacheStorage = new BinaryStorage<ProgramIndexCache>();
_cache = _cacheStorage.Load();
_programs = _cache.Programs;
});
Log.Info($"Preload {_programs.Count} programs from cache");
Stopwatch.Debug("Program Index", IndexPrograms);
}
public void Save()
@ -50,29 +48,35 @@ namespace Wox.Plugin.Program
{
var results = _programs.AsParallel()
.Where(p => Score(p, query.Search) > 0)
.Select(ScoreFilter)
.OrderByDescending(p => p.Score)
.Select(p => new Result
{
Title = p.Title,
SubTitle = p.Path,
IcoPath = p.IcoPath,
Score = p.Score,
ContextData = p,
Action = e =>
{
var info = new ProcessStartInfo
{
FileName = p.Path,
WorkingDirectory = p.Directory
};
var hide = StartProcess(info);
return hide;
}
}).ToList();
.Select(ResultFromProgram)
.ToList();
return results;
}
public Result ResultFromProgram(Program p)
{
var result = new Result
{
Title = p.Title,
SubTitle = p.Path,
IcoPath = p.IcoPath,
Score = p.Score,
ContextData = p,
Action = e =>
{
var info = new ProcessStartInfo
{
FileName = p.Path,
WorkingDirectory = p.Directory
};
var hide = StartProcess(info);
return hide;
}
};
return result;
}
private int Score(Program program, string query)
{
var score1 = StringMatcher.Score(program.Title, query);
@ -86,101 +90,83 @@ namespace Wox.Plugin.Program
public void Init(PluginInitContext context)
{
_context = context;
Stopwatch.Debug("Preload programs", () =>
{
_programs = _cache.Programs;
});
Log.Info($"Preload {_programs.Count} programs from cache");
Stopwatch.Debug("Program Index", IndexPrograms);
}
public static void IndexPrograms()
{
// todo why there is a lock??
lock (lockObject)
{
var sources = DefaultProgramSources();
if (_settings.ProgramSources != null &&
_settings.ProgramSources.Count(o => o.Enabled) > 0)
{
sources.AddRange(_settings.ProgramSources);
}
var sources = ProgramSources();
_sources = sources.AsParallel()
.Where(s => s.Enabled && SourceTypes.ContainsKey(s.Type))
.Select(s =>
{
var sourceClass = SourceTypes[s.Type];
var constructorInfo = sourceClass.GetConstructor(new[] { typeof(ProgramSource) });
var programSource = constructorInfo?.Invoke(new object[] { s }) as IProgramSource;
return programSource;
})
.Where(s => s != null).ToList();
var programs = sources.AsParallel()
.SelectMany(s => s.LoadPrograms())
// filter duplicate program
.GroupBy(x => new { ExecutePath = x.Path, ExecuteName = x.ExecutableName })
.Select(g => g.First());
programs = programs.Select(ScoreFilter);
_programs = _sources.AsParallel()
.SelectMany(s => s.LoadPrograms())
// filter duplicate program
.GroupBy(x => new { ExecutePath = x.Path, ExecuteName = x.ExecutableName })
.Select(g => g.First())
.ToList();
_cache.Programs = _programs;
}
_programs = programs.ToList();
_cache.Programs = _programs;
}
/// <summary>
/// Load program sources that wox always provide
/// </summary>
private static List<ProgramSource> DefaultProgramSources()
private static List<ProgramSource> ProgramSources()
{
var list = new List<ProgramSource>
var sources = new List<ProgramSource>
{
new ProgramSource
new CommonStartMenuProgramSource
{
BonusPoints = 0,
Enabled = _settings.EnableStartMenuSource,
Type = "CommonStartMenuProgramSource"
},
new ProgramSource
new UserStartMenuProgramSource
{
BonusPoints = 0,
Enabled = _settings.EnableStartMenuSource,
Type = "UserStartMenuProgramSource"
},
new ProgramSource
new AppPathsProgramSource
{
BonusPoints = -10,
Enabled = _settings.EnableRegistrySource,
Type = "AppPathsProgramSource"
}
};
return list;
if (_settings.ProgramSources.Count(o => o.Enabled) > 0)
{
sources.AddRange(_settings.ProgramSources);
}
return sources;
}
private Program ScoreFilter(Program p)
private static Program ScoreFilter(Program p)
{
p.Score += p.Source.BonusPoints;
var start = new[] { "启动", "start" };
var doc = new[] { "帮助", "help", "文档", "documentation" };
var uninstall = new[] { "卸载", "uninstall" };
if (p.Title.Contains("启动") || p.Title.ToLower().Contains("start"))
var contained = start.Any(s => p.Title.ToLower().Contains(s));
if (contained)
{
p.Score += 10;
if (p.Title.Contains("帮助") || p.Title.ToLower().Contains("help") || p.Title.Contains("文档") || p.Title.ToLower().Contains("documentation"))
}
contained = doc.Any(d => p.Title.ToLower().Contains(d));
if (contained)
{
p.Score -= 10;
if (p.Title.Contains("卸载") || p.Title.ToLower().Contains("uninstall"))
}
contained = uninstall.Any(u => p.Title.ToLower().Contains(u));
if (contained)
{
p.Score -= 20;
}
return p;
}
#region ISettingProvider Members
public Control CreateSettingPanel()
{
return new ProgramSetting(_context, _settings);
}
#endregion
public string GetTranslatedPluginTitle()
{
return _context.API.GetTranslation("wox_plugin_program_plugin_name");

View file

@ -2,6 +2,7 @@ using System;
using System.Text.RegularExpressions;
using System.Threading;
using Wox.Infrastructure;
using Wox.Plugin.Program.ProgramSources;
namespace Wox.Plugin.Program
{
@ -14,6 +15,6 @@ namespace Wox.Plugin.Program
public string Directory { get; set; }
public string ExecutableName { get; set; }
public int Score { get; set; }
public IProgramSource Source { get; set; }
public ProgramSource Source { get; set; }
}
}

View file

@ -2,6 +2,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Wox.Plugin.Program.ProgramSources;
namespace Wox.Plugin.Program
{
@ -50,7 +51,7 @@ namespace Wox.Plugin.Program
private void btnDeleteProgramSource_OnClick(object sender, RoutedEventArgs e)
{
ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
var selectedProgramSource = programSourceView.SelectedItem as FileSystemProgramSource;
if (selectedProgramSource != null)
{
string msg = string.Format(context.API.GetTranslation("wox_plugin_program_delete_program_source"), selectedProgramSource.Location);
@ -70,7 +71,7 @@ namespace Wox.Plugin.Program
private void btnEditProgramSource_OnClick(object sender, RoutedEventArgs e)
{
ProgramSource selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
var selectedProgramSource = programSourceView.SelectedItem as FileSystemProgramSource;
if (selectedProgramSource != null)
{
var add = new AddProgramSource(selectedProgramSource, _settings);
@ -119,10 +120,9 @@ namespace Wox.Plugin.Program
{
if (Directory.Exists(s))
{
_settings.ProgramSources.Add(new ProgramSource
_settings.ProgramSources.Add(new FileSystemProgramSource
{
Location = s,
Type = "FileSystemProgramSource",
Enabled = true
});

View file

@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
namespace Wox.Plugin.Program
{
[Serializable]
public class ProgramSource
{
public string Location { get; set; }
public string Type { get; set; }
public int BonusPoints { get; set; }
public bool Enabled { get; set; }
// happlebao todo: temp hack for program suffixes
public string[] Suffixes { get; set; } = {"bat", "appref-ms", "exe", "lnk"};
public const char SuffixSeperator = ';';
public int MaxDepth { get; set; }
public Dictionary<string, string> Meta { get; set; }
public override string ToString()
{
return (Type ?? "") + ":" + Location ?? "";
}
}
}

View file

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using Microsoft.Win32;
using Wox.Infrastructure.Logger;
@ -8,24 +7,19 @@ using Wox.Infrastructure.Logger;
namespace Wox.Plugin.Program.ProgramSources
{
[Serializable]
[Browsable(false)]
public class AppPathsProgramSource : AbstractProgramSource
public class AppPathsProgramSource : ProgramSource
{
public AppPathsProgramSource()
{
BonusPoints = -10;
}
public AppPathsProgramSource(ProgramSource source) : 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
ReadAppPaths(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths", list);
//TODO: need test more on 64-bit
return list;
}
@ -40,12 +34,12 @@ namespace Wox.Plugin.Program.ProgramSources
{
using (var key = root.OpenSubKey(item))
{
string path = key.GetValue("") as string;
var path = key.GetValue("") as string;
if (string.IsNullOrEmpty(path)) continue;
// fix path like this ""\"C:\\folder\\executable.exe\"""
const int begin = 0;
int end = path.Length - 1;
var end = path.Length - 1;
const char quotationMark = '"';
if (path[begin] == quotationMark && path[end] == quotationMark)
{
@ -66,10 +60,5 @@ namespace Wox.Plugin.Program.ProgramSources
}
}
}
public override string ToString()
{
return typeof(AppPathsProgramSource).Name;
}
}
}
}

View file

@ -1,40 +1,30 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Text;
namespace Wox.Plugin.Program.ProgramSources
{
[Serializable]
[Browsable(false)]
public class CommonStartMenuProgramSource : FileSystemProgramSource
public sealed class CommonStartMenuProgramSource : FileSystemProgramSource
{
private const int CSIDL_COMMON_PROGRAMS = 0x17;
// todo happlebao how to pass location before loadPrograms
public CommonStartMenuProgramSource()
{
Location = getPath();
}
[DllImport("shell32.dll")]
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out] StringBuilder lpszPath, int nFolder, bool fCreate);
const int CSIDL_COMMON_PROGRAMS = 0x17;
private static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out] StringBuilder lpszPath, int nFolder,
bool fCreate);
private static string getPath()
{
StringBuilder commonStartMenuPath = new StringBuilder(560);
var commonStartMenuPath = new StringBuilder(560);
SHGetSpecialFolderPath(IntPtr.Zero, commonStartMenuPath, CSIDL_COMMON_PROGRAMS, false);
return commonStartMenuPath.ToString();
}
public CommonStartMenuProgramSource(string[] suffixes)
: base(getPath(), suffixes)
{
}
public CommonStartMenuProgramSource(ProgramSource source)
: this(source.Suffixes)
{
BonusPoints = source.BonusPoints;
}
public override string ToString()
{
return typeof(CommonStartMenuProgramSource).Name;
}
}
}
}

View file

@ -8,35 +8,17 @@ using Wox.Infrastructure.Logger;
namespace Wox.Plugin.Program.ProgramSources
{
[Serializable]
public class FileSystemProgramSource : AbstractProgramSource
public class FileSystemProgramSource : ProgramSource
{
private string _baseDirectory;
private int _maxDepth;
private string[] _suffixes;
public FileSystemProgramSource(string baseDirectory, int maxDepth, string[] suffixes)
{
_baseDirectory = baseDirectory;
_maxDepth = maxDepth;
_suffixes = suffixes;
}
public FileSystemProgramSource(string baseDirectory, string[] suffixes)
: this(baseDirectory, -1, suffixes) {}
public FileSystemProgramSource(ProgramSource source)
: this(source.Location, source.MaxDepth, source.Suffixes)
{
BonusPoints = source.BonusPoints;
}
public string Location { get; set; } = "";
public override List<Program> LoadPrograms()
{
List<Program> list = new List<Program>();
if (Directory.Exists(_baseDirectory))
var list = new List<Program>();
if (Directory.Exists(Location))
{
GetAppFromDirectory(_baseDirectory, list);
FileChangeWatcher.AddWatch(_baseDirectory, _suffixes);
GetAppFromDirectory(Location, list);
FileChangeWatcher.AddWatch(Location, Suffixes);
}
return list;
}
@ -48,17 +30,17 @@ namespace Wox.Plugin.Program.ProgramSources
private void GetAppFromDirectory(string path, List<Program> list, int depth)
{
if(_maxDepth != -1 && depth > _maxDepth)
if (MaxDepth != -1 && depth > MaxDepth)
{
return;
}
try
{
foreach (string file in Directory.GetFiles(path))
foreach (var file in Directory.GetFiles(path))
{
if (_suffixes.Any(o => file.EndsWith("." + o)))
if (Suffixes.Any(o => file.EndsWith("." + o)))
{
Program p = CreateEntry(file);
var p = CreateEntry(file);
p.Source = this;
list.Add(p);
}
@ -75,10 +57,10 @@ namespace Wox.Plugin.Program.ProgramSources
Log.Exception(woxPluginException);
}
}
public override string ToString()
{
return typeof(FileSystemProgramSource).Name + ":" + _baseDirectory;
var display = GetType().Name + Location;
return display;
}
}
}
}

View file

@ -3,20 +3,20 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
namespace Wox.Plugin.Program
namespace Wox.Plugin.Program.ProgramSources
{
public interface IProgramSource
{
List<Program> LoadPrograms();
int BonusPoints { get; set; }
}
[Serializable]
public abstract class AbstractProgramSource : IProgramSource
public abstract class ProgramSource
{
public abstract List<Program> LoadPrograms();
public const char SuffixSeperator = ';';
public int BonusPoints { get; set; } = 0;
public bool Enabled { get; set; } = true;
// happlebao todo: temp hack for program suffixes
public string[] Suffixes { get; set; } = {"bat", "appref-ms", "exe", "lnk"};
public int MaxDepth { get; set; } = -1;
public int BonusPoints { get; set; }
public abstract List<Program> LoadPrograms();
protected Program CreateEntry(string file)
{
@ -34,16 +34,18 @@ namespace Wox.Plugin.Program
p.ExecutableName = Path.GetFileName(file);
try
{
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(file);
var versionInfo = FileVersionInfo.GetVersionInfo(file);
if (!string.IsNullOrEmpty(versionInfo.FileDescription))
{
p.Title = versionInfo.FileDescription;
}
}
catch (Exception) { }
catch (Exception)
{
}
break;
}
return p;
}
}
}
}

View file

@ -1,26 +1,14 @@
using System;
using System.ComponentModel;
namespace Wox.Plugin.Program.ProgramSources
{
[Serializable]
[Browsable(false)]
public class UserStartMenuProgramSource : FileSystemProgramSource
public sealed class UserStartMenuProgramSource : FileSystemProgramSource
{
public UserStartMenuProgramSource(string[] suffixes)
: base(Environment.GetFolderPath(Environment.SpecialFolder.Programs), suffixes)
public UserStartMenuProgramSource()
{
}
public UserStartMenuProgramSource(ProgramSource source)
: this(source.Suffixes)
{
BonusPoints = source.BonusPoints;
}
public override string ToString()
{
return typeof(UserStartMenuProgramSource).Name;
Location = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
}
}
}
}

View file

@ -1,5 +1,6 @@
using System.Windows;
using System.Linq;
using Wox.Plugin.Program.ProgramSources;
namespace Wox.Plugin.Program
{

View file

@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Wox.Plugin.Program.ProgramSources;
namespace Wox.Plugin.Program
{
public class Settings
{
public List<ProgramSource> ProgramSources { get; set; } = new List<ProgramSource>();
public List<FileSystemProgramSource> ProgramSources { get; set; } = new List<FileSystemProgramSource>();
public string[] ProgramSuffixes { get; set; } = {"bat", "appref-ms", "exe", "lnk"};
public bool EnableStartMenuSource { get; set; } = true;

View file

@ -61,7 +61,6 @@
<DependentUpon>AddProgramSource.xaml</DependentUpon>
</Compile>
<Compile Include="FileChangeWatcher.cs" />
<Compile Include="IProgramSource.cs" />
<Compile Include="SuffixesConverter.cs" />
<Compile Include="Program.cs" />
<Compile Include="ProgramIndexCache.cs" />
@ -69,7 +68,7 @@
<Compile Include="ProgramSetting.xaml.cs">
<DependentUpon>ProgramSetting.xaml</DependentUpon>
</Compile>
<Compile Include="ProgramSource.cs" />
<Compile Include="ProgramSources\ProgramSource.cs" />
<Compile Include="ProgramSources\AppPathsProgramSource.cs" />
<Compile Include="ProgramSources\CommonStartMenuProgramSource.cs" />
<Compile Include="ProgramSources\FileSystemProgramSource.cs" />

View file

@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Windows;
using WindowsInput;
using WindowsInput.Native;
using Wox.Infrastructure.Hotkey;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.Storage;
@ -12,19 +13,19 @@ using Application = System.Windows.Application;
using Control = System.Windows.Controls.Control;
using Keys = System.Windows.Forms.Keys;
namespace Wox.Plugin.CMD
namespace Wox.Plugin.Shell
{
public class CMD : IPlugin, ISettingProvider, IPluginI18n, IContextMenu, ISavable
public class Main : IPlugin, ISettingProvider, IPluginI18n, IContextMenu, ISavable
{
private const string Image = "Images/shell.png";
private PluginInitContext context;
private bool WinRStroked;
private readonly KeyboardSimulator keyboardSimulator = new KeyboardSimulator(new InputSimulator());
private PluginInitContext _context;
private bool _winRStroked;
private readonly KeyboardSimulator _keyboardSimulator = new KeyboardSimulator(new InputSimulator());
private readonly Settings _settings;
private readonly PluginJsonStorage<Settings> _storage;
public CMD()
public Main()
{
_storage = new PluginJsonStorage<Settings>();
_settings = _storage.Load();
@ -104,14 +105,14 @@ namespace Wox.Plugin.CMD
{
if (m.Key == cmd)
{
result.SubTitle = string.Format(context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value);
result.SubTitle = string.Format(_context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value);
return null;
}
var ret = new Result
{
Title = m.Key,
SubTitle = string.Format(context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value),
SubTitle = string.Format(_context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value),
IcoPath = Image,
Action = c =>
{
@ -130,7 +131,7 @@ namespace Wox.Plugin.CMD
{
Title = cmd,
Score = 5000,
SubTitle = context.API.GetTranslation("wox_plugin_cmd_execute_through_shell"),
SubTitle = _context.API.GetTranslation("wox_plugin_cmd_execute_through_shell"),
IcoPath = Image,
Action = c =>
{
@ -148,7 +149,7 @@ namespace Wox.Plugin.CMD
.Select(m => new Result
{
Title = m.Key,
SubTitle = string.Format(context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value),
SubTitle = string.Format(_context.API.GetTranslation("wox_plugin_cmd_cmd_has_been_executed_times"), m.Value),
IcoPath = Image,
Action = c =>
{
@ -165,7 +166,7 @@ namespace Wox.Plugin.CMD
command = Environment.ExpandEnvironmentVariables(command);
ProcessStartInfo info;
if (_settings.Shell == Shell.CMD)
if (_settings.Shell == Shell.Cmd)
{
var arguments = _settings.LeaveShellOpen ? $"/k \"{command}\"" : $"/c \"{command}\" & pause";
info = new ProcessStartInfo
@ -268,7 +269,7 @@ namespace Wox.Plugin.CMD
public void Init(PluginInitContext context)
{
this.context = context;
this._context = context;
context.API.GlobalKeyboardEvent += API_GlobalKeyboardEvent;
}
@ -278,13 +279,14 @@ namespace Wox.Plugin.CMD
{
if (keyevent == (int)KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed)
{
WinRStroked = true;
_winRStroked = true;
OnWinRPressed();
return false;
}
if (keyevent == (int)KeyEvent.WM_KEYUP && WinRStroked && vkcode == (int)Keys.LWin)
if (keyevent == (int)KeyEvent.WM_KEYUP && _winRStroked && vkcode == (int)Keys.LWin)
{
WinRStroked = false;
_winRStroked = false;
_keyboardSimulator.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.CONTROL);
return false;
}
}
@ -293,7 +295,7 @@ namespace Wox.Plugin.CMD
private void OnWinRPressed()
{
context.API.ChangeQuery($"{context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeperater}");
_context.API.ChangeQuery($"{_context.CurrentPluginMetadata.ActionKeywords[0]}{Plugin.Query.TermSeperater}");
Application.Current.MainWindow.Visibility = Visibility.Visible;
}
@ -304,12 +306,12 @@ namespace Wox.Plugin.CMD
public string GetTranslatedPluginTitle()
{
return context.API.GetTranslation("wox_plugin_cmd_plugin_name");
return _context.API.GetTranslation("wox_plugin_cmd_plugin_name");
}
public string GetTranslatedPluginDescription()
{
return context.API.GetTranslation("wox_plugin_cmd_plugin_description");
return _context.API.GetTranslation("wox_plugin_cmd_plugin_description");
}
public List<Result> LoadContextMenus(Result selectedResult)
@ -318,7 +320,7 @@ namespace Wox.Plugin.CMD
{
new Result
{
Title = context.API.GetTranslation("wox_plugin_cmd_run_as_administrator"),
Title = _context.API.GetTranslation("wox_plugin_cmd_run_as_administrator"),
Action = c =>
{
Execute(selectedResult.Title, true);

View file

@ -1,10 +1,10 @@
using System.Collections.Generic;
namespace Wox.Plugin.CMD
namespace Wox.Plugin.Shell
{
public class Settings
{
public Shell Shell { get; set; } = Shell.CMD;
public Shell Shell { get; set; } = Shell.Cmd;
public bool ReplaceWinR { get; set; } = true;
public bool LeaveShellOpen { get; set; }
public Dictionary<string, int> Count = new Dictionary<string, int>();
@ -24,7 +24,7 @@ namespace Wox.Plugin.CMD
public enum Shell
{
CMD = 0,
Cmd = 0,
Powershell = 1,
RunCommand = 2,

View file

@ -1,4 +1,4 @@
<UserControl x:Class="Wox.Plugin.CMD.CMDSetting"
<UserControl x:Class="Wox.Plugin.Shell.CMDSetting"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

View file

@ -1,7 +1,7 @@
using System.Windows;
using System.Windows.Controls;
namespace Wox.Plugin.CMD
namespace Wox.Plugin.Shell
{
public partial class CMDSetting : UserControl
{

View file

@ -96,11 +96,10 @@ namespace Wox.Plugin.WebSearch
private void EditSearchSource()
{
var keyword = _searchSource.ActionKeyword;
if (!PluginManager.ActionKeywordRegistered(keyword))
var newKeyword = _searchSource.ActionKeyword;
var oldKeyword = _oldSearchSource.ActionKeyword;
if (!PluginManager.ActionKeywordRegistered(newKeyword) || oldKeyword == newKeyword)
{
var newKeyword = keyword;
var oldKeyword = _oldSearchSource.ActionKeyword;
var id = _context.CurrentPluginMetadata.ID;
PluginManager.ReplaceActionKeyword(id, oldKeyword, newKeyword);

View file

@ -5,6 +5,7 @@ WoX
[![Build status](https://ci.appveyor.com/api/projects/status/bfktntbivg32e103)](https://ci.appveyor.com/project/happlebao/wox)
[![Github All Releases](https://img.shields.io/github/downloads/Wox-launcher/Wox/total.svg)](https://github.com/Wox-launcher/Wox/releases)
[![Issue Stats](http://issuestats.com/github/Wox-launcher/Wox/badge/pr)](http://issuestats.com/github/Wox-launcher/Wox)
[![RamenBless](https://cdn.rawgit.com/LunaGao/BlessYourCodeTag/master/tags/ramen.svg)](https://github.com/LunaGao/BlessYourCodeTag)
**WoX** is a launcher for Windows that simply works. It's an alternative to [Alfred](https://www.alfredapp.com/) and [Launchy](http://www.launchy.net/). You can call it Windows omni-eXecutor if you want a long name.

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Wox.Infrastructure;
using Wox.Infrastructure.Exception;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.UserSettings;
@ -113,6 +114,7 @@ namespace Wox.Core.Plugin
return new List<PluginPair>();
}
}
Constant.PythonPath = filename;
var plugins = metadatas.Select(metadata => new PluginPair
{
Plugin = new PythonPlugin(filename),

View file

@ -59,7 +59,7 @@ namespace Wox.Core.Resource
// Exception of FindResource can't be cathed if global exception handle is set
var isBlur = Application.Current.TryFindResource("ThemeBlurEnabled");
if (isBlur is bool)
if (isBlur is bool && Environment.OSVersion.Version >= new Version(6, 2))
{
SetBlurForWindow(Application.Current.MainWindow, (bool)isBlur);
}

View file

@ -24,54 +24,52 @@ namespace Wox.Infrastructure.Exception
sb.AppendLine();
sb.AppendLine("```");
var exlist = new List<StringBuilder>();
var exlist = new List<StringBuilder>();
while (ex != null)
while (ex != null)
{
var exsb = new StringBuilder();
exsb.Append(ex.GetType().FullName);
exsb.Append(": ");
exsb.AppendLine(ex.Message);
if (ex.Source != null)
{
var exsb = new StringBuilder();
exsb.Append(ex.GetType().FullName);
exsb.Append(": ");
exsb.AppendLine(ex.Message);
if (ex.Source != null)
{
exsb.Append(" Source: ");
exsb.AppendLine(ex.Source);
}
if (ex.TargetSite != null)
{
exsb.Append(" TargetAssembly: ");
exsb.AppendLine(ex.TargetSite.Module.Assembly.ToString());
exsb.Append(" TargetModule: ");
exsb.AppendLine(ex.TargetSite.Module.ToString());
exsb.Append(" TargetSite: ");
exsb.AppendLine(ex.TargetSite.ToString());
}
exsb.AppendLine(ex.StackTrace);
exlist.Add(exsb);
ex = ex.InnerException;
exsb.Append(" Source: ");
exsb.AppendLine(ex.Source);
}
foreach (var result in exlist.Select(o => o.ToString()).Reverse())
if (ex.TargetSite != null)
{
sb.AppendLine(result);
exsb.Append(" TargetAssembly: ");
exsb.AppendLine(ex.TargetSite.Module.Assembly.ToString());
exsb.Append(" TargetModule: ");
exsb.AppendLine(ex.TargetSite.Module.ToString());
exsb.Append(" TargetSite: ");
exsb.AppendLine(ex.TargetSite.ToString());
}
sb.AppendLine("```");
sb.AppendLine();
exsb.AppendLine(ex.StackTrace);
exlist.Add(exsb);
ex = ex.InnerException;
}
foreach (var result in exlist.Select(o => o.ToString()).Reverse())
{
sb.AppendLine(result);
}
sb.AppendLine("```");
sb.AppendLine();
sb.AppendLine("## Environment");
sb.AppendLine();
sb.Append("* Command Line: ");
sb.AppendLine(Environment.CommandLine);
sb.Append("* Timestamp: ");
sb.AppendLine(DateTime.Now.ToString(CultureInfo.InvariantCulture));
sb.Append("* IntPtr Length: ");
sb.AppendLine(IntPtr.Size.ToString());
sb.Append("* System Version: ");
sb.AppendLine(Environment.OSVersion.VersionString);
sb.Append("* CLR Version: ");
sb.AppendLine(Environment.Version.ToString());
sb.AppendLine("* Installed .NET Framework: ");
sb.AppendLine($"* Command Line: {Environment.CommandLine}");
sb.AppendLine($"* Timestamp: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}");
sb.AppendLine($"* Wox version: {Constant.Version}");
sb.AppendLine($"* OS Version: {Environment.OSVersion.VersionString}");
sb.AppendLine($"* IntPtr Length: {IntPtr.Size}");
sb.AppendLine($"* x64: {Environment.Is64BitOperatingSystem}");
sb.AppendLine($"* Python Path: {Constant.PythonPath}");
sb.AppendLine($"* Everything SDK Path: {Constant.EverythingSDKPath}");
sb.AppendLine($"* CLR Version: {Environment.Version}");
sb.AppendLine($"* Installed .NET Framework: ");
foreach (var result in GetFrameworkVersionFromRegistry())
{
sb.Append(" * ");

View file

@ -21,5 +21,8 @@ namespace Wox.Infrastructure
public const string Github = "https://github.com/Wox-launcher/Wox";
public const string Issue = "https://github.com/Wox-launcher/Wox/issues/new";
public static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location).ProductVersion;
public static string PythonPath;
public static string EverythingSDKPath;
}
}

View file

@ -70,9 +70,6 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Calculator", "Plugins\Wox.Plugin.Calculator\Wox.Plugin.Calculator.csproj", "{59BD9891-3837-438A-958D-ADC7F91F6F7E}"
EndProject
Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64

View file

@ -60,10 +60,7 @@ namespace Wox
AutoStartup();
AutoUpdates();
if (!_settings.HideOnStartup)
{
mainVM.MainWindowVisibility = Visibility.Visible;
}
mainVM.MainWindowVisibility = _settings.HideOnStartup ? Visibility.Hidden : Visibility.Visible;
});
}
@ -102,7 +99,7 @@ namespace Wox
}
/// <summary>
/// let exception throw as normal is better for Debug
/// let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private void RegisterDispatcherUnhandledException()
@ -113,7 +110,7 @@ namespace Wox
/// <summary>
/// let exception throw as normal is better for Debug
/// let exception throw as normal is better for Debug
/// </summary>
[Conditional("RELEASE")]
private static void RegisterAppDomainExceptions()

View file

@ -17,6 +17,7 @@
Icon="Images\app.png"
AllowsTransparency="True"
Loaded="OnLoaded"
Initialized="OnInitialized"
Closing="OnClosing"
Drop="OnDrop"
SizeChanged="OnSizeChanged"

View file

@ -46,11 +46,16 @@ namespace Wox
_viewModel.Save();
}
private void OnInitialized(object sender, EventArgs e)
{
// show notify icon when wox is hided
InitializeNotifyIcon();
}
private void OnLoaded(object sender, RoutedEventArgs _)
{
WindowIntelopHelper.DisableControlBox(this);
ThemeManager.Instance.ChangeTheme(_settings.Theme);
InitializeNotifyIcon();
InitProgressbarAnimation();
_viewModel.PropertyChanged += (o, e) =>
@ -230,7 +235,11 @@ namespace Wox
private void OnTextChanged(object sender, TextChangedEventArgs e)
{
QueryTextBox.CaretIndex = QueryTextBox.Text.Length;
if (_viewModel.QueryTextCursorMovedToEnd)
{
QueryTextBox.CaretIndex = QueryTextBox.Text.Length;
_viewModel.QueryTextCursorMovedToEnd = false;
}
}
}
}

View file

@ -36,12 +36,12 @@ namespace Wox
public void ChangeQuery(string query, bool requery = false)
{
_mainVM.QueryText = query;
_mainVM.ChangeQueryText(query);
}
public void ChangeQueryText(string query, bool selectAll = false)
{
_mainVM.QueryText = query;
_mainVM.ChangeQueryText(query);
}
[Obsolete]

View file

@ -34,6 +34,10 @@ namespace Wox
StringBuilder content = new StringBuilder();
content.AppendLine($"Wox version: {Constant.Version}");
content.AppendLine($"OS Version: {Environment.OSVersion.VersionString}");
content.AppendLine($"IntPtr Length: {IntPtr.Size}");
content.AppendLine($"x64: {Environment.Is64BitOperatingSystem}");
content.AppendLine($"Python Path: {Constant.PythonPath}");
content.AppendLine($"Everything SDK Path: {Constant.EverythingSDKPath}");
content.AppendLine($"Date: {DateTime.Now.ToString(CultureInfo.InvariantCulture)}");
content.AppendLine("Exception:");
content.AppendLine(exception.Source);

View file

@ -205,7 +205,19 @@ namespace Wox.ViewModel
Query();
}
}
/// <summary>
/// we need move cursor to end when we manually changed query
/// but we don't want to move cursor to end when query is updated from TextBox
/// </summary>
/// <param name="queryText"></param>
public void ChangeQueryText(string queryText)
{
QueryTextCursorMovedToEnd = true;
QueryText = queryText;
}
public bool QueryTextSelected { get; set; }
public bool QueryTextCursorMovedToEnd { get; set; }
private ResultsViewModel _selectedResults;
private ResultsViewModel SelectedResults
@ -218,7 +230,7 @@ namespace Wox.ViewModel
{
ContextMenu.Visbility = Visibility.Collapsed;
History.Visbility = Visibility.Collapsed;
QueryText = _queryTextBeforeLeaveResults;
ChangeQueryText(_queryTextBeforeLeaveResults);
}
else
{
@ -325,7 +337,7 @@ namespace Wox.ViewModel
Action = _ =>
{
SelectedResults = Results;
QueryText = h.Query;
ChangeQueryText(h.Query);
return false;
}
};
@ -547,7 +559,7 @@ namespace Wox.ViewModel
{
if (ShouldIgnoreHotkeys()) return;
MainWindowVisibility = Visibility.Visible;
QueryText = hotkey.ActionKeyword;
ChangeQueryText(hotkey.ActionKeyword);
});
}
}