common helper for execute shell process from run plugins (#9538)

This commit is contained in:
Davide Giacometti
2021-02-23 09:53:08 +01:00
committed by GitHub
parent 20a922ce21
commit 571bceb386
17 changed files with 77 additions and 128 deletions

View File

@@ -7,6 +7,7 @@ using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Text.RegularExpressions;
using Wox.Infrastructure;
using Wox.Plugin;
using Wox.Plugin.Logger;
@@ -48,23 +49,12 @@ namespace Microsoft.Plugin.Folder.Sources
return sanitizedPath.Insert(0, "\\");
}
[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 path, IPublicAPI contextApi)
{
try
if (!Helper.OpenInShell(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}, {e.Message}", e, MethodBase.GetCurrentMethod().DeclaringType);
contextApi.ShowMsg(messageBoxTitle, e.Message);
var message = string.Format(CultureInfo.InvariantCulture, "{0}: {1}", Properties.Resources.wox_plugin_folder_select_folder_OpenFileOrFolder_error_message, path);
contextApi.ShowMsg(message);
}
return true;