mirror of
https://github.com/greenshot/greenshot
synced 2025-08-22 14:24:43 -07:00
Add placeholder for random alphanumerics in filename
This commit is contained in:
parent
5db1f5564b
commit
c2eeeb0211
2 changed files with 8 additions and 0 deletions
|
@ -232,6 +232,7 @@ ${hh} hour, 2 digits
|
||||||
${mm} minute, 2 digits
|
${mm} minute, 2 digits
|
||||||
${ss} second, 2 digits
|
${ss} second, 2 digits
|
||||||
${NUM} incrementing number, 6 digits
|
${NUM} incrementing number, 6 digits
|
||||||
|
${RRR...} random alphanumerics, same length as 'R's
|
||||||
${title} Window title
|
${title} Window title
|
||||||
${user} Windows user
|
${user} Windows user
|
||||||
${domain} Windows domain
|
${domain} Windows domain
|
||||||
|
|
|
@ -44,6 +44,8 @@ namespace GreenshotPlugin.Core {
|
||||||
private const int MaxTitleLength = 80;
|
private const int MaxTitleLength = 80;
|
||||||
private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection<CoreConfiguration>();
|
private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection<CoreConfiguration>();
|
||||||
private const string UnsafeReplacement = "_";
|
private const string UnsafeReplacement = "_";
|
||||||
|
private static readonly Random RandomNumberGen = new Random();
|
||||||
|
private static readonly Regex RandRegexp = new Regex("^R+$", RegexOptions.Compiled);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Remove invalid characters from the fully qualified filename
|
/// Remove invalid characters from the fully qualified filename
|
||||||
|
@ -160,6 +162,7 @@ namespace GreenshotPlugin.Core {
|
||||||
string replaceValue = string.Empty;
|
string replaceValue = string.Empty;
|
||||||
string variable = match.Groups["variable"].Value;
|
string variable = match.Groups["variable"].Value;
|
||||||
string parameters = match.Groups["parameters"].Value;
|
string parameters = match.Groups["parameters"].Value;
|
||||||
|
string randomChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
if (parameters.Length > 0) {
|
if (parameters.Length > 0) {
|
||||||
string[] parms = SplitRegexp.Split(parameters);
|
string[] parms = SplitRegexp.Split(parameters);
|
||||||
|
@ -241,6 +244,10 @@ namespace GreenshotPlugin.Core {
|
||||||
if (filenameSafeMode) {
|
if (filenameSafeMode) {
|
||||||
replaceValue = MakePathSafe(replaceValue);
|
replaceValue = MakePathSafe(replaceValue);
|
||||||
}
|
}
|
||||||
|
} else if (RandRegexp.IsMatch(variable)) {
|
||||||
|
for (int i = 0; i < variable.Length; i++) {
|
||||||
|
replaceValue += randomChars[RandomNumberGen.Next(randomChars.Length)];
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Handle other variables
|
// Handle other variables
|
||||||
// Default use "now" for the capture take´n
|
// Default use "now" for the capture take´n
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue