From c90dd0e818201131bf578f6f904c4c8a59113b90 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Tue, 3 Dec 2019 23:02:24 +0200 Subject: [PATCH 01/16] updated top most record --- Wox.Infrastructure/Storage/WoxJsonStorage.cs | 4 +- Wox.Plugin/Result.cs | 2 +- Wox/Storage/TopMostRecord.cs | 49 +++++++++++--------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/Wox.Infrastructure/Storage/WoxJsonStorage.cs b/Wox.Infrastructure/Storage/WoxJsonStorage.cs index f117aee22..da0dbd073 100644 --- a/Wox.Infrastructure/Storage/WoxJsonStorage.cs +++ b/Wox.Infrastructure/Storage/WoxJsonStorage.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Wox.Infrastructure.Storage { - class WoxJsonStorage : JsonStrorage where T : new() + public class WoxJsonStorage : JsonStrorage where T : new() { public WoxJsonStorage() { @@ -18,4 +18,4 @@ namespace Wox.Infrastructure.Storage FilePath = Path.Combine(directoryPath, $"{filename}{FileSuffix}"); } } -} +} \ No newline at end of file diff --git a/Wox.Plugin/Result.cs b/Wox.Plugin/Result.cs index 2f7459170..592bcac5c 100644 --- a/Wox.Plugin/Result.cs +++ b/Wox.Plugin/Result.cs @@ -108,7 +108,7 @@ namespace Wox.Plugin public object ContextData { get; set; } /// - /// Plugin ID that generate this result + /// Plugin ID that generated this result /// public string PluginID { get; internal set; } } diff --git a/Wox/Storage/TopMostRecord.cs b/Wox/Storage/TopMostRecord.cs index 4d33f91eb..38cfbab8e 100644 --- a/Wox/Storage/TopMostRecord.cs +++ b/Wox/Storage/TopMostRecord.cs @@ -1,47 +1,52 @@ using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; +using Newtonsoft.Json; using Wox.Infrastructure.Storage; using Wox.Plugin; namespace Wox.Storage { + // todo this class is not thread safe.... but used from multiple threads. public class TopMostRecord { - public Dictionary records = new Dictionary(); + [JsonProperty] + private Dictionary records = new Dictionary(); internal bool IsTopMost(Result result) { + if (records.Count == 0) + { + return false; + } + + // since this dictionary should be very small (or empty) going over it should be pretty fast. return records.Any(o => o.Value.Title == result.Title - && o.Value.SubTitle == result.SubTitle - && o.Value.PluginID == result.PluginID - && o.Key == result.OriginQuery.RawQuery); + && o.Value.SubTitle == result.SubTitle + && o.Value.PluginID == result.PluginID + && o.Key == result.OriginQuery.RawQuery); } internal void Remove(Result result) { - if (records.ContainsKey(result.OriginQuery.RawQuery)) - { - records.Remove(result.OriginQuery.RawQuery); - } + records.Remove(result.OriginQuery.RawQuery); } internal void AddOrUpdate(Result result) { - if (records.ContainsKey(result.OriginQuery.RawQuery)) + var record = new Record { - records[result.OriginQuery.RawQuery].Title = result.Title; - records[result.OriginQuery.RawQuery].SubTitle = result.SubTitle; - records[result.OriginQuery.RawQuery].PluginID = result.PluginID; - } - else - { - records.Add(result.OriginQuery.RawQuery, new Record - { - PluginID = result.PluginID, - Title = result.Title, - SubTitle = result.SubTitle - }); - } + PluginID = result.PluginID, + Title = result.Title, + SubTitle = result.SubTitle + }; + records[result.OriginQuery.RawQuery] = record; + + } + + public void Load(Dictionary dictionary) + { + records = dictionary; } } From b3fdc4bb9602881fe908a27d479d385b0ff0cab6 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Tue, 3 Dec 2019 23:37:55 +0200 Subject: [PATCH 02/16] updated user selected record --- Wox/Storage/UserSelectedRecord.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Wox/Storage/UserSelectedRecord.cs b/Wox/Storage/UserSelectedRecord.cs index 900559041..ef8bf7f8e 100644 --- a/Wox/Storage/UserSelectedRecord.cs +++ b/Wox/Storage/UserSelectedRecord.cs @@ -12,21 +12,23 @@ namespace Wox.Storage public void Add(Result result) { - if (records.ContainsKey(result.ToString())) + var key = result.ToString(); + if (records.TryGetValue(key, out int value)) { - records[result.ToString()] += 1; + records[key] = value + 1; } else { - records.Add(result.ToString(), 1); + records.Add(key, 1); + } } public int GetSelectedCount(Result result) { - if (records.ContainsKey(result.ToString())) + if (records.TryGetValue(result.ToString(), out int value)) { - return records[result.ToString()]; + return value; } return 0; } From 02511b77852ff29f4f4e9c4306b1949e0a18eaf6 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Wed, 4 Dec 2019 00:15:46 +0200 Subject: [PATCH 03/16] some more --- Wox/ViewModel/MainViewModel.cs | 8 +++++--- Wox/ViewModel/ResultsViewModel.cs | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index 1a12d6c8c..153caa55d 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -419,6 +419,11 @@ namespace Wox.ViewModel UpdateResultView(results, plugin.Metadata, query); } }); + + // this should happen once after all queries are done so progress bar should continue + // until the end of all querying + _queryHasReturn = true; + ProgressBarVisibility = Visibility.Hidden; }, _updateToken); } } @@ -627,9 +632,6 @@ namespace Wox.ViewModel /// public void UpdateResultView(List list, PluginMetadata metadata, Query originQuery) { - _queryHasReturn = true; - ProgressBarVisibility = Visibility.Hidden; - foreach (var result in list) { if (_topMostRecord.IsTopMost(result)) diff --git a/Wox/ViewModel/ResultsViewModel.cs b/Wox/ViewModel/ResultsViewModel.cs index 674923228..1175cd8c3 100644 --- a/Wox/ViewModel/ResultsViewModel.cs +++ b/Wox/ViewModel/ResultsViewModel.cs @@ -155,7 +155,6 @@ namespace Wox.ViewModel // Find the same results in A (old results) and B (new newResults) var sameResults = oldResults .Where(t1 => newResults.Any(x => x.Result.Equals(t1.Result))) - .Select(t1 => t1) .ToList(); // remove result of relative complement of B in A From 92bde25a49fdbc25febe7c1cb5a1cc9a4a8fb265 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Fri, 6 Dec 2019 07:49:20 +1100 Subject: [PATCH 04/16] Add option to run as administrator for Shell plugin --- Plugins/Wox.Plugin.Program/Programs/Win32.cs | 10 ++------ Wox.Plugin/SharedCommands/ShellCommand.cs | 24 ++++++++++++++++++++ Wox.Plugin/Wox.Plugin.csproj | 1 + 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 Wox.Plugin/SharedCommands/ShellCommand.cs diff --git a/Plugins/Wox.Plugin.Program/Programs/Win32.cs b/Plugins/Wox.Plugin.Program/Programs/Win32.cs index 36e08a3c4..f0697abef 100644 --- a/Plugins/Wox.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Wox.Plugin.Program/Programs/Win32.cs @@ -10,6 +10,7 @@ using Microsoft.Win32; using Shell; using Wox.Infrastructure; using Wox.Plugin.Program.Logger; +using Wox.Plugin.SharedCommands; namespace Wox.Plugin.Program.Programs { @@ -96,14 +97,7 @@ namespace Wox.Plugin.Program.Programs Title = api.GetTranslation("wox_plugin_program_run_as_administrator"), Action = _ => { - var info = new ProcessStartInfo - { - FileName = FullPath, - WorkingDirectory = ParentDirectory, - Verb = "runas" - }; - var hide = Main.StartProcess(info); - return hide; + return Main.StartProcess(ShellCommand.SetCMDRunAsAdministrator(FullPath, ParentDirectory)); }, IcoPath = "Images/cmd.png" }, diff --git a/Wox.Plugin/SharedCommands/ShellCommand.cs b/Wox.Plugin/SharedCommands/ShellCommand.cs new file mode 100644 index 000000000..ac3f4e7cb --- /dev/null +++ b/Wox.Plugin/SharedCommands/ShellCommand.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Wox.Plugin.SharedCommands +{ + public static class ShellCommand + { + public static ProcessStartInfo SetCMDRunAsAdministrator(this string fullPath, string parentDirectory) + { + var info = new ProcessStartInfo + { + FileName = fullPath, + WorkingDirectory = parentDirectory, + Verb = "runas" + }; + + return info; + } + } +} diff --git a/Wox.Plugin/Wox.Plugin.csproj b/Wox.Plugin/Wox.Plugin.csproj index 843cc7d8b..3a486fb42 100644 --- a/Wox.Plugin/Wox.Plugin.csproj +++ b/Wox.Plugin/Wox.Plugin.csproj @@ -78,6 +78,7 @@ + From a2d685815fd8775c1996d1bb6040c98b9607f3b7 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Fri, 6 Dec 2019 22:36:00 +0200 Subject: [PATCH 05/16] updated --- Wox/Storage/TopMostRecord.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Wox/Storage/TopMostRecord.cs b/Wox/Storage/TopMostRecord.cs index 38cfbab8e..5f940f218 100644 --- a/Wox/Storage/TopMostRecord.cs +++ b/Wox/Storage/TopMostRecord.cs @@ -1,8 +1,6 @@ using System.Collections.Generic; using System.Linq; -using System.Runtime.InteropServices; using Newtonsoft.Json; -using Wox.Infrastructure.Storage; using Wox.Plugin; namespace Wox.Storage From 431f22283da2a52753f0f3dba86fd9f4f1d119c1 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Sat, 7 Dec 2019 16:57:21 +0200 Subject: [PATCH 06/16] added goto first result command (alt home) --- Wox/MainWindow.xaml | 1 + Wox/ViewModel/MainViewModel.cs | 3 +++ Wox/ViewModel/ResultsViewModel.cs | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/Wox/MainWindow.xaml b/Wox/MainWindow.xaml index d1e610dfc..7dfe8cd1e 100644 --- a/Wox/MainWindow.xaml +++ b/Wox/MainWindow.xaml @@ -36,6 +36,7 @@ + diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index 1a12d6c8c..ee240cd86 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -126,6 +126,8 @@ namespace Wox.ViewModel SelectedResults.SelectPrevPage(); }); + SelectFirstResultCommand = new RelayCommand(_ => SelectedResults.SelectFirstResult()); + StartHelpCommand = new RelayCommand(_ => { Process.Start("http://doc.wox.one/"); @@ -268,6 +270,7 @@ namespace Wox.ViewModel public ICommand SelectPrevItemCommand { get; set; } public ICommand SelectNextPageCommand { get; set; } public ICommand SelectPrevPageCommand { get; set; } + public ICommand SelectFirstResultCommand { get; set; } public ICommand StartHelpCommand { get; set; } public ICommand LoadContextMenuCommand { get; set; } public ICommand LoadHistoryCommand { get; set; } diff --git a/Wox/ViewModel/ResultsViewModel.cs b/Wox/ViewModel/ResultsViewModel.cs index 674923228..a586664e6 100644 --- a/Wox/ViewModel/ResultsViewModel.cs +++ b/Wox/ViewModel/ResultsViewModel.cs @@ -107,6 +107,11 @@ namespace Wox.ViewModel SelectedIndex = NewIndex(SelectedIndex - MaxResults); } + public void SelectFirstResult() + { + SelectedIndex = NewIndex(0); + } + public void Clear() { Results.Clear(); From 6c4ab3b7f438ee6fca27087e28b4a0f56a9aa124 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 9 Dec 2019 07:45:19 +1100 Subject: [PATCH 07/16] add action keyword when changing qury --- Plugins/Wox.Plugin.Folder/Main.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Plugins/Wox.Plugin.Folder/Main.cs b/Plugins/Wox.Plugin.Folder/Main.cs index b5c122b10..0e8162378 100644 --- a/Plugins/Wox.Plugin.Folder/Main.cs +++ b/Plugins/Wox.Plugin.Folder/Main.cs @@ -58,7 +58,7 @@ namespace Wox.Plugin.Folder return results; } - private Result CreateFolderResult(string title, string path) + private Result CreateFolderResult(string title, string path, string queryActionKeyword) { return new Result { @@ -82,7 +82,7 @@ namespace Wox.Plugin.Folder } string changeTo = path.EndsWith("\\") ? path : path + "\\"; - _context.API.ChangeQuery(changeTo); + _context.API.ChangeQuery(queryActionKeyword + " " + changeTo); return false; } }; @@ -93,7 +93,7 @@ namespace Wox.Plugin.Folder string search = query.Search.ToLower(); var userFolderLinks = _settings.FolderLinks.Where( x => x.Nickname.StartsWith(search, StringComparison.OrdinalIgnoreCase)); - var results = userFolderLinks.Select(item => CreateFolderResult(item.Nickname, item.Path)) + var results = userFolderLinks.Select(item => CreateFolderResult(item.Nickname, item.Path, query.ActionKeyword)) .ToList(); return results; } @@ -166,7 +166,7 @@ namespace Wox.Plugin.Folder var result = fileSystemInfo is DirectoryInfo - ? CreateFolderResult(fileSystemInfo.Name, fileSystemInfo.FullName) + ? CreateFolderResult(fileSystemInfo.Name, fileSystemInfo.FullName, query.ActionKeyword) : CreateFileResult(fileSystemInfo.FullName); results.Add(result); } From f05767afe861afb681e87a2b9cabce87f35070b9 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 9 Dec 2019 08:27:50 +1100 Subject: [PATCH 08/16] Add exceptions for unauth and arg not found when searching --- Plugins/Wox.Plugin.Folder/Main.cs | 36 +++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/Plugins/Wox.Plugin.Folder/Main.cs b/Plugins/Wox.Plugin.Folder/Main.cs index 0e8162378..487974ceb 100644 --- a/Plugins/Wox.Plugin.Folder/Main.cs +++ b/Plugins/Wox.Plugin.Folder/Main.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -157,18 +157,32 @@ namespace Wox.Plugin.Folder incompleteName = incompleteName.Substring(1); } - // search folder and add results - var fileSystemInfos = directoryInfo.GetFileSystemInfos(incompleteName, searchOption); - - foreach (var fileSystemInfo in fileSystemInfos) + try { - if ((fileSystemInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue; + // search folder and add results + var fileSystemInfos = directoryInfo.GetFileSystemInfos(incompleteName, searchOption); - var result = - fileSystemInfo is DirectoryInfo - ? CreateFolderResult(fileSystemInfo.Name, fileSystemInfo.FullName, query.ActionKeyword) - : CreateFileResult(fileSystemInfo.FullName); - results.Add(result); + foreach (var fileSystemInfo in fileSystemInfos) + { + if ((fileSystemInfo.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) continue; + + var result = + fileSystemInfo is DirectoryInfo + ? CreateFolderResult(fileSystemInfo.Name, fileSystemInfo.FullName, query.ActionKeyword) + : CreateFileResult(fileSystemInfo.FullName); + results.Add(result); + } + } + catch(Exception e) + { + if (e is UnauthorizedAccessException || e is ArgumentException) + { + results.Add(new Result { Title = e.Message, Score = 501 }); + + return results; + } + + throw; } return results; From 4f38a953ac39fd5951f079d1904957aa0470451e Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 9 Dec 2019 08:28:22 +1100 Subject: [PATCH 09/16] Add handling when query action keyword is empty --- Plugins/Wox.Plugin.Folder/Main.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Wox.Plugin.Folder/Main.cs b/Plugins/Wox.Plugin.Folder/Main.cs index 487974ceb..de0107284 100644 --- a/Plugins/Wox.Plugin.Folder/Main.cs +++ b/Plugins/Wox.Plugin.Folder/Main.cs @@ -82,7 +82,7 @@ namespace Wox.Plugin.Folder } string changeTo = path.EndsWith("\\") ? path : path + "\\"; - _context.API.ChangeQuery(queryActionKeyword + " " + changeTo); + _context.API.ChangeQuery(string.IsNullOrEmpty(queryActionKeyword)? changeTo : queryActionKeyword + " " + changeTo); return false; } }; From 0acb4f5aed3d0d0bc6e5bb868c97dad86c191dff Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 9 Dec 2019 08:29:20 +1100 Subject: [PATCH 10/16] lower the score for folder results A search of other scores shows highest is 500, except for calculated score from String.Matcher --- Plugins/Wox.Plugin.Folder/Main.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Wox.Plugin.Folder/Main.cs b/Plugins/Wox.Plugin.Folder/Main.cs index de0107284..73725d35f 100644 --- a/Plugins/Wox.Plugin.Folder/Main.cs +++ b/Plugins/Wox.Plugin.Folder/Main.cs @@ -220,7 +220,7 @@ namespace Wox.Plugin.Folder { Title = firstResult, IcoPath = search, - Score = 10000, + Score = 500, Action = c => { Process.Start(search); From 5aa15ef7315d13fdcf4bd58f26af8e049fbdefba Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Mon, 9 Dec 2019 21:27:33 +1100 Subject: [PATCH 11/16] Add tips string to folder subtitle --- Plugins/Wox.Plugin.Folder/Main.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Plugins/Wox.Plugin.Folder/Main.cs b/Plugins/Wox.Plugin.Folder/Main.cs index 73725d35f..2c8cf2703 100644 --- a/Plugins/Wox.Plugin.Folder/Main.cs +++ b/Plugins/Wox.Plugin.Folder/Main.cs @@ -118,7 +118,7 @@ namespace Wox.Plugin.Folder private List QueryInternal_Directory_Exists(Query query) { - var search = query.Search.ToLower(); + var search = query.Search; var results = new List(); var hasSpecial = search.IndexOfAny(_specialSearchChars) >= 0; string incompleteName = ""; @@ -213,12 +213,17 @@ namespace Wox.Plugin.Folder private static Result CreateOpenCurrentFolderResult(string incompleteName, string search) { - string firstResult = "Open current directory"; + var firstResult = "Open current directory"; if (incompleteName.Length > 0) firstResult = "Open " + search; + + var folderName = search.TrimEnd('\\').Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None).Last(); + return new Result { Title = firstResult, + SubTitle = $"Use > to search files and subfolders within {folderName}, " + + $"* to search for file extensions in {folderName} or both >* to combine the search", IcoPath = search, Score = 500, Action = c => From 201c26f7c853c0e758782eff2af18832f9504f32 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 10 Dec 2019 08:23:34 +1100 Subject: [PATCH 12/16] Add run as administrator to Shell plugin settings --- Plugins/Wox.Plugin.Program/Programs/Win32.cs | 2 +- Plugins/Wox.Plugin.Shell/Main.cs | 32 +++++++------------- Plugins/Wox.Plugin.Shell/Settings.cs | 2 ++ Wox.Plugin/SharedCommands/ShellCommand.cs | 9 +++--- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/Plugins/Wox.Plugin.Program/Programs/Win32.cs b/Plugins/Wox.Plugin.Program/Programs/Win32.cs index f0697abef..12b54b524 100644 --- a/Plugins/Wox.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Wox.Plugin.Program/Programs/Win32.cs @@ -97,7 +97,7 @@ namespace Wox.Plugin.Program.Programs Title = api.GetTranslation("wox_plugin_program_run_as_administrator"), Action = _ => { - return Main.StartProcess(ShellCommand.SetCMDRunAsAdministrator(FullPath, ParentDirectory)); + return Main.StartProcess(ShellCommand.SetProcessStartInfo(FullPath, ParentDirectory)); }, IcoPath = "Images/cmd.png" }, diff --git a/Plugins/Wox.Plugin.Shell/Main.cs b/Plugins/Wox.Plugin.Shell/Main.cs index 1e60ef8c9..323cfb5cd 100644 --- a/Plugins/Wox.Plugin.Shell/Main.cs +++ b/Plugins/Wox.Plugin.Shell/Main.cs @@ -9,6 +9,7 @@ using WindowsInput.Native; using Wox.Infrastructure.Hotkey; using Wox.Infrastructure.Logger; using Wox.Infrastructure.Storage; +using Wox.Plugin.SharedCommands; using Application = System.Windows.Application; using Control = System.Windows.Controls.Control; using Keys = System.Windows.Forms.Keys; @@ -164,16 +165,15 @@ namespace Wox.Plugin.Shell { command = command.Trim(); command = Environment.ExpandEnvironmentVariables(command); + var workingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + var runAsAdministratorArg = !runAsAdministrator && !_settings.RunAsAdministrator ? "" : "runas"; ProcessStartInfo info; if (_settings.Shell == Shell.Cmd) { var arguments = _settings.LeaveShellOpen ? $"/k \"{command}\"" : $"/c \"{command}\" & pause"; - info = new ProcessStartInfo - { - FileName = "cmd.exe", - Arguments = arguments, - }; + + info = ShellCommand.SetProcessStartInfo("cmd.exe", workingDirectory, arguments, runAsAdministratorArg); } else if (_settings.Shell == Shell.Powershell) { @@ -186,11 +186,8 @@ namespace Wox.Plugin.Shell { arguments = $"\"{command} ; Read-Host -Prompt \\\"Press Enter to continue\\\"\""; } - info = new ProcessStartInfo - { - FileName = "powershell.exe", - Arguments = arguments - }; + + info = ShellCommand.SetProcessStartInfo("powershell.exe", workingDirectory, arguments, runAsAdministratorArg); } else if (_settings.Shell == Shell.RunCommand) { @@ -200,21 +197,17 @@ namespace Wox.Plugin.Shell var filename = parts[0]; if (ExistInPath(filename)) { - var arguemtns = parts[1]; - info = new ProcessStartInfo - { - FileName = filename, - Arguments = arguemtns - }; + var arguments = parts[1]; + info = ShellCommand.SetProcessStartInfo(filename, workingDirectory, arguments, runAsAdministratorArg); } else { - info = new ProcessStartInfo(command); + info = ShellCommand.SetProcessStartInfo(command, verb: runAsAdministratorArg); } } else { - info = new ProcessStartInfo(command); + info = ShellCommand.SetProcessStartInfo(command, verb: runAsAdministratorArg); } } else @@ -222,10 +215,7 @@ namespace Wox.Plugin.Shell return; } - info.UseShellExecute = true; - info.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); - info.Verb = runAsAdministrator ? "runas" : ""; try { diff --git a/Plugins/Wox.Plugin.Shell/Settings.cs b/Plugins/Wox.Plugin.Shell/Settings.cs index 62eb31f4e..121875308 100644 --- a/Plugins/Wox.Plugin.Shell/Settings.cs +++ b/Plugins/Wox.Plugin.Shell/Settings.cs @@ -7,6 +7,8 @@ namespace Wox.Plugin.Shell public Shell Shell { get; set; } = Shell.Cmd; public bool ReplaceWinR { get; set; } = true; public bool LeaveShellOpen { get; set; } + internal bool RunAsAdministrator { get; set; } = true; + public Dictionary Count = new Dictionary(); public void AddCmdHistory(string cmdName) diff --git a/Wox.Plugin/SharedCommands/ShellCommand.cs b/Wox.Plugin/SharedCommands/ShellCommand.cs index ac3f4e7cb..d7071e735 100644 --- a/Wox.Plugin/SharedCommands/ShellCommand.cs +++ b/Wox.Plugin/SharedCommands/ShellCommand.cs @@ -9,13 +9,14 @@ namespace Wox.Plugin.SharedCommands { public static class ShellCommand { - public static ProcessStartInfo SetCMDRunAsAdministrator(this string fullPath, string parentDirectory) + public static ProcessStartInfo SetProcessStartInfo(this string fileName, string workingDirectory="", string arguments = "", string verb = "") { var info = new ProcessStartInfo { - FileName = fullPath, - WorkingDirectory = parentDirectory, - Verb = "runas" + FileName = fileName, + WorkingDirectory = workingDirectory, + Arguments = arguments, + Verb = verb }; return info; From b123d95b71520540c73e92d5dc776a7630f323ab Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 10 Dec 2019 20:03:43 +1100 Subject: [PATCH 13/16] Add run as admin toggle option to plugin settings --- Plugins/Wox.Plugin.Shell/Languages/en.xaml | 1 + Plugins/Wox.Plugin.Shell/ShellSetting.xaml | 4 +++- Plugins/Wox.Plugin.Shell/ShellSetting.xaml.cs | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Plugins/Wox.Plugin.Shell/Languages/en.xaml b/Plugins/Wox.Plugin.Shell/Languages/en.xaml index 7a953986c..6f56e83f5 100644 --- a/Plugins/Wox.Plugin.Shell/Languages/en.xaml +++ b/Plugins/Wox.Plugin.Shell/Languages/en.xaml @@ -4,6 +4,7 @@ Replace Win+R Do not close Command Prompt after command execution + Always run as administrator Shell Allows to execute system commands from Wox. Commands should start with > this command has been executed {0} times diff --git a/Plugins/Wox.Plugin.Shell/ShellSetting.xaml b/Plugins/Wox.Plugin.Shell/ShellSetting.xaml index f631f6e22..dc6de53ba 100644 --- a/Plugins/Wox.Plugin.Shell/ShellSetting.xaml +++ b/Plugins/Wox.Plugin.Shell/ShellSetting.xaml @@ -12,10 +12,12 @@ + - + + CMD PowerShell RunCommand diff --git a/Plugins/Wox.Plugin.Shell/ShellSetting.xaml.cs b/Plugins/Wox.Plugin.Shell/ShellSetting.xaml.cs index 639c5c3c9..ffa3b5856 100644 --- a/Plugins/Wox.Plugin.Shell/ShellSetting.xaml.cs +++ b/Plugins/Wox.Plugin.Shell/ShellSetting.xaml.cs @@ -17,6 +17,7 @@ namespace Wox.Plugin.Shell { ReplaceWinR.IsChecked = _settings.ReplaceWinR; LeaveShellOpen.IsChecked = _settings.LeaveShellOpen; + AlwaysRunAsAdministrator.IsChecked = _settings.RunAsAdministrator; LeaveShellOpen.IsEnabled = _settings.Shell != Shell.RunCommand; LeaveShellOpen.Checked += (o, e) => @@ -29,6 +30,16 @@ namespace Wox.Plugin.Shell _settings.LeaveShellOpen = false; }; + AlwaysRunAsAdministrator.Checked += (o, e) => + { + _settings.RunAsAdministrator = true; + }; + + AlwaysRunAsAdministrator.Unchecked += (o, e) => + { + _settings.RunAsAdministrator = false; + }; + ReplaceWinR.Checked += (o, e) => { _settings.ReplaceWinR = true; From c22ab4afdf2dfdb8a88351b273aeed3058dc3d28 Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 10 Dec 2019 20:11:12 +1100 Subject: [PATCH 14/16] Revert changes to other plugin. Will refactor as a separate PR --- Plugins/Wox.Plugin.Program/Programs/Win32.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Plugins/Wox.Plugin.Program/Programs/Win32.cs b/Plugins/Wox.Plugin.Program/Programs/Win32.cs index 12b54b524..36e08a3c4 100644 --- a/Plugins/Wox.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Wox.Plugin.Program/Programs/Win32.cs @@ -10,7 +10,6 @@ using Microsoft.Win32; using Shell; using Wox.Infrastructure; using Wox.Plugin.Program.Logger; -using Wox.Plugin.SharedCommands; namespace Wox.Plugin.Program.Programs { @@ -97,7 +96,14 @@ namespace Wox.Plugin.Program.Programs Title = api.GetTranslation("wox_plugin_program_run_as_administrator"), Action = _ => { - return Main.StartProcess(ShellCommand.SetProcessStartInfo(FullPath, ParentDirectory)); + var info = new ProcessStartInfo + { + FileName = FullPath, + WorkingDirectory = ParentDirectory, + Verb = "runas" + }; + var hide = Main.StartProcess(info); + return hide; }, IcoPath = "Images/cmd.png" }, From e60e574902a582c8dbbc50fbc502c604a5faa8ba Mon Sep 17 00:00:00 2001 From: Jeremy Wu Date: Tue, 10 Dec 2019 20:24:18 +1100 Subject: [PATCH 15/16] update --- Plugins/Wox.Plugin.Shell/Settings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Wox.Plugin.Shell/Settings.cs b/Plugins/Wox.Plugin.Shell/Settings.cs index 121875308..af149e829 100644 --- a/Plugins/Wox.Plugin.Shell/Settings.cs +++ b/Plugins/Wox.Plugin.Shell/Settings.cs @@ -7,7 +7,7 @@ namespace Wox.Plugin.Shell public Shell Shell { get; set; } = Shell.Cmd; public bool ReplaceWinR { get; set; } = true; public bool LeaveShellOpen { get; set; } - internal bool RunAsAdministrator { get; set; } = true; + public bool RunAsAdministrator { get; set; } = true; public Dictionary Count = new Dictionary(); From bcc9379ebc9087f6cd5ae75f143354dfbb766026 Mon Sep 17 00:00:00 2001 From: AT <14300910+theClueless@users.noreply.github.com> Date: Tue, 10 Dec 2019 12:18:24 +0200 Subject: [PATCH 16/16] typo in log --- Wox.Infrastructure/Logger/Log.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index dfa05c715..ff72dff1c 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -87,7 +87,7 @@ namespace Wox.Infrastructure.Logger do { - logger.Error($"Exception fulle name:\n <{e.GetType().FullName}>"); + logger.Error($"Exception full name:\n <{e.GetType().FullName}>"); logger.Error($"Exception message:\n <{e.Message}>"); logger.Error($"Exception stack trace:\n <{e.StackTrace}>"); logger.Error($"Exception source:\n <{e.Source}>");