From 31bbf3cfd5452212313e6bce0d4ef5591e3fd930 Mon Sep 17 00:00:00 2001 From: Yeechan Lu Date: Sat, 22 Mar 2014 16:50:47 +0800 Subject: [PATCH] Fix applicationDirectory issues and add plugin debuggerMode --- Wox.Infrastructure/CommonStorage.cs | 2 +- Wox.Infrastructure/UserSettings/UserSetting.cs | 5 +++-- Wox.Plugin.System/BrowserBookmarks.cs | 2 +- Wox.Plugin.System/CMD.cs | 2 +- Wox.UAC/FileTypeAssociateInstaller.cs | 4 ++-- Wox.UAC/Wox.UAC.csproj | 1 + Wox/App.xaml.cs | 5 +++++ Wox/MainWindow.xaml.cs | 2 +- Wox/PluginLoader/BasePluginLoader.cs | 8 +++++++- Wox/PluginLoader/Plugins.cs | 11 +++++++++++ Wox/PluginLoader/PythonPluginLoader.cs | 2 +- Wox/SettingWindow.xaml.cs | 6 +++--- 12 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Wox.Infrastructure/CommonStorage.cs b/Wox.Infrastructure/CommonStorage.cs index 07004abacf..a235192a38 100644 --- a/Wox.Infrastructure/CommonStorage.cs +++ b/Wox.Infrastructure/CommonStorage.cs @@ -11,7 +11,7 @@ namespace Wox.Infrastructure [Serializable] public class CommonStorage { - private static string configPath = Directory.GetCurrentDirectory() + "\\config.json"; + private static string configPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\config.json"; private static object locker = new object(); private static CommonStorage storage; diff --git a/Wox.Infrastructure/UserSettings/UserSetting.cs b/Wox.Infrastructure/UserSettings/UserSetting.cs index e98f44df24..dca235ee1a 100644 --- a/Wox.Infrastructure/UserSettings/UserSetting.cs +++ b/Wox.Infrastructure/UserSettings/UserSetting.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.IO; +using System.Windows.Forms; namespace Wox.Infrastructure.UserSettings { @@ -29,7 +30,7 @@ namespace Wox.Infrastructure.UserSettings { Title = "Google", ActionWord = "g", - IconPath = Directory.GetCurrentDirectory() + @"\Images\websearch\google.png", + IconPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\Images\websearch\google.png", Url = "https://www.google.com/search?q={q}", Enabled = true }; @@ -40,7 +41,7 @@ namespace Wox.Infrastructure.UserSettings { Title = "Wikipedia", ActionWord = "wiki", - IconPath = Directory.GetCurrentDirectory() + @"\Images\websearch\wiki.png", + IconPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\Images\websearch\wiki.png", Url = "http://en.wikipedia.org/wiki/{q}", Enabled = true }; diff --git a/Wox.Plugin.System/BrowserBookmarks.cs b/Wox.Plugin.System/BrowserBookmarks.cs index 32965762db..7b72159b2e 100644 --- a/Wox.Plugin.System/BrowserBookmarks.cs +++ b/Wox.Plugin.System/BrowserBookmarks.cs @@ -27,7 +27,7 @@ namespace Wox.Plugin.System { Title = c.Name, SubTitle = "Bookmark: " + c.Url, - IcoPath = Directory.GetCurrentDirectory() + @"\Images\bookmark.png", + IcoPath = Path.GetDirectoryName(Application.ExecutablePath) + @"\Images\bookmark.png", Score = 5, Action = (e) => { diff --git a/Wox.Plugin.System/CMD.cs b/Wox.Plugin.System/CMD.cs index d8c7b6ff34..bb9914cae7 100644 --- a/Wox.Plugin.System/CMD.cs +++ b/Wox.Plugin.System/CMD.cs @@ -12,7 +12,7 @@ namespace Wox.Plugin.System public class CMD : BaseSystemPlugin { private Dictionary cmdHistory = new Dictionary(); - private string filePath = Directory.GetCurrentDirectory() + "\\CMDHistory.dat"; + private string filePath = Path.GetDirectoryName(Application.ExecutablePath) + "\\CMDHistory.dat"; private PluginInitContext context; protected override List QueryInternal(Query query) diff --git a/Wox.UAC/FileTypeAssociateInstaller.cs b/Wox.UAC/FileTypeAssociateInstaller.cs index e0ececd9cf..8cea1d4682 100644 --- a/Wox.UAC/FileTypeAssociateInstaller.cs +++ b/Wox.UAC/FileTypeAssociateInstaller.cs @@ -60,8 +60,8 @@ namespace Wox.UAC public void RegisterInstaller() { - string filePath = Directory.GetCurrentDirectory() + "\\Wox.exe"; - string iconPath = Directory.GetCurrentDirectory() + "\\app.ico"; + string filePath = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Wox.exe"); + string iconPath = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "app.ico"); SaveReg(filePath, ".wox", iconPath, true); } diff --git a/Wox.UAC/Wox.UAC.csproj b/Wox.UAC/Wox.UAC.csproj index 3223e2a82d..a69735aec0 100644 --- a/Wox.UAC/Wox.UAC.csproj +++ b/Wox.UAC/Wox.UAC.csproj @@ -54,6 +54,7 @@ + diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 5f3e2d468f..b3a8d85588 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -83,6 +83,11 @@ namespace Wox return; } + if (e.Args.Length > 0 && e.Args[0].ToLower() == "plugindebugger") + { + var path = e.Args[1]; + PluginLoader.Plugins.ActivatePluginDebugger(path); + } window = new MainWindow(); if (e.Args.Length == 0 || e.Args[0].ToLower() != "hidestart") diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 4256d4920f..aa6289809f 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -424,7 +424,7 @@ namespace Wox { var dict = new ResourceDictionary { - Source = new Uri(Path.Combine(Directory.GetCurrentDirectory(), "Themes\\" + themeName + ".xaml"), UriKind.Absolute) + Source = new Uri(Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Themes\\" + themeName + ".xaml"), UriKind.Absolute) }; diff --git a/Wox/PluginLoader/BasePluginLoader.cs b/Wox/PluginLoader/BasePluginLoader.cs index cd1f6efb89..ab71816f63 100644 --- a/Wox/PluginLoader/BasePluginLoader.cs +++ b/Wox/PluginLoader/BasePluginLoader.cs @@ -13,7 +13,7 @@ namespace Wox.PluginLoader { public abstract class BasePluginLoader { - private static string PluginPath = AppDomain.CurrentDomain.BaseDirectory + "Plugins"; + private static string PluginPath = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Plugins"); private static string PluginConfigName = "plugin.json"; protected static List pluginMetadatas = new List(); public abstract List LoadPlugin(); @@ -23,6 +23,12 @@ namespace Wox.PluginLoader pluginMetadatas.Clear(); ParseSystemPlugins(); ParseThirdPartyPlugins(); + + if (Plugins.DebuggerMode != null) + { + PluginMetadata metadata = GetMetadataFromJson(Plugins.DebuggerMode); + if (metadata != null) pluginMetadatas.Add(metadata); + } } private static void ParseSystemPlugins() diff --git a/Wox/PluginLoader/Plugins.cs b/Wox/PluginLoader/Plugins.cs index 72accc6109..fa5796275c 100644 --- a/Wox/PluginLoader/Plugins.cs +++ b/Wox/PluginLoader/Plugins.cs @@ -12,6 +12,7 @@ namespace Wox.PluginLoader { public static class Plugins { + private static string debuggerMode = null; private static List plugins = new List(); public static void Init() @@ -68,5 +69,15 @@ namespace Wox.PluginLoader return plugins.Any(o => o.Metadata.PluginType == PluginType.ThirdParty && o.Metadata.ActionKeyword == query.ActionName); } + + public static void ActivatePluginDebugger(string path) + { + debuggerMode = path; + } + + public static String DebuggerMode + { + get { return debuggerMode; } + } } } diff --git a/Wox/PluginLoader/PythonPluginLoader.cs b/Wox/PluginLoader/PythonPluginLoader.cs index e9f88c0a7e..644b82fbd1 100644 --- a/Wox/PluginLoader/PythonPluginLoader.cs +++ b/Wox/PluginLoader/PythonPluginLoader.cs @@ -47,7 +47,7 @@ namespace Wox.PluginLoader private void SetPythonHome() { - //Environment.SetEnvironmentVariable("PYTHONHOME",Path.Combine(Directory.GetCurrentDirectory(),"PythonHome")); + //Environment.SetEnvironmentVariable("PYTHONHOME",Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),"PythonHome")); //PythonEngine.PythonHome = //PythonEngine.ProgramName } diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index 07014f4449..177611091c 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -139,7 +139,7 @@ namespace Wox private List LoadAvailableThemes() { - string themePath = Directory.GetCurrentDirectory() + "\\Themes\\"; + string themePath = Path.Combine(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), "Themes"); return Directory.GetFiles(themePath).Where(filePath => filePath.EndsWith(".xaml") && !filePath.EndsWith("Default.xaml")).ToList(); } @@ -244,9 +244,9 @@ namespace Wox IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(woxLinkPath); shortcut.TargetPath = Application.ExecutablePath; shortcut.Arguments = "hideStart"; - shortcut.WorkingDirectory = Application.StartupPath; + shortcut.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath); shortcut.Description = "Launch Wox"; - shortcut.IconLocation = Application.StartupPath + @"\App.ico"; + shortcut.IconLocation = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "App.ico"); shortcut.Save(); }