Add placeholder for random alphanumerics in filename (#216)

This commit is contained in:
Peter F 2020-08-06 15:27:39 -04:00 committed by GitHub
parent 7fd013b6c8
commit 926855cd70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View file

@ -44,6 +44,8 @@ namespace GreenshotPlugin.Core {
private const int MaxTitleLength = 80;
private static readonly CoreConfiguration CoreConfig = IniConfig.GetIniSection<CoreConfiguration>();
private const string UnsafeReplacement = "_";
private static readonly Random RandomNumberGen = new Random();
private static readonly Regex RandRegexp = new Regex("^R+$", RegexOptions.Compiled);
/// <summary>
/// Remove invalid characters from the fully qualified filename
@ -160,6 +162,7 @@ namespace GreenshotPlugin.Core {
string replaceValue = string.Empty;
string variable = match.Groups["variable"].Value;
string parameters = match.Groups["parameters"].Value;
string randomChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
if (parameters.Length > 0) {
string[] parms = SplitRegexp.Split(parameters);
@ -241,6 +244,10 @@ namespace GreenshotPlugin.Core {
if (filenameSafeMode) {
replaceValue = MakePathSafe(replaceValue);
}
} else if (RandRegexp.IsMatch(variable)) {
for (int i = 0; i < variable.Length; i++) {
replaceValue += randomChars[RandomNumberGen.Next(randomChars.Length)];
}
} else {
// Handle other variables
// Default use "now" for the capture take´n