diff --git a/AVDump3CL/AVD3CLModule.cs b/AVDump3CL/AVD3CLModule.cs index 7887e5b..729b526 100644 --- a/AVDump3CL/AVD3CLModule.cs +++ b/AVDump3CL/AVD3CLModule.cs @@ -74,12 +74,12 @@ public interface IAVDMoveFileExtension { } public class AVDMoveFileScriptGlobal { - public AVDMoveFileScriptGlobal(Dictionary placeholders, IServiceProvider serviceProvider) { - Placeholders = placeholders ?? throw new ArgumentNullException(nameof(placeholders)); + public AVDMoveFileScriptGlobal(Func getHandler, IServiceProvider serviceProvider) { + Get = getHandler ?? throw new ArgumentNullException(nameof(getHandler)); ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider)); } - public Dictionary Placeholders { get; } + public Func Get { get; } public IServiceProvider ServiceProvider { get; } } @@ -239,13 +239,7 @@ static void CreateDirectoryChain(string? path, bool isDirectory = false) { if(settings.FileMove.Mode != FileMoveMode.None) { var scriptString = settings.FileMove.Mode switch { - FileMoveMode.Placeholder => string.Join("\n", - "var filePath = \"" + settings.FileMove.Pattern.Replace("\\", "\\\\").Replace("\"", "\\\"") + "\";", - "foreach(var placeholder in Placeholders) {", - " filePath = filePath.Replace(\"{\" + placeholder.Key + \"}\", placeholder.Value);", - "}", - "return filePath;" - ), + FileMoveMode.Placeholder => "return \"" + Regex.Replace(settings.FileMove.Pattern.Replace("\\", "\\\\").Replace("\"", "\\\""), @"\{([^\}]+)\}", @"Get(""\1"")") + "\";", FileMoveMode.CSharpScriptFile => File.ReadAllText(settings.FileMove.Pattern), FileMoveMode.CSharpScriptInline => throw new NotImplementedException(), _ => throw new InvalidOperationException(), @@ -507,16 +501,18 @@ private async Task HandleReporting(FileMetaInfo fileMetaInfo) { var destFilePath = fileMetaInfo.FileInfo.FullName; if(settings.FileMove.Mode != FileMoveMode.None) { try { - var placeholders = new Dictionary() { - { "FullName", fileMetaInfo.FileInfo.FullName }, - { "FileName", fileMetaInfo.FileInfo.Name }, - { "FileNameWithoutExtension", Path.GetFileNameWithoutExtension(fileMetaInfo.FileInfo.FullName) }, - { "DirectoryName", fileMetaInfo.FileInfo.DirectoryName }, - { "DetectedExtension", fileMetaInfo.CondensedProviders.OfType().FirstOrDefault()?.Select(MediaProvider.SuggestedFileExtensionType)?.Value.FirstOrDefault() ?? fileMetaInfo.FileInfo.Extension } + string GetValue(string key) => key switch { + "FullName" => fileMetaInfo.FileInfo.FullName, + "FileName" => fileMetaInfo.FileInfo.Name, + "FileExtension" => fileMetaInfo.FileInfo.Extension, + "FileNameWithoutExtension" => Path.GetFileNameWithoutExtension(fileMetaInfo.FileInfo.FullName), + "DirectoryName" => fileMetaInfo.FileInfo.DirectoryName, + "DetectedExtension" => fileMetaInfo.CondensedProviders.OfType().FirstOrDefault()?.Select(MediaProvider.SuggestedFileExtensionType)?.Value.FirstOrDefault() ?? fileMetaInfo.FileInfo.Extension, + _ => "", }; - destFilePath = await fileMoveScriptRunner(new AVDMoveFileScriptGlobal(placeholders, fileMoveServiceProvider)); + destFilePath = await fileMoveScriptRunner(new AVDMoveFileScriptGlobal(GetValue, fileMoveServiceProvider)); await Task.Run(() => fileMetaInfo.FileInfo.MoveTo(destFilePath)).ConfigureAwait(false); } catch(Exception) { diff --git a/AVDump3CL/AVDump3CL.csproj b/AVDump3CL/AVDump3CL.csproj index dd02adb..293bce2 100644 --- a/AVDump3CL/AVDump3CL.csproj +++ b/AVDump3CL/AVDump3CL.csproj @@ -5,7 +5,7 @@ netcoreapp3.1 AVD3Icon.ico AVDump3CL.Program - 3.0.8080.0 + 3.0.8081.0 3.0.0 extknot DvdKhl @@ -16,7 +16,7 @@ en Copyright © 2020 extknot AnyCPU;x64 - 3.0.8080.0 + 3.0.8081.0 Debug;Release;GithubWorkflow enable diff --git a/AVDump3Lib/AVDump3Lib.csproj b/AVDump3Lib/AVDump3Lib.csproj index 71d4f35..69526bf 100644 --- a/AVDump3Lib/AVDump3Lib.csproj +++ b/AVDump3Lib/AVDump3Lib.csproj @@ -13,8 +13,8 @@ en AnyCPU;x64 - 3.0.8080.0 - 3.0.8080.0 + 3.0.8081.0 + 3.0.8081.0 Debug;Release;GithubWorkflow enable