BUG-2114 / FEATURE-998 consolidated the logic to make the behavior equal for all entry points.

This commit is contained in:
Robin 2017-01-20 12:13:37 +01:00
commit 5bdfcd5306
2 changed files with 35 additions and 58 deletions

View file

@ -1307,38 +1307,10 @@ namespace Greenshot {
private void NotifyIconClick(ClickActions clickAction) { private void NotifyIconClick(ClickActions clickAction) {
switch (clickAction) { switch (clickAction) {
case ClickActions.OPEN_LAST_IN_EXPLORER: case ClickActions.OPEN_LAST_IN_EXPLORER:
// Added for BUG-1992, reset the OutputFilePath / OutputFileAsFullpath if they don't exist (e.g. the configuration is used on a different PC) Contextmenu_OpenRecent(this, null);
var outputFilePath = Path.GetDirectoryName(_conf.OutputFileAsFullpath);
if (outputFilePath == null || (!File.Exists(_conf.OutputFileAsFullpath) && !Directory.Exists(Path.GetDirectoryName(outputFilePath))))
{
_conf.OutputFileAsFullpath = _conf.GetDefault(nameof(_conf.OutputFileAsFullpath)) as string;
}
string path = _conf.OutputFileAsFullpath;
if (!File.Exists(path)) {
string lastFilePath = Path.GetDirectoryName(_conf.OutputFileAsFullpath);
if (!string.IsNullOrEmpty(lastFilePath) && Directory.Exists(lastFilePath)) {
path = lastFilePath;
}
}
if (path == null) {
// Added for BUG-1992, reset the OutputFilePath / OutputFileAsFullpath if they don't exist (e.g. the configuration is used on a different PC)
if (!File.Exists(_conf.OutputFilePath))
{
_conf.OutputFilePath = _conf.GetDefault(nameof(_conf.OutputFilePath)) as string;
}
string configPath = FilenameHelper.FillVariables(_conf.OutputFilePath, false);
if (Directory.Exists(configPath)) {
path = configPath;
}
}
ExplorerHelper.OpenInExplorer(path);
break; break;
case ClickActions.OPEN_LAST_IN_EDITOR: case ClickActions.OPEN_LAST_IN_EDITOR:
// Added for BUG-1992, reset the OutputFilePath / OutputFileAsFullpath if they don't exist (e.g. the configuration is used on a different PC) _conf.ValidateAndCorrectOutputFileAsFullpath();
if (!File.Exists(_conf.OutputFileAsFullpath))
{
_conf.OutputFileAsFullpath = _conf.GetDefault(nameof(_conf.OutputFileAsFullpath)) as string;
}
if (File.Exists(_conf.OutputFileAsFullpath)) { if (File.Exists(_conf.OutputFileAsFullpath)) {
CaptureHelper.CaptureFile(_conf.OutputFileAsFullpath, DestinationHelper.GetDestination(EditorDestination.DESIGNATION)); CaptureHelper.CaptureFile(_conf.OutputFileAsFullpath, DestinationHelper.GetDestination(EditorDestination.DESIGNATION));
@ -1357,38 +1329,40 @@ namespace Greenshot {
/// <summary> /// <summary>
/// The Contextmenu_OpenRecent currently opens the last know save location /// The Contextmenu_OpenRecent currently opens the last know save location
/// </summary> /// </summary>
private void Contextmenu_OpenRecent(object sender, EventArgs eventArgs) { private void Contextmenu_OpenRecent(object sender, EventArgs eventArgs)
// Added for BUG-1992, reset the OutputFilePath / OutputFileAsFullpath if they don't exist (e.g. the configuration is used on a different PC) {
if (!File.Exists(_conf.OutputFilePath)) _conf.ValidateAndCorrectOutputFilePath();
_conf.ValidateAndCorrectOutputFileAsFullpath();
string path = _conf.OutputFileAsFullpath;
if (!File.Exists(path))
{ {
_conf.OutputFilePath = _conf.GetDefault(nameof(_conf.OutputFilePath)) as string; path = FilenameHelper.FillVariables(_conf.OutputFilePath, false);
} // Fix for #1470, problems with a drive which is no longer available
try
string path = FilenameHelper.FillVariables(_conf.OutputFilePath, false);
// Fix for #1470, problems with a drive which is no longer available
try {
// Added for BUG-1992, reset the OutputFilePath / OutputFileAsFullpath if they don't exist (e.g. the configuration is used on a different PC)
var outputFilePath = Path.GetDirectoryName(_conf.OutputFileAsFullpath);
if (outputFilePath == null || (!File.Exists(_conf.OutputFileAsFullpath) && !Directory.Exists(Path.GetDirectoryName(outputFilePath))))
{ {
_conf.OutputFileAsFullpath = _conf.GetDefault(nameof(_conf.OutputFileAsFullpath)) as string; string lastFilePath = Path.GetDirectoryName(_conf.OutputFileAsFullpath);
}
string lastFilePath = Path.GetDirectoryName(_conf.OutputFileAsFullpath); if (lastFilePath != null && Directory.Exists(lastFilePath))
{
if (lastFilePath != null && Directory.Exists(lastFilePath)) { path = lastFilePath;
path = lastFilePath; }
} else if (!Directory.Exists(path)) { else if (!Directory.Exists(path))
// What do I open when nothing can be found? Right, nothing... {
return; // What do I open when nothing can be found? Right, nothing...
return;
}
}
catch (Exception ex)
{
LOG.Warn("Couldn't open the path to the last exported file, taking default.", ex);
} }
} catch (Exception ex) {
LOG.Warn("Couldn't open the path to the last exported file, taking default.", ex);
} }
LOG.Debug("DoubleClick was called! Starting: " + path); try
try { {
ExplorerHelper.OpenInExplorer(path); ExplorerHelper.OpenInExplorer(path);
} catch (Exception ex) { }
catch (Exception ex)
{
// Make sure we show what we tried to open in the exception // Make sure we show what we tried to open in the exception
ex.Data.Add("path", path); ex.Data.Add("path", path);
LOG.Warn("Couldn't open the path to the last exported file", ex); LOG.Warn("Couldn't open the path to the last exported file", ex);

View file

@ -15,11 +15,11 @@ namespace GreenshotPlugin.Core
/// If the path is a file, the explorer is opened with the directory and the file is selected. /// If the path is a file, the explorer is opened with the directory and the file is selected.
/// </summary> /// </summary>
/// <param name="path">Path to file or directory</param> /// <param name="path">Path to file or directory</param>
public static void OpenInExplorer(string path) public static bool OpenInExplorer(string path)
{ {
if (path == null) if (path == null)
{ {
return; return false;
} }
try try
{ {
@ -28,6 +28,7 @@ namespace GreenshotPlugin.Core
{ {
using (Process.Start(path)) using (Process.Start(path))
{ {
return true;
} }
} }
// Check if path is a file // Check if path is a file
@ -37,6 +38,7 @@ namespace GreenshotPlugin.Core
using (var explorer = Process.Start("explorer.exe", $"/select,\"{path}\"")) using (var explorer = Process.Start("explorer.exe", $"/select,\"{path}\""))
{ {
explorer?.WaitForInputIdle(500); explorer?.WaitForInputIdle(500);
return true;
} }
} }
} }
@ -46,6 +48,7 @@ namespace GreenshotPlugin.Core
ex.Data.Add("path", path); ex.Data.Add("path", path);
throw; throw;
} }
return false;
} }
} }
} }