BUG-1750 show error message in case of invalid filename generated from pattern

This commit is contained in:
JKlingen 2015-02-18 21:23:23 +01:00
commit ecaf7e95c9
4 changed files with 34 additions and 8 deletions

View file

@ -156,6 +156,7 @@ namespace Greenshot.Configuration {
error_openfile,
error_openlink,
error_save,
error_save_invalid_chars,
help_title,
jpegqualitydialog_choosejpegquality,
qualitydialog_dontaskagain,

View file

@ -84,14 +84,7 @@ namespace Greenshot.Destinations {
fullPath = captureDetails.Filename;
outputSettings.Format = ImageOutput.FormatForFilename(fullPath);
} else {
LOG.InfoFormat("Creating new filename");
string pattern = conf.OutputFileFilenamePattern;
if (string.IsNullOrEmpty(pattern)) {
pattern = "greenshot ${capturetime}";
}
string filename = FilenameHelper.GetFilenameFromPattern(pattern, conf.OutputFileFormat, captureDetails);
string filepath = FilenameHelper.FillVariables(conf.OutputFilePath, false);
fullPath = Path.Combine(filepath, filename);
fullPath = CreateNewFilename(captureDetails);
// As we generate a file, the configuration tells us if we allow to overwrite
overwrite = conf.OutputFileAllowOverwrite;
}
@ -130,5 +123,35 @@ namespace Greenshot.Destinations {
ProcessExport(exportInformation, surface);
return exportInformation;
}
private static string CreateNewFilename(ICaptureDetails captureDetails) {
string fullPath;
LOG.InfoFormat("Creating new filename");
string pattern = conf.OutputFileFilenamePattern;
if (string.IsNullOrEmpty(pattern)) {
pattern = "greenshot ${capturetime}";
}
string filename = FilenameHelper.GetFilenameFromPattern(pattern, conf.OutputFileFormat, captureDetails);
string filepath = FilenameHelper.FillVariables(conf.OutputFilePath, false);
try {
fullPath = Path.Combine(filepath, filename);
} catch (ArgumentException ae) {
// configured filename or path not valid, show error message...
LOG.InfoFormat("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 = new SettingsForm().ShowDialog();
if (dialogResult == DialogResult.OK) {
// ... OK -> then try again:
fullPath = CreateNewFilename(captureDetails);
} else {
// ... cancelled.
fullPath = null;
}
}
return fullPath;
}
}
}

View file

@ -164,6 +164,7 @@ Bitte überprüfen Sie die Schreibrechte oder wählen Sie einen anderen Speicher
<resource name="error_openfile">Die Datei "{0}" konnte nicht geöffnet werden.</resource>
<resource name="error_openlink">Konnte Link '{0}' nicht öffnen.</resource>
<resource name="error_save">Screenshot konnte nicht gespeichert werden, bitte wählen Sie einen anderen Speicherort.</resource>
<resource name="error_save_invalid_chars">Der generierte Datei- oder Verzeichnisname ist nicht gültig. Bitte korrigieren Sie das Dateiname-Muster und versuchen Sie es erneut.</resource>
<resource name="expertsettings">Experten</resource>
<resource name="expertsettings_autoreducecolors">8-Bit-Bilder erstellen bei weniger als 256 Farben</resource>
<resource name="expertsettings_checkunstableupdates">Auch instabile Updates anbieten</resource>

View file

@ -164,6 +164,7 @@ Please check write accessibility of the selected storage location.</resource>
<resource name="error_openfile">The file "{0}" could not be opened.</resource>
<resource name="error_openlink">Could not open link '{0}'.</resource>
<resource name="error_save">Could not save screenshot, please find a suitable location.</resource>
<resource name="error_save_invalid_chars">The generated filename or directory name is not valid. Please fix the filename pattern and then try again.</resource>
<resource name="expertsettings">Expert</resource>
<resource name="expertsettings_autoreducecolors">Create an 8-bit image if the colors are less than 256 while having a &gt; 8 bits image</resource>
<resource name="expertsettings_checkunstableupdates">Check for unstable updates</resource>