mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 05:53:27 -07:00
BUG-1750 show error message in case of invalid filename generated from pattern
This commit is contained in:
parent
f393f3a9d4
commit
ecaf7e95c9
4 changed files with 34 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue