mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2025-12-30 17:29:30 -06:00
added Touch node
This commit is contained in:
Binary file not shown.
@@ -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": {
|
||||
|
||||
59
BasicNodes/File/Touch.cs
Normal file
59
BasicNodes/File/Touch.cs
Normal file
@@ -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; }
|
||||
}
|
||||
}
|
||||
38
BasicNodes/Tests/TouchTests.cs
Normal file
38
BasicNodes/Tests/TouchTests.cs
Normal file
@@ -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
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Emby/Emby.csproj
BIN
Emby/Emby.csproj
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Plex/Plex.csproj
BIN
Plex/Plex.csproj
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user