FileSystemPlugin

Check for invalid paths
[Open this directory] Action always appears at top is path is existing
directory or parent is
This commit is contained in:
Aaron Campf 2014-05-20 16:45:11 -07:00
parent 60f4937aae
commit cefa8326e3
4 changed files with 53 additions and 54 deletions

View File

@ -47,14 +47,6 @@ namespace Wox.Plugin.SystemPlugins.FileSystem {
var currentPath = link == null ? input : link.Path + input.Remove(0, inputName.Length);
InitialDriverList();
//TODO: Consider always clearing the cache
//TODO: Prove the following was not ever actually used
//if (string.IsNullOrEmpty(query.RawQuery)) {
// // clear the cache
// if (parentDirectories.Count > 0) parentDirectories.Clear();
// return results;
//}
foreach (var item in UserSettingStorage.Instance.FolderLinks.Where(x => x.Nickname.StartsWith(input, StringComparison.OrdinalIgnoreCase))) {
results.Add(new Result(item.Nickname, "Images/folder.png") {
Action = (c) => {
@ -84,55 +76,61 @@ namespace Wox.Plugin.SystemPlugins.FileSystem {
private void QueryInternal_Directory_Exists(string currentPath, string input, List<Result> results) {
string path = Directory.Exists(currentPath) ? new DirectoryInfo(currentPath).FullName : Path.GetDirectoryName(input);
if (!System.IO.Directory.Exists(path)) return;
if (path != null) {
var dirs = new DirectoryInfo(path).GetDirectories();
var parentDirKey = input.TrimEnd('\\', '/');
if (!parentDirectories.ContainsKey(parentDirKey)) parentDirectories.Add(parentDirKey, dirs);
var fuzzy = FuzzyMatcher.Create(Path.GetFileName(currentPath).ToLower());
foreach (var dir in dirs) { //.Where(x => (x.Attributes & FileAttributes.Hidden) != 0)) {
if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue;
var result = new Result(dir.Name, "Images/folder.png") {
Action = (c) => {
context.ChangeQuery(dir.FullName);
return false;
}
};
if (Path.GetFileName(currentPath).ToLower() != "") {
var matchResult = fuzzy.Evaluate(dir.Name);
result.Score = matchResult.Score;
if (!matchResult.Success) continue;
}
results.Add(result);
}
}
else {
//TODO: Make sure we do not need anything here
}
if (results.Count == 0) {
results.Add(new Result("Open this directory", "Images/folder.png", "No files in this directory") {
Action = (c) => {
results.Add(new Result("Open this directory", "Images/folder.png") {
Score = 100000,
Action = (c) => {
if (Directory.Exists(currentPath)) {
Process.Start(currentPath);
return true;
}
});
else if (currentPath.Contains("\\")) {
var index = currentPath.LastIndexOf("\\");
Process.Start(currentPath.Remove(index) + "\\");
}
return true;
}
});
//if (System.IO.Directory.Exists(input)) {
var dirs = new DirectoryInfo(path).GetDirectories();
var parentDirKey = input.TrimEnd('\\', '/');
if (!parentDirectories.ContainsKey(parentDirKey)) parentDirectories.Add(parentDirKey, dirs);
var fuzzy = FuzzyMatcher.Create(Path.GetFileName(currentPath).ToLower());
foreach (var dir in dirs) { //.Where(x => (x.Attributes & FileAttributes.Hidden) != 0)) {
if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue;
var result = new Result(dir.Name, "Images/folder.png") {
Action = (c) => {
//context.ChangeQuery(dir.FullName);
context.ChangeQuery(input + dir.Name + "\\");
return false;
}
};
if (Path.GetFileName(currentPath).ToLower() != "") {
var matchResult = fuzzy.Evaluate(dir.Name);
result.Score = matchResult.Score;
if (!matchResult.Success) continue;
}
results.Add(result);
}
//}
var Folder = Path.GetDirectoryName(currentPath);
if (Folder != null) {
var dirInfo1 = new DirectoryInfo(Folder);
var fuzzy = FuzzyMatcher.Create(Path.GetFileName(currentPath).ToLower());
foreach (var dir in dirInfo1.GetFiles()) { //.Where(x => (x.Attributes & FileAttributes.Hidden) != 0)) {
//var fuzzy = FuzzyMatcher.Create(Path.GetFileName(currentPath).ToLower());
foreach (var dir in new DirectoryInfo(Folder).GetFiles()) { //.Where(x => (x.Attributes & FileAttributes.Hidden) != 0)) {
if ((dir.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue;
var dirPath = dir.FullName;
Result result = new Result(System.IO.Path.GetFileNameWithoutExtension(dirPath), dirPath) {
Result result = new Result(Path.GetFileNameWithoutExtension(dirPath), dirPath) {
Action = (c) => {
try {
Process.Start(dirPath);
@ -145,7 +143,7 @@ namespace Wox.Plugin.SystemPlugins.FileSystem {
}
};
if (Path.GetFileName(currentPath).ToLower() != "") {
if (Path.GetFileName(currentPath) != "") {
var matchResult = fuzzy.Evaluate(dir.Name);
result.Score = matchResult.Score;
if (!matchResult.Success) continue;

View File

@ -21,6 +21,7 @@ using UnhandledExceptionEventArgs = System.UnhandledExceptionEventArgs;
namespace Wox {
public static class EntryPoint {
[STAThread]
[System.Diagnostics.DebuggerStepThrough]
public static void Main(string[] args) {
AppDomain.CurrentDomain.UnhandledException += ErrorReporting.UnhandledExceptionHandle;
System.Windows.Forms.Application.ThreadException += ErrorReporting.ThreadException;
@ -30,7 +31,7 @@ namespace Wox {
Entry(args);
}
[System.Diagnostics.DebuggerStepThrough]
private static void Entry(string[] args) {
SingleInstanceManager manager = new SingleInstanceManager();
manager.Run(args);

View File

@ -324,7 +324,7 @@ namespace Wox {
private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, SpecialKeyState state) {
if (UserSettingStorage.Instance.ReplaceWinR) {
//todo:need refatoring. move those codes to CMD file or expose events
//todo:need refactoring. move those codes to CMD file or expose events
if (keyevent == KeyEvent.WM_KEYDOWN && vkcode == (int)Keys.R && state.WinPressed) {
WinRStroked = true;
Dispatcher.BeginInvoke(new Action(OnWinRPressed));
@ -453,7 +453,7 @@ namespace Wox {
queryHasReturn = true;
progressBar.Dispatcher.Invoke(new Action(StopProgress));
if (list.Count > 0) {
//todo:this should be opened to users, it's their choise to use it or not in thier workflows
//todo:this should be opened to users, it's their choice to use it or not in their workflows
list.ForEach(
o => {
if (o.AutoAjustScore) o.Score += UserSelectedRecordStorage.Instance.GetSelectedCount(o);

View File

@ -11,7 +11,7 @@ namespace Wox.PluginLoader {
public class CSharpPluginLoader : BasePluginLoader {
public override List<PluginPair> LoadPlugin() {
List<PluginPair> plugins = new List<PluginPair>();
var plugins = new List<PluginPair>();
List<PluginMetadata> metadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
foreach (PluginMetadata metadata in metadatas) {
@ -19,7 +19,7 @@ namespace Wox.PluginLoader {
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && (o.BaseType == typeof(BaseSystemPlugin) || o.GetInterfaces().Contains(typeof(IPlugin)))).ToList();
if (types.Count == 0) {
Log.Warn(string.Format("Cound't load plugin {0}: didn't find the class who implement IPlugin", metadata.Name));
Log.Warn(string.Format("Couldn't load plugin {0}: didn't find the class who implement IPlugin", metadata.Name));
continue;
}
@ -38,7 +38,7 @@ namespace Wox.PluginLoader {
}
}
catch (Exception e) {
Log.Error(string.Format("Cound't load plugin {0}: {1}", metadata.Name, e.Message));
Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message));
#if (DEBUG)
{
throw;