diff --git a/Greenshot/Destinations/FileDestination.cs b/Greenshot/Destinations/FileDestination.cs index d3f1a2cb4..0c52af596 100644 --- a/Greenshot/Destinations/FileDestination.cs +++ b/Greenshot/Destinations/FileDestination.cs @@ -115,6 +115,11 @@ namespace Greenshot.Destinations { pattern = "greenshot ${capturetime}"; } string filename = FilenameHelper.GetFilenameFromPattern(pattern, CoreConfig.OutputFileFormat, captureDetails); + // 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(CoreConfig.OutputFilePath)) + { + CoreConfig.OutputFilePath = CoreConfig.GetDefault(nameof(CoreConfig.OutputFilePath)) as string; + } string filepath = FilenameHelper.FillVariables(CoreConfig.OutputFilePath, false); try { fullPath = Path.Combine(filepath, filename); diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index da36ae559..9509d3458 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -1307,6 +1307,11 @@ namespace Greenshot { private void NotifyIconClick(ClickActions clickAction) { switch (clickAction) { 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) + if (!File.Exists(_conf.OutputFileAsFullpath)) + { + _conf.OutputFileAsFullpath = _conf.GetDefault(nameof(_conf.OutputFileAsFullpath)) as string; + } string path = _conf.OutputFileAsFullpath; if (!File.Exists(path)) { string lastFilePath = Path.GetDirectoryName(_conf.OutputFileAsFullpath); @@ -1315,15 +1320,25 @@ namespace Greenshot { } } 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; 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) + if (!File.Exists(_conf.OutputFileAsFullpath)) + { + _conf.OutputFileAsFullpath = _conf.GetDefault(nameof(_conf.OutputFileAsFullpath)) as string; + } + if (File.Exists(_conf.OutputFileAsFullpath)) { CaptureHelper.CaptureFile(_conf.OutputFileAsFullpath, DestinationHelper.GetDestination(EditorDestination.DESIGNATION)); } @@ -1342,9 +1357,21 @@ namespace Greenshot { /// The Contextmenu_OpenRecent currently opens the last know save location /// 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.OutputFilePath = _conf.GetDefault(nameof(_conf.OutputFilePath)) as string; + } + 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) + if (!File.Exists(_conf.OutputFileAsFullpath)) + { + _conf.OutputFileAsFullpath = _conf.GetDefault(nameof(_conf.OutputFileAsFullpath)) as string; + } + string lastFilePath = Path.GetDirectoryName(_conf.OutputFileAsFullpath); if (lastFilePath != null && Directory.Exists(lastFilePath)) { diff --git a/GreenshotPlugin/Controls/SaveImageFileDialog.cs b/GreenshotPlugin/Controls/SaveImageFileDialog.cs index 10621c323..e79450958 100644 --- a/GreenshotPlugin/Controls/SaveImageFileDialog.cs +++ b/GreenshotPlugin/Controls/SaveImageFileDialog.cs @@ -68,6 +68,12 @@ namespace GreenshotPlugin.Controls { ApplyFilterOptions(); string initialDirectory = null; try { + // 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.OutputFileAsFullpath)) + { + conf.OutputFileAsFullpath = conf.GetDefault(nameof(conf.OutputFileAsFullpath)) as string; + } + initialDirectory = Path.GetDirectoryName(conf.OutputFileAsFullpath); } catch { LOG.WarnFormat("OutputFileAsFullpath was set to {0}, ignoring due to problem in path.", conf.OutputFileAsFullpath); @@ -90,12 +96,12 @@ namespace GreenshotPlugin.Controls { PrepareFilterOptions(); string fdf = ""; int preselect = 0; - var outputFileFormatAsString = Enum.GetName(typeof(OutputFormat), conf.OutputFileFormat); + var outputFileFormatAsString = Enum.GetName(typeof(OutputFormat), conf.OutputFileFormat); for(int i=0; i<_filterOptions.Length; i++){ FilterOption fo = _filterOptions[i]; fdf += fo.Label + "|*." + fo.Extension + "|"; - if(outputFileFormatAsString == fo.Extension) - preselect = i; + if(outputFileFormatAsString == fo.Extension) + preselect = i; } fdf = fdf.Substring(0, fdf.Length-1); SaveFileDialog.Filter = fdf; diff --git a/GreenshotPlugin/Core/CoreConfiguration.cs b/GreenshotPlugin/Core/CoreConfiguration.cs index c61cab2e3..a08392109 100644 --- a/GreenshotPlugin/Core/CoreConfiguration.cs +++ b/GreenshotPlugin/Core/CoreConfiguration.cs @@ -342,9 +342,8 @@ namespace GreenshotPlugin.Core { case "OutputFileAsFullpath": if (IniConfig.IsPortable) { return Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots\dummy.png"); - } else { - return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"dummy.png"); } + return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),"dummy.png"); case "OutputFilePath": if (IniConfig.IsPortable) { string pafOutputFilePath = Path.Combine(Application.StartupPath, @"..\..\Documents\Pictures\Greenshots"); @@ -515,16 +514,6 @@ namespace GreenshotPlugin.Core { if (WebRequestReadWriteTimeout < 1) { WebRequestReadWriteTimeout = 100; } - - // Added for BUG-1992, reset the OutputFilePath / OutputFileAsFullpath if they don't exist (e.g. the configuration is used on a different PC) - if (!Directory.Exists(OutputFilePath)) - { - OutputFilePath = GetDefault(nameof(OutputFilePath)) as string; - } - if (!File.Exists(OutputFileAsFullpath)) - { - OutputFileAsFullpath = GetDefault(nameof(OutputFileAsFullpath)) as string; - } } } } \ No newline at end of file