From bac17d9a9b03f01ebde2e4c455ec36dc05d995c8 Mon Sep 17 00:00:00 2001 From: John Andrews Date: Fri, 22 Apr 2022 16:29:36 +1200 Subject: [PATCH] added Touch node --- BasicNodes/BasicNodes.csproj | Bin 3778 -> 3778 bytes BasicNodes/BasicNodes.en.json | 10 +++++ BasicNodes/File/Touch.cs | 59 +++++++++++++++++++++++++ BasicNodes/Tests/TouchTests.cs | 38 ++++++++++++++++ ChecksumNodes/ChecksumNodes.csproj | Bin 2872 -> 2872 bytes CollectionNodes/CollectionNodes.csproj | Bin 3256 -> 3256 bytes DiscordNodes/DiscordNodes.csproj | Bin 2870 -> 2870 bytes EmailNodes/EmailNodes.csproj | Bin 3386 -> 3386 bytes Emby/Emby.csproj | Bin 2844 -> 2844 bytes Gotify/Gotify.csproj | Bin 2752 -> 2752 bytes MetaNodes/MetaNodes.csproj | Bin 4504 -> 4504 bytes MusicNodes/MusicNodes.csproj | Bin 4228 -> 4228 bytes Plex/Plex.csproj | Bin 2844 -> 2844 bytes VideoNodes/VideoNodes.csproj | Bin 4098 -> 4098 bytes 14 files changed, 107 insertions(+) create mode 100644 BasicNodes/File/Touch.cs create mode 100644 BasicNodes/Tests/TouchTests.cs diff --git a/BasicNodes/BasicNodes.csproj b/BasicNodes/BasicNodes.csproj index 1a0ebfbdadc3a304ddb10d4d46c8e70ad0705e16..013e81a74a01cd39d157bb488ee5503f4af38f83 100644 GIT binary patch delta 20 ccmX>kdq{S}8%9R6$!{4W8O=7kGgb2d09CyQCjbBd delta 20 ccmX>kdq{S}8%9Rc$!{4W8BI64Ggb2d09C68B>(^b diff --git a/BasicNodes/BasicNodes.en.json b/BasicNodes/BasicNodes.en.json index 8804daa1..ab678b92 100644 --- a/BasicNodes/BasicNodes.en.json +++ b/BasicNodes/BasicNodes.en.json @@ -243,6 +243,16 @@ "CsvFile-Help": "Will append to this file the original name and the renamed file. Useful when using ''Log Only'' to test the renamer before changing files." } }, + "Touch": { + "Description": "Touches a file or directory and sets the last write time to now.", + "Outputs": { + "1": "Successfully touched item" + }, + "Fields": { + "FileName": "File Name", + "FileName-Help": "Full filename of file or folder to touch.\nIf left blank the working file will be used." + } + }, "WebRequest": { "Description": "Allows you to send a web request", "Outputs": { diff --git a/BasicNodes/File/Touch.cs b/BasicNodes/File/Touch.cs new file mode 100644 index 00000000..81a80f4e --- /dev/null +++ b/BasicNodes/File/Touch.cs @@ -0,0 +1,59 @@ +namespace FileFlows.BasicNodes.File; + +using FileFlows.Plugin; +using FileFlows.Plugin.Attributes; + +public class Touch : Node +{ + public override int Inputs => 1; + public override int Outputs => 1; + public override FlowElementType Type => FlowElementType.Process; + public override string Icon => "fas fa-hand-point-right"; + + [TextVariable(1)] + public string FileName { get; set; } + + public override int Execute(NodeParameters args) + { + string filename = args.ReplaceVariables(this.FileName ?? string.Empty, stripMissing: true); + if (string.IsNullOrEmpty(filename)) + filename = args.WorkingFile; + + if (IsDirectory(filename)) + { + try + { + var dir = new DirectoryInfo(filename); + Directory.SetLastWriteTimeUtc(filename, DateTime.UtcNow); + return 1; + } + catch (Exception ex) + { + args.Logger?.ELog("Failed to touch directory: " + ex.Message); + return -1; + } + } + else + { + try + { + System.IO.File.SetLastWriteTimeUtc(filename, DateTime.UtcNow); + return 1; + } + catch (Exception ex) + { + args.Logger?.ELog($"Failed to touch file: '{filename}' => {ex.Message}"); + return -1; + } + } + } + + private bool IsDirectory(string filename) + { + try + { + return new DirectoryInfo(filename).Exists; + } + catch (Exception) { return false; } + } +} diff --git a/BasicNodes/Tests/TouchTests.cs b/BasicNodes/Tests/TouchTests.cs new file mode 100644 index 00000000..f2c7dfa4 --- /dev/null +++ b/BasicNodes/Tests/TouchTests.cs @@ -0,0 +1,38 @@ +#if(DEBUG) + +namespace BasicNodes.Tests; + +using FileFlows.BasicNodes.File; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +[TestClass] +public class TouchTests +{ + FileFlows.Plugin.NodeParameters Args; + + [TestInitialize] + public void TestStarting() + { + Args = new FileFlows.Plugin.NodeParameters(@"c:\test\testfile.mkv", new TestLogger(), false, string.Empty); + } + + [TestMethod] + public void Touch_File() + { + Touch node = new (); + node.FileName = @"D:\videos\testfiles\basic.mkv"; + var result = node.Execute(Args); + Assert.AreEqual(1, result); + } + + [TestMethod] + public void Touch_Folder() + { + Touch node = new(); + node.FileName = @"D:\videos\testfiles"; + var result = node.Execute(Args); + Assert.AreEqual(1, result); + } +} + +#endif \ No newline at end of file diff --git a/ChecksumNodes/ChecksumNodes.csproj b/ChecksumNodes/ChecksumNodes.csproj index 246539c9d4cde5b529b85ee9a8321c03bbbf5606..e236e7f28e70b366e01e140c1884f4b91f5514e5 100644 GIT binary patch delta 35 rcmdlXwnJ>gDJE7k1{((b$qShzC*R}ZnykjcH;Gw+(QLCKvp5F;!FmZm delta 35 rcmdlXwnJ>gDJE7^1{((b$qShzC*R}ZnykjcH;Gw+(R8ySvp5F;!C47D diff --git a/CollectionNodes/CollectionNodes.csproj b/CollectionNodes/CollectionNodes.csproj index f5b62424f543d938819efe5a8f0625720a6363cc..9b3d99952829147889f7cbd32d5e492ba874cb18 100644 GIT binary patch delta 36 scmdlXxkGZpEk;%|1{((b$r~9ZC&%${P2R)IH(7v5fzfQUAyYdS0M1gdO&o83lpmugAIfJWN9YJ$$OYMCTB6}F`8|j$)wH!0FmwpN&o-= delta 32 ocmX>gdO&o83lpm;gAIfJWN9YJ$$OYMCTB6}F`90k$)wH!0FlrLNB{r; diff --git a/MetaNodes/MetaNodes.csproj b/MetaNodes/MetaNodes.csproj index a2193392bb624dc15ad5414dcd47028c18c50949..8359f92796d3fd85555ee032d62e9c3f9c5628d7 100644 GIT binary patch delta 20 ccmbQCJVSZI9VSMz$#9m;e9( diff --git a/MusicNodes/MusicNodes.csproj b/MusicNodes/MusicNodes.csproj index a2fb444a707f25c501d78081e1f5454acc7bd37a..1b8e5b65794b8816cfa9d019116a2e6812bd4dda 100644 GIT binary patch delta 20 bcmZosY*F0sh>6i`@?)k*MzhVf%6j3@?)k*M$^r<%6i`@?)k*MzhVf%tv_uOf?4F delta 20 bcmZotXj0hlh>6j3@?)k*M$^r<%tv_uOd|%`