diff --git a/Source/LibationFileManager/TemplateTags.cs b/Source/LibationFileManager/TemplateTags.cs index 6b14a3a0..764f1ea8 100644 --- a/Source/LibationFileManager/TemplateTags.cs +++ b/Source/LibationFileManager/TemplateTags.cs @@ -41,8 +41,9 @@ namespace LibationFileManager public static TemplateTags Locale { get; } = new TemplateTags("locale", "Region/country"); public static TemplateTags YearPublished { get; } = new TemplateTags("year", "Year published"); - // Special case. Isn't mapped to a replacement in Templates.cs + // Special cases. Aren't mapped to replacements in Templates.cs // Included here for display by EditTemplateDialog + public static TemplateTags Date { get; } = new TemplateTags("date[...]", "File date/time. e.g. yyyy-MM-dd HH-mm"); public static TemplateTags IfSeries { get; } = new TemplateTags("if series->...<-if series", "Only include if part of a series"); } } diff --git a/Source/LibationFileManager/Templates.cs b/Source/LibationFileManager/Templates.cs index 99d3181b..6047cfe9 100644 --- a/Source/LibationFileManager/Templates.cs +++ b/Source/LibationFileManager/Templates.cs @@ -105,6 +105,7 @@ namespace LibationFileManager : getFileNamingTemplate(libraryBookDto, template, null, fileExtension) .GetFilePath(Configuration.Instance.ReplacementCharacters, fileExtension).PathWithoutPrefix; + private static Regex dateFormatRegex { get; } = new Regex(@"", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static Regex ifSeriesRegex { get; } = new Regex("(.*?)<-if series>", RegexOptions.Compiled | RegexOptions.IgnoreCase); internal static FileNamingTemplate getFileNamingTemplate(LibraryBookDto libraryBookDto, string template, string dirFullPath, string extension) @@ -120,6 +121,8 @@ namespace LibationFileManager template, string.IsNullOrWhiteSpace(libraryBookDto.SeriesName) ? "" : "$1"); + template = dateFormatRegex.Replace(template, dateMatchEvaluator); + var t = template + FileUtility.GetStandardizedExtension(extension); var fullfilename = dirFullPath == "" ? t : Path.Combine(dirFullPath, t); @@ -148,6 +151,18 @@ namespace LibationFileManager } #endregion + private static string dateMatchEvaluator(Match match) + { + try + { + return DateTime.Now.ToString(match.Groups[1].Value); + } + catch + { + return match.Value; + } + } + public virtual IEnumerable GetTemplateTags() => TemplateTags.GetAll() // yeah, this line is a little funky but it works when you think through it. also: trust the unit tests