diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/IExplorerAction.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/IShellAction.cs similarity index 91% rename from src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/IExplorerAction.cs rename to src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/IShellAction.cs index 5617256d75..27946bd096 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/IExplorerAction.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/IShellAction.cs @@ -6,7 +6,7 @@ using Wox.Plugin; namespace Microsoft.Plugin.Folder.Sources { - public interface IExplorerAction + public interface IShellAction { bool Execute(string sanitizedPath, IPublicAPI contextApi); diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Result/CreateOpenCurrentFolderResult.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Result/CreateOpenCurrentFolderResult.cs index 86c60b0cec..3e323fae5d 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Result/CreateOpenCurrentFolderResult.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Result/CreateOpenCurrentFolderResult.cs @@ -2,26 +2,25 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using System.Globalization; using Wox.Plugin; namespace Microsoft.Plugin.Folder.Sources.Result { public class CreateOpenCurrentFolderResult : IItemResult { - private readonly IExplorerAction _explorerAction; + private readonly IShellAction _shellAction; - public string Search { get; set; } + public string Search { get; set; } public CreateOpenCurrentFolderResult(string search) - : this(search, new ExplorerAction()) + : this(search, new ShellAction()) { } - public CreateOpenCurrentFolderResult(string search, IExplorerAction explorerAction) + public CreateOpenCurrentFolderResult(string search, IShellAction shellAction) { Search = search; - _explorerAction = explorerAction; + _shellAction = shellAction; } public Wox.Plugin.Result Create(IPublicAPI contextApi) @@ -33,7 +32,7 @@ namespace Microsoft.Plugin.Folder.Sources.Result SubTitle = Properties.Resources.wox_plugin_folder_select_folder_first_result_subtitle, IcoPath = Search, Score = 500, - Action = c => _explorerAction.ExecuteSanitized(Search, contextApi), + Action = c => _shellAction.ExecuteSanitized(Search, contextApi), }; } } diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Result/FileItemResult.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Result/FileItemResult.cs index 84a35e1396..67ce726808 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Result/FileItemResult.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Result/FileItemResult.cs @@ -11,7 +11,7 @@ namespace Microsoft.Plugin.Folder.Sources.Result { public class FileItemResult : IItemResult { - private static readonly IExplorerAction ExplorerAction = new ExplorerAction(); + private static readonly IShellAction ShellAction = new ShellAction(); public string FilePath { get; set; } @@ -27,7 +27,7 @@ namespace Microsoft.Plugin.Folder.Sources.Result SubTitle = string.Format(CultureInfo.CurrentCulture, Properties.Resources.wox_plugin_folder_select_file_result_subtitle, FilePath), IcoPath = FilePath, TitleHighlightData = StringMatcher.FuzzySearch(Search, Path.GetFileName(FilePath)).MatchData, - Action = c => ExplorerAction.Execute(FilePath, contextApi), + Action = c => ShellAction.Execute(FilePath, contextApi), ContextData = new SearchResult { Type = ResultType.File, FullPath = FilePath }, }; return result; diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Result/FolderItemResult.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Result/FolderItemResult.cs index ad5f1e7f5e..dd295f9413 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Result/FolderItemResult.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/Result/FolderItemResult.cs @@ -10,7 +10,7 @@ namespace Microsoft.Plugin.Folder.Sources.Result { public class FolderItemResult : IItemResult { - private static readonly IExplorerAction ExplorerAction = new ExplorerAction(); + private static readonly IShellAction ShellAction = new ShellAction(); public FolderItemResult() { @@ -41,7 +41,7 @@ namespace Microsoft.Plugin.Folder.Sources.Result QueryTextDisplay = Path, TitleHighlightData = StringMatcher.FuzzySearch(Search, Title).MatchData, ContextData = new SearchResult { Type = ResultType.Folder, FullPath = Path }, - Action = c => ExplorerAction.Execute(Path, contextApi), + Action = c => ShellAction.Execute(Path, contextApi), }; } } diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/ExplorerAction.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/ShellAction.cs similarity index 78% rename from src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/ExplorerAction.cs rename to src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/ShellAction.cs index 69c2562eab..d82ff91459 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/ExplorerAction.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/Sources/ShellAction.cs @@ -7,16 +7,13 @@ using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Text.RegularExpressions; -using System.Windows; using Wox.Infrastructure.Logger; using Wox.Plugin; namespace Microsoft.Plugin.Folder.Sources { - public class ExplorerAction : IExplorerAction + public class ShellAction : IShellAction { - private const string FileExplorerProgramName = "explorer"; - public bool Execute(string path, IPublicAPI contextApi) { if (contextApi == null) @@ -24,7 +21,7 @@ namespace Microsoft.Plugin.Folder.Sources throw new ArgumentNullException(nameof(contextApi)); } - return OpenFileOrFolder(FileExplorerProgramName, path, contextApi); + return OpenFileOrFolder(path, contextApi); } public bool ExecuteSanitized(string search, IPublicAPI contextApi) @@ -51,16 +48,21 @@ namespace Microsoft.Plugin.Folder.Sources } [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "We want to keep the process alive and instead inform the user of the error")] - private static bool OpenFileOrFolder(string program, string path, IPublicAPI contextApi) + private static bool OpenFileOrFolder(string path, IPublicAPI contextApi) { try { - Process.Start(program, path); + using (var process = new Process()) + { + process.StartInfo.FileName = path; + process.StartInfo.UseShellExecute = true; + process.Start(); + } } catch (Exception e) { string messageBoxTitle = string.Format(CultureInfo.InvariantCulture, "{0} {1}", Properties.Resources.wox_plugin_folder_select_folder_OpenFileOrFolder_error_message, path); - Log.Exception($"Failed to open {path} in {FileExplorerProgramName}, {e.Message}", e, MethodBase.GetCurrentMethod().DeclaringType); + Log.Exception($"Failed to open {path}, {e.Message}", e, MethodBase.GetCurrentMethod().DeclaringType); contextApi.ShowMsg(messageBoxTitle, e.Message); } diff --git a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/UserFolderResult.cs b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/UserFolderResult.cs index 01ccb56bee..f8bb9ce1eb 100644 --- a/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/UserFolderResult.cs +++ b/src/modules/launcher/Plugins/Microsoft.Plugin.Folder/UserFolderResult.cs @@ -12,7 +12,7 @@ namespace Microsoft.Plugin.Folder { public class UserFolderResult : IItemResult { - private readonly IExplorerAction _explorerAction = new ExplorerAction(); + private readonly IShellAction _shellAction = new ShellAction(); public string Search { get; set; } @@ -32,7 +32,7 @@ namespace Microsoft.Plugin.Folder QueryTextDisplay = Path, TitleHighlightData = StringMatcher.FuzzySearch(Search, Title).MatchData, ContextData = new SearchResult { Type = ResultType.Folder, FullPath = Path }, - Action = c => _explorerAction.Execute(Path, contextApi), + Action = c => _shellAction.Execute(Path, contextApi), }; } }