using FileFlows.Plugin; using FileFlows.Plugin.Attributes; using FileFlows.Plugin.Types; namespace FileFlows.BasicNodes.File; /// /// Flow element that compares a file size /// public class FileSize : Node { /// public override int Inputs => 1; /// public override int Outputs => 2; /// public override FlowElementType Type => FlowElementType.Logic; /// public override string Icon => "fas fa-balance-scale-right"; /// public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/file-size"; /// /// Gets or sets the lower value /// [NumberInt(1)] public int Lower { get; set; } /// /// Gets or sets the upper value /// [NumberInt(2)] public int Upper { get; set; } /// public override int Execute(NodeParameters args) { var result = args.IsDirectory ? args.FileService.DirectorySize(args.WorkingFile) : args.FileService.FileSize(args.WorkingFile); if(result.Failed(out string error)) { args.Logger.ELog("Error getting size: " + error); return -1; } return TestSize(args, result.ValueOrDefault); } public int TestSize(NodeParameters args, long size) { if (size < (((long)Lower) * 1024 * 1024)) return 2; if (Upper > 0 && size > (((long)Upper) * 1024 * 1024)) return 2; return 1; } }