diff --git a/BasicNodes/BasicNodes.csproj b/BasicNodes/BasicNodes.csproj index 1a0ebfbd..013e81a7 100644 Binary files a/BasicNodes/BasicNodes.csproj and b/BasicNodes/BasicNodes.csproj differ 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 246539c9..e236e7f2 100644 Binary files a/ChecksumNodes/ChecksumNodes.csproj and b/ChecksumNodes/ChecksumNodes.csproj differ diff --git a/CollectionNodes/CollectionNodes.csproj b/CollectionNodes/CollectionNodes.csproj index f5b62424..9b3d9995 100644 Binary files a/CollectionNodes/CollectionNodes.csproj and b/CollectionNodes/CollectionNodes.csproj differ diff --git a/DiscordNodes/DiscordNodes.csproj b/DiscordNodes/DiscordNodes.csproj index c62e740e..1b1f1f54 100644 Binary files a/DiscordNodes/DiscordNodes.csproj and b/DiscordNodes/DiscordNodes.csproj differ diff --git a/EmailNodes/EmailNodes.csproj b/EmailNodes/EmailNodes.csproj index 01f6877c..f9791695 100644 Binary files a/EmailNodes/EmailNodes.csproj and b/EmailNodes/EmailNodes.csproj differ diff --git a/Emby/Emby.csproj b/Emby/Emby.csproj index 60e9c3df..386675df 100644 Binary files a/Emby/Emby.csproj and b/Emby/Emby.csproj differ diff --git a/Gotify/Gotify.csproj b/Gotify/Gotify.csproj index 31fdcdad..a9d7a8f8 100644 Binary files a/Gotify/Gotify.csproj and b/Gotify/Gotify.csproj differ diff --git a/MetaNodes/MetaNodes.csproj b/MetaNodes/MetaNodes.csproj index a2193392..8359f927 100644 Binary files a/MetaNodes/MetaNodes.csproj and b/MetaNodes/MetaNodes.csproj differ diff --git a/MusicNodes/MusicNodes.csproj b/MusicNodes/MusicNodes.csproj index a2fb444a..1b8e5b65 100644 Binary files a/MusicNodes/MusicNodes.csproj and b/MusicNodes/MusicNodes.csproj differ diff --git a/Plex/Plex.csproj b/Plex/Plex.csproj index 6a632ba4..de1facb7 100644 Binary files a/Plex/Plex.csproj and b/Plex/Plex.csproj differ diff --git a/VideoNodes/VideoNodes.csproj b/VideoNodes/VideoNodes.csproj index c4f285c0..6288c443 100644 Binary files a/VideoNodes/VideoNodes.csproj and b/VideoNodes/VideoNodes.csproj differ