diff --git a/Greenshot/Forms/ImageEditorForm.cs b/Greenshot/Forms/ImageEditorForm.cs index c5de9937e..9577772f9 100644 --- a/Greenshot/Forms/ImageEditorForm.cs +++ b/Greenshot/Forms/ImageEditorForm.cs @@ -21,7 +21,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.IO; @@ -1003,24 +1002,12 @@ namespace Greenshot { } private void OpenDirectoryMenuItemClick(object sender, EventArgs e) { - var path = Path.GetDirectoryName(_surface.LastSaveFullPath); - if (path == null) - { - return; - } - var processStartInfo = new ProcessStartInfo("explorer") - { - Arguments = path, - UseShellExecute = false - }; - using (var process = new Process()) { - process.StartInfo = processStartInfo; - process.Start(); - } + ExplorerHelper.OpenInExplorer(_surface.LastSaveFullPath); } #endregion private void BindFieldControls() { + // TODO: This is actually risky, if there are no references than the objects may be garbage collected new BidirectionalBinding(btnFillColor, "SelectedColor", _surface.FieldAggregator.GetField(FieldType.FILL_COLOR), "Value", NotNullValidator.GetInstance()); new BidirectionalBinding(btnLineColor, "SelectedColor", _surface.FieldAggregator.GetField(FieldType.LINE_COLOR), "Value", NotNullValidator.GetInstance()); new BidirectionalBinding(lineThicknessUpDown, "Value", _surface.FieldAggregator.GetField(FieldType.LINE_THICKNESS), "Value", DecimalIntConverter.GetInstance(), NotNullValidator.GetInstance()); diff --git a/Greenshot/Helpers/CaptureHelper.cs b/Greenshot/Helpers/CaptureHelper.cs index 3351db1d8..adffadb58 100644 --- a/Greenshot/Helpers/CaptureHelper.cs +++ b/Greenshot/Helpers/CaptureHelper.cs @@ -507,55 +507,17 @@ namespace Greenshot.Helpers { return; } ISurface surface = eventArgs.Surface; - if (surface != null && eventArgs.MessageType == SurfaceMessageTyp.FileSaved) { - if (!string.IsNullOrEmpty(surface.LastSaveFullPath)) { - string errorMessage = null; - var path = Path.GetDirectoryName(surface.LastSaveFullPath); - try { - 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"); - if (windowsPath != null) - { - string explorerPath = Path.Combine(windowsPath, "explorer.exe"); - if (File.Exists(explorerPath)) - { - var lastSaveDirectory = Path.GetDirectoryName(surface.LastSaveFullPath); - if (lastSaveDirectory != null) - { - var processStartInfo = new ProcessStartInfo(explorerPath) - { - Arguments = lastSaveDirectory, - UseShellExecute = false - }; - using (var process = new Process()) { - process.StartInfo = processStartInfo; - process.Start(); - } - } - errorMessage = null; - } - } - } - catch - { - // ignored - } - } - if (errorMessage != null) { - MessageBox.Show($"{errorMessage}\r\nexplorer.exe {surface.LastSaveFullPath}", "explorer.exe", MessageBoxButtons.OK, MessageBoxIcon.Error); - } + if (surface != null) + { + switch (eventArgs.MessageType) + { + case SurfaceMessageTyp.FileSaved: + ExplorerHelper.OpenInExplorer(surface.LastSaveFullPath); + break; + case SurfaceMessageTyp.UploadedUri: + Process.Start(surface.UploadUrl); + break; } - } else if (!string.IsNullOrEmpty(surface?.UploadUrl)) { - Process.Start(surface.UploadUrl); } Log.DebugFormat("Deregistering the BalloonTipClicked"); RemoveEventHandler(sender, e); diff --git a/GreenshotPlugin/Core/ExplorerHelper.cs b/GreenshotPlugin/Core/ExplorerHelper.cs index 7f65294f4..a94513f48 100644 --- a/GreenshotPlugin/Core/ExplorerHelper.cs +++ b/GreenshotPlugin/Core/ExplorerHelper.cs @@ -32,7 +32,7 @@ namespace GreenshotPlugin.Core } } // Check if path is a file - else if (File.Exists(path)) + if (File.Exists(path)) { // Start the explorer process and select the file using (var explorer = Process.Start("explorer.exe", $"/select,\"{path}\""))