diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs
index b8164fba4..da36ae559 100644
--- a/Greenshot/Forms/MainForm.cs
+++ b/Greenshot/Forms/MainForm.cs
@@ -1321,30 +1321,7 @@ namespace Greenshot {
}
}
- if (path != null) {
- try {
- // Check if path is a directory
- if (Directory.Exists(path))
- {
- using (Process.Start(path))
- {
- }
- }
- // Check if path is a file
- else if (File.Exists(path))
- {
- // Start the explorer process and select the file
- using (var explorer = Process.Start("explorer.exe", $"/select,\"{path}\""))
- {
- explorer?.WaitForInputIdle(500);
- }
- }
- } catch (Exception ex) {
- // Make sure we show what we tried to open in the exception
- ex.Data.Add("path", path);
- throw;
- }
- }
+ ExplorerHelper.OpenInExplorer(path);
break;
case ClickActions.OPEN_LAST_IN_EDITOR:
if (File.Exists(_conf.OutputFileAsFullpath)) {
@@ -1381,7 +1358,7 @@ namespace Greenshot {
}
LOG.Debug("DoubleClick was called! Starting: " + path);
try {
- Process.Start(path);
+ ExplorerHelper.OpenInExplorer(path);
} catch (Exception ex) {
// Make sure we show what we tried to open in the exception
ex.Data.Add("path", path);
diff --git a/Greenshot/Helpers/CaptureHelper.cs b/Greenshot/Helpers/CaptureHelper.cs
index e62afabe7..9cfc3a665 100644
--- a/Greenshot/Helpers/CaptureHelper.cs
+++ b/Greenshot/Helpers/CaptureHelper.cs
@@ -512,22 +512,14 @@ namespace Greenshot.Helpers {
string errorMessage = null;
var path = Path.GetDirectoryName(surface.LastSaveFullPath);
try {
- if (path != null)
- {
- var processStartInfo = new ProcessStartInfo("explorer.exe")
- {
- Arguments = path,
- UseShellExecute = false
- };
- using (var process = new Process()) {
- process.StartInfo = processStartInfo;
- process.Start();
- }
- }
- } catch (Exception ex) {
+ ExplorerHelper.OpenInExplorer(path);
+ }
+ catch (Exception ex)
+ {
errorMessage = ex.Message;
}
// Added fallback for when the explorer can't be found
+ // TODO: Check if this makes sense
if (errorMessage != null) {
try {
string windowsPath = Environment.GetEnvironmentVariable("SYSTEMROOT");
diff --git a/GreenshotPlugin/Core/ExplorerHelper.cs b/GreenshotPlugin/Core/ExplorerHelper.cs
new file mode 100644
index 000000000..12bcb1787
--- /dev/null
+++ b/GreenshotPlugin/Core/ExplorerHelper.cs
@@ -0,0 +1,51 @@
+using System;
+using System.Diagnostics;
+using System.IO;
+
+namespace GreenshotPlugin.Core
+{
+ ///
+ /// Simple utility for the explorer
+ ///
+ public static class ExplorerHelper
+ {
+ ///
+ /// Open the path in the windows explorer.
+ /// If the path is a directory, it will just open the explorer with that directory.
+ /// If the path is a file, the explorer is opened with the directory and the file is selected.
+ ///
+ /// Path to file or directory
+ public static void OpenInExplorer(string path)
+ {
+ if (path == null)
+ {
+ return;
+ }
+ try
+ {
+ // Check if path is a directory
+ if (Directory.Exists(path))
+ {
+ using (Process.Start(path))
+ {
+ }
+ }
+ // Check if path is a file
+ else if (File.Exists(path))
+ {
+ // Start the explorer process and select the file
+ using (var explorer = Process.Start("explorer.exe", $"/select,\"{path}\""))
+ {
+ explorer?.WaitForInputIdle(500);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ // Make sure we show what we tried to open in the exception
+ ex.Data.Add("path", path);
+ throw;
+ }
+ }
+ }
+}