Add file creation DateTime to naming templates

typo
This commit is contained in:
Mbucari 2023-01-19 17:11:29 -07:00
parent f72551fa9a
commit 9309aea6d9
2 changed files with 17 additions and 1 deletions

View File

@ -41,8 +41,9 @@ namespace LibationFileManager
public static TemplateTags Locale { get; } = new TemplateTags("locale", "Region/country"); public static TemplateTags Locale { get; } = new TemplateTags("locale", "Region/country");
public static TemplateTags YearPublished { get; } = new TemplateTags("year", "Year published"); 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 // 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"); public static TemplateTags IfSeries { get; } = new TemplateTags("if series->...<-if series", "Only include if part of a series");
} }
} }

View File

@ -105,6 +105,7 @@ namespace LibationFileManager
: getFileNamingTemplate(libraryBookDto, template, null, fileExtension) : getFileNamingTemplate(libraryBookDto, template, null, fileExtension)
.GetFilePath(Configuration.Instance.ReplacementCharacters, fileExtension).PathWithoutPrefix; .GetFilePath(Configuration.Instance.ReplacementCharacters, fileExtension).PathWithoutPrefix;
private static Regex dateFormatRegex { get; } = new Regex(@"<date\[(.*?)\]>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private static Regex ifSeriesRegex { get; } = new Regex("<if series->(.*?)<-if series>", RegexOptions.Compiled | RegexOptions.IgnoreCase); private static Regex ifSeriesRegex { get; } = new Regex("<if series->(.*?)<-if series>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
internal static FileNamingTemplate getFileNamingTemplate(LibraryBookDto libraryBookDto, string template, string dirFullPath, string extension) internal static FileNamingTemplate getFileNamingTemplate(LibraryBookDto libraryBookDto, string template, string dirFullPath, string extension)
@ -120,6 +121,8 @@ namespace LibationFileManager
template, template,
string.IsNullOrWhiteSpace(libraryBookDto.SeriesName) ? "" : "$1"); string.IsNullOrWhiteSpace(libraryBookDto.SeriesName) ? "" : "$1");
template = dateFormatRegex.Replace(template, dateMatchEvaluator);
var t = template + FileUtility.GetStandardizedExtension(extension); var t = template + FileUtility.GetStandardizedExtension(extension);
var fullfilename = dirFullPath == "" ? t : Path.Combine(dirFullPath, t); var fullfilename = dirFullPath == "" ? t : Path.Combine(dirFullPath, t);
@ -148,6 +151,18 @@ namespace LibationFileManager
} }
#endregion #endregion
private static string dateMatchEvaluator(Match match)
{
try
{
return DateTime.Now.ToString(match.Groups[1].Value);
}
catch
{
return match.Value;
}
}
public virtual IEnumerable<TemplateTags> GetTemplateTags() public virtual IEnumerable<TemplateTags> GetTemplateTags()
=> TemplateTags.GetAll() => TemplateTags.GetAll()
// yeah, this line is a little funky but it works when you think through it. also: trust the unit tests // yeah, this line is a little funky but it works when you think through it. also: trust the unit tests