mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-01-05 23:39:50 -06:00
FF-1015 - fixing copy/move
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.RegularExpressions;
|
||||
using FileFlows.Plugin;
|
||||
using FileFlows.Plugin.Attributes;
|
||||
|
||||
@@ -80,7 +81,7 @@ public class MoveFile : Node
|
||||
/// <returns>the output to call next</returns>
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
var dest = GetDesitnationPath(args, DestinationPath, DestinationFile, MoveFolder);
|
||||
var dest = GetDestinationPath(args, DestinationPath, DestinationFile, MoveFolder);
|
||||
if (dest == null)
|
||||
return -1;
|
||||
|
||||
@@ -146,55 +147,76 @@ public class MoveFile : Node
|
||||
return 1;
|
||||
}
|
||||
|
||||
internal static string GetDesitnationPath(NodeParameters args, string destinationPath, string destinationFile = null, bool moveFolder = false)
|
||||
/// <summary>
|
||||
/// Gets the full destination path
|
||||
/// </summary>
|
||||
/// <param name="args">the node parameters</param>
|
||||
/// <param name="destinationPath">the requested destination path</param>
|
||||
/// <param name="destinationFile">the requested destination file</param>
|
||||
/// <param name="moveFolder">if the relative folder should be also be included, relative to the library</param>
|
||||
/// <returns>the full destination path</returns>
|
||||
internal static string GetDestinationPath(NodeParameters args, string destinationPath,
|
||||
string destinationFile = null, bool moveFolder = false)
|
||||
{
|
||||
string dest = args.ReplaceVariables(destinationPath, true);
|
||||
dest = dest.Replace("\\", Path.DirectorySeparatorChar.ToString());
|
||||
dest = dest.Replace("/", Path.DirectorySeparatorChar.ToString());
|
||||
if (string.IsNullOrEmpty(dest))
|
||||
var result = GetDestinationPathParts(args, destinationPath, destinationFile, moveFolder);
|
||||
if(result.Filename == null)
|
||||
return null;
|
||||
return result.Path + result.Separator + result.Filename;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the destination path and filename
|
||||
/// </summary>
|
||||
/// <param name="args">the node parameters</param>
|
||||
/// <param name="destinationPath">the requested destination path</param>
|
||||
/// <param name="destinationFile">the requested destination file</param>
|
||||
/// <param name="moveFolder">if the relative folder should be also be included, relative to the library</param>
|
||||
/// <returns>the path and filename</returns>
|
||||
internal static (string? Path, string? Filename, string? Separator) GetDestinationPathParts(NodeParameters args, string destinationPath, string destinationFile = null, bool moveFolder = false)
|
||||
{
|
||||
string separator = args.WorkingFile.IndexOf('/') >= 0 ? "/" : "\\";
|
||||
string destFolder = args.ReplaceVariables(destinationPath, true);
|
||||
destFolder = destFolder.Replace("\\", separator);
|
||||
destFolder = destFolder.Replace("/", separator);
|
||||
string destFilename = args.FileName.Replace("\\", separator)
|
||||
.Replace("/", separator);
|
||||
destFilename = destFilename.Substring(destFilename.LastIndexOf(separator) + 1);
|
||||
if (string.IsNullOrEmpty(destFolder))
|
||||
{
|
||||
args.Logger?.ELog("No destination specified");
|
||||
args.Result = NodeResult.Failure;
|
||||
return null;
|
||||
return (null, null, null);
|
||||
}
|
||||
args.Result = NodeResult.Failure;
|
||||
|
||||
if (moveFolder) // we only want the full directory relative to the library, we don't want the original filename
|
||||
{
|
||||
dest = Path.Combine(dest, args.RelativeFile);
|
||||
dest = dest[..dest.LastIndexOf(Path.DirectorySeparatorChar)];
|
||||
args.Logger?.ILog("Using relative directory: " + dest);
|
||||
}
|
||||
|
||||
dest = Path.Combine(dest, new FileInfo(args.FileName).Name);
|
||||
|
||||
var fiDest = new FileInfo(dest);
|
||||
var fiWorking = new FileInfo(args.WorkingFile);
|
||||
if (string.IsNullOrEmpty(fiDest.Extension) == false && fiDest.Extension != fiWorking.Extension)
|
||||
{
|
||||
dest = dest.Substring(0, dest.LastIndexOf(".")) + fiWorking.Extension;
|
||||
destFolder = Path.Combine(destFolder, args.RelativeFile);
|
||||
destFolder = destFolder[..destFolder.LastIndexOf(separator)];
|
||||
args.Logger?.ILog("Using relative directory: " + destFolder);
|
||||
}
|
||||
|
||||
// dest = Path.Combine(dest, argsFilename);
|
||||
if (string.IsNullOrEmpty(destinationFile) == false)
|
||||
{
|
||||
// FF-154 - changed file.Name and file.Orig.Filename to be the full short filename including the extension
|
||||
destinationFile = destinationFile.Replace("{file.Orig.FileName}{file.Orig.Extension}", "{file.Orig.FileName}");
|
||||
destinationFile = destinationFile.Replace("{file.Name}{file.Extension}", "{file.Name}");
|
||||
destinationFile = destinationFile.Replace("{file.Name}{ext}", "{file.Name}");
|
||||
string destFile = args.ReplaceVariables(destinationFile);
|
||||
dest = Path.Combine(new FileInfo(dest).DirectoryName!, destFile);
|
||||
destFilename = args.ReplaceVariables(destinationFile);
|
||||
}
|
||||
|
||||
string destExtension = new FileInfo(destFilename).Extension;
|
||||
string workingExtension = new FileInfo(args.WorkingFile).Extension;
|
||||
|
||||
fiDest = new FileInfo(dest);
|
||||
var fiWorkingFile = new FileInfo(args.WorkingFile);
|
||||
if (fiDest.Extension != fiWorkingFile.Extension)
|
||||
if (string.IsNullOrEmpty(destExtension) == false && destExtension != workingExtension)
|
||||
{
|
||||
dest = dest.Replace(fiDest.Extension, fiWorkingFile.Extension);
|
||||
fiDest = new FileInfo(dest);
|
||||
destFilename = destFilename.Substring(0, destFilename.LastIndexOf(".")) + workingExtension;
|
||||
}
|
||||
|
||||
args.Logger?.ILog("Final destination: " + dest);
|
||||
|
||||
return dest;
|
||||
args.Logger?.ILog("Final destination path: " + destFolder);
|
||||
args.Logger?.ILog("Final destination filename: " + destFilename);
|
||||
|
||||
return (destFolder, destFilename, separator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user