From 32793c545575f06c5e6d43ed1fc9fbaef414ebce Mon Sep 17 00:00:00 2001 From: John Andrews Date: Fri, 24 Jun 2022 22:49:21 +1200 Subject: [PATCH] added help url for replace original --- BasicNodes/File/ReplaceOriginal.cs | 107 ++++++++++++++--------------- 1 file changed, 53 insertions(+), 54 deletions(-) diff --git a/BasicNodes/File/ReplaceOriginal.cs b/BasicNodes/File/ReplaceOriginal.cs index 4bd20b24..8a8ede26 100644 --- a/BasicNodes/File/ReplaceOriginal.cs +++ b/BasicNodes/File/ReplaceOriginal.cs @@ -1,61 +1,60 @@ -namespace FileFlows.BasicNodes.File +using FileFlows.Plugin; + +namespace FileFlows.BasicNodes.File; + +public class ReplaceOriginal : Node { - using System.Text; - using System.Text.RegularExpressions; - using FileFlows.Plugin; + public override int Inputs => 1; + public override int Outputs => 1; + public override string Icon => "fas fa-file"; + + public override string HelpUrl => "https://docs.fileflows.com/plugins/basic-nodes/replace-original"; - public class ReplaceOriginal : Node + public string _Pattern = string.Empty; + + public override FlowElementType Type => FlowElementType.Process; + + public override int Execute(NodeParameters args) { - public override int Inputs => 1; - public override int Outputs => 1; - public override string Icon => "fas fa-file"; - - public string _Pattern = string.Empty; - - public override FlowElementType Type => FlowElementType.Process; - - public override int Execute(NodeParameters args) + if (args.FileName == args.WorkingFile) { - if (args.FileName == args.WorkingFile) - { - args.Logger?.ILog("Working file is same as original, nothing to do."); - return 1; - } - var wf = new FileInfo(args.WorkingFile); - if (args.FileName.ToLower().EndsWith(wf.Extension.ToLower())) - { - // easy replace - bool moved = args.MoveFile(args.FileName); - if(moved == false) - { - args.Logger?.ELog("Failed to move file to: "+ args.FileName); - return -1; - } - } - else - { - // different extension, we will move the file, but then delete the original - string dest = Path.ChangeExtension(args.FileName, wf.Extension); - if(args.MoveFile(dest) == false) - { - args.Logger?.ELog("Failed to move file to: " + dest); - return -1; - } - if (dest.ToLower() != args.FileName.ToLower()) - { - try - { - System.IO.File.Delete(args.FileName); - } - catch (Exception ex) - { - args.Logger?.ELog("Failed to delete orginal (with different extension): " + ex.Message); - return -1; - } - } - } - + args.Logger?.ILog("Working file is same as original, nothing to do."); return 1; } + var wf = new FileInfo(args.WorkingFile); + if (args.FileName.ToLower().EndsWith(wf.Extension.ToLower())) + { + // easy replace + bool moved = args.MoveFile(args.FileName); + if(moved == false) + { + args.Logger?.ELog("Failed to move file to: "+ args.FileName); + return -1; + } + } + else + { + // different extension, we will move the file, but then delete the original + string dest = Path.ChangeExtension(args.FileName, wf.Extension); + if(args.MoveFile(dest) == false) + { + args.Logger?.ELog("Failed to move file to: " + dest); + return -1; + } + if (dest.ToLower() != args.FileName.ToLower()) + { + try + { + System.IO.File.Delete(args.FileName); + } + catch (Exception ex) + { + args.Logger?.ELog("Failed to delete orginal (with different extension): " + ex.Message); + return -1; + } + } + } + + return 1; } -} +} \ No newline at end of file