Skip to content

Commit

Permalink
FileMove Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DvdKhl committed Jul 10, 2020
1 parent b75a5c5 commit 61d6b8a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
30 changes: 13 additions & 17 deletions AVDump3CL/AVD3CLModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public interface IAVDMoveFileExtension {
}

public class AVDMoveFileScriptGlobal {
public AVDMoveFileScriptGlobal(Dictionary<string, string> placeholders, IServiceProvider serviceProvider) {
Placeholders = placeholders ?? throw new ArgumentNullException(nameof(placeholders));
public AVDMoveFileScriptGlobal(Func<string, string> getHandler, IServiceProvider serviceProvider) {
Get = getHandler ?? throw new ArgumentNullException(nameof(getHandler));
ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
}

public Dictionary<string, string> Placeholders { get; }
public Func<string, string> Get { get; }
public IServiceProvider ServiceProvider { get; }
}

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -507,16 +501,18 @@ private async Task<bool> HandleReporting(FileMetaInfo fileMetaInfo) {
var destFilePath = fileMetaInfo.FileInfo.FullName;
if(settings.FileMove.Mode != FileMoveMode.None) {
try {
var placeholders = new Dictionary<string, string>() {
{ "FullName", fileMetaInfo.FileInfo.FullName },
{ "FileName", fileMetaInfo.FileInfo.Name },
{ "FileNameWithoutExtension", Path.GetFileNameWithoutExtension(fileMetaInfo.FileInfo.FullName) },
{ "DirectoryName", fileMetaInfo.FileInfo.DirectoryName },
{ "DetectedExtension", fileMetaInfo.CondensedProviders.OfType<MediaProvider>().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<MediaProvider>().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) {
Expand Down
4 changes: 2 additions & 2 deletions AVDump3CL/AVDump3CL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<ApplicationIcon>AVD3Icon.ico</ApplicationIcon>
<StartupObject>AVDump3CL.Program</StartupObject>
<AssemblyVersion>3.0.8080.0</AssemblyVersion>
<AssemblyVersion>3.0.8081.0</AssemblyVersion>
<Version>3.0.0</Version>
<Company>extknot</Company>
<Authors>DvdKhl</Authors>
Expand All @@ -16,7 +16,7 @@
<NeutralLanguage>en</NeutralLanguage>
<Copyright>Copyright © 2020 extknot</Copyright>
<Platforms>AnyCPU;x64</Platforms>
<FileVersion>3.0.8080.0</FileVersion>
<FileVersion>3.0.8081.0</FileVersion>
<Configurations>Debug;Release;GithubWorkflow</Configurations>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions AVDump3Lib/AVDump3Lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<NeutralLanguage>en</NeutralLanguage>
<ApplicationIcon></ApplicationIcon>
<Platforms>AnyCPU;x64</Platforms>
<AssemblyVersion>3.0.8080.0</AssemblyVersion>
<FileVersion>3.0.8080.0</FileVersion>
<AssemblyVersion>3.0.8081.0</AssemblyVersion>
<FileVersion>3.0.8081.0</FileVersion>
<Configurations>Debug;Release;GithubWorkflow</Configurations>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down

0 comments on commit 61d6b8a

Please sign in to comment.