/// <summary> /// The Contextmenu_OpenRecent currently opens the last know save location /// </summary> private void Contextmenu_OpenRecent(object sender, EventArgs eventArgs) { _coreConfiguration.ValidateAndCorrectOutputFilePath(); _coreConfiguration.ValidateAndCorrectOutputFileAsFullpath(); var path = _coreConfiguration.OutputFileAsFullpath; if (!File.Exists(path)) { path = FilenameHelper.FillVariables(_coreConfiguration.OutputFilePath, false); // Fix for #1470, problems with a drive which is no longer available try { var lastFilePath = Path.GetDirectoryName(_coreConfiguration.OutputFileAsFullpath); if (lastFilePath != null && Directory.Exists(lastFilePath)) { path = lastFilePath; } else if (!Directory.Exists(path)) { // What do I open when nothing can be found? Right, nothing... return; } } catch (Exception ex) { Log.Warn().WriteLine(ex, "Couldn't open the path to the last exported file, taking default."); } } try { ExplorerHelper.OpenInExplorer(path); } catch (Exception ex) { // Make sure we show what we tried to open in the exception ex.Data.Add("path", path); Log.Warn().WriteLine(ex, "Couldn't open the path to the last exported file"); // No reason to create a bug-form, we just display the error. MessageBox.Show(this, ex.Message, $"Opening {path}", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private string CreateNewFilename(ICaptureDetails captureDetails) { string fullPath; Log.Info().WriteLine("Creating new filename"); var pattern = _coreConfiguration.OutputFileFilenamePattern; if (string.IsNullOrEmpty(pattern)) { pattern = "greenshot ${capturetime}"; } var filename = FilenameHelper.GetFilenameFromPattern(pattern, _coreConfiguration.OutputFileFormat, captureDetails); _coreConfiguration.ValidateAndCorrectOutputFilePath(); var filepath = FilenameHelper.FillVariables(_coreConfiguration.OutputFilePath, false); try { fullPath = Path.Combine(filepath, filename); } catch (ArgumentException) { // configured filename or path not valid, show error message... Log.Info().WriteLine("Generated path or filename not valid: {0}, {1}", filepath, filename); MessageBox.Show(Language.GetString(LangKey.error_save_invalid_chars), Language.GetString(LangKey.error)); // ... lets get the pattern fixed.... var dialogResult = _settingsForm.ShowDialog(); if (dialogResult == DialogResult.OK) { // ... OK -> then try again: fullPath = CreateNewFilename(captureDetails); } else { // ... cancelled. fullPath = null; } } return(fullPath); }