mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-02-19 20:09:04 -06:00
set WarningsAsErrors = true
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
<PackageProjectUrl>https://fileflows.com/</PackageProjectUrl>
|
||||
<Description>Basic flow elements for FileFlows. This plugin contains basic and common flow elements to process files.
|
||||
This plugin is required for FileFlows to work.</Description>
|
||||
<TreatWarningsAsErrors>True</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<NoWarn>1701;1702;CS8618;CS8601;CS8602;CS8603;CS8604;CS8618;CS8625;CS8765;CS8767;CS8618l;CS8600</NoWarn>
|
||||
@@ -25,9 +26,6 @@ This plugin is required for FileFlows to work.</Description>
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="3.3.1" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SharpCompress" Version="0.36.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Plugin">
|
||||
<HintPath>..\FileFlows.Plugin.dll</HintPath>
|
||||
|
||||
@@ -1,185 +1,189 @@
|
||||
namespace FileFlows.BasicNodes.File
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using FileFlows.Plugin;
|
||||
using FileFlows.Plugin.Attributes;
|
||||
using FileFlows.Plugin.Helpers;
|
||||
|
||||
namespace FileFlows.BasicNodes.File;
|
||||
|
||||
/// <summary>
|
||||
/// Node that copies a file
|
||||
/// </summary>
|
||||
public class CopyFile : Node
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using FileFlows.Plugin;
|
||||
using FileFlows.Plugin.Attributes;
|
||||
using FileFlows.Plugin.Helpers;
|
||||
/// <summary>
|
||||
/// Gets the number of inputs
|
||||
/// </summary>
|
||||
public override int Inputs => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of outputs
|
||||
/// </summary>
|
||||
public override int Outputs => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of node
|
||||
/// </summary>
|
||||
public override FlowElementType Type => FlowElementType.Process;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the icon for this node
|
||||
/// </summary>
|
||||
public override string Icon => "far fa-copy";
|
||||
|
||||
/// <summary>
|
||||
/// Node that copies a file
|
||||
/// Gets the help URL
|
||||
/// </summary>
|
||||
public class CopyFile : Node
|
||||
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/copy-file";
|
||||
|
||||
private string _DestinationPath = string.Empty;
|
||||
private string _DestinationFile = string.Empty;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the input file to move
|
||||
/// </summary>
|
||||
[TextVariable(1)]
|
||||
public string InputFile{ get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the destination path to copy the file to
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Folder(2)]
|
||||
public string DestinationPath
|
||||
{
|
||||
get => _DestinationPath;
|
||||
set => _DestinationPath = value ?? string.Empty;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets or sets the destination file
|
||||
/// </summary>
|
||||
[TextVariable(3)]
|
||||
public string DestinationFile
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the number of inputs
|
||||
/// </summary>
|
||||
public override int Inputs => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of outputs
|
||||
/// </summary>
|
||||
public override int Outputs => 1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the type of node
|
||||
/// </summary>
|
||||
public override FlowElementType Type => FlowElementType.Process;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the icon for this node
|
||||
/// </summary>
|
||||
public override string Icon => "far fa-copy";
|
||||
get => _DestinationFile;
|
||||
set => _DestinationFile = value ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the help URL
|
||||
/// </summary>
|
||||
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/copy-file";
|
||||
/// <summary>
|
||||
/// Gets or sets if the folder structure should be copied
|
||||
/// </summary>
|
||||
[Boolean(4)]
|
||||
public bool CopyFolder { get; set; }
|
||||
|
||||
private string _DestinationPath = string.Empty;
|
||||
private string _DestinationFile = string.Empty;
|
||||
/// <summary>
|
||||
/// Gets or sets additional files to copy
|
||||
/// </summary>
|
||||
[StringArray(5)]
|
||||
public string[] AdditionalFiles { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the additional files should be copied from the source location (true) or temporary location (false)
|
||||
/// </summary>
|
||||
[Boolean(6)]
|
||||
public bool AdditionalFilesFromOriginal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the input file to move
|
||||
/// </summary>
|
||||
[TextVariable(1)]
|
||||
public string InputFile{ get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets if the original files creation and last write time dates should be preserved
|
||||
/// </summary>
|
||||
[Boolean(7)]
|
||||
public bool PreserverOriginalDates { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
|
||||
var destParts = MoveFile.GetDestinationPathParts(args, DestinationPath, DestinationFile, CopyFolder);
|
||||
if (destParts.Filename == null)
|
||||
return -1;
|
||||
|
||||
[Required]
|
||||
[Folder(2)]
|
||||
public string DestinationPath
|
||||
{
|
||||
get => _DestinationPath;
|
||||
set { _DestinationPath = value ?? ""; }
|
||||
}
|
||||
[TextVariable(3)]
|
||||
public string DestinationFile
|
||||
string inputFile = args.ReplaceVariables(InputFile ?? string.Empty, stripMissing: true)?.EmptyAsNull() ?? args.WorkingFile;
|
||||
|
||||
// cant use new FileInfo(dest).Directory.Name here since
|
||||
// if the folder is a linux folder and this node is running on windows
|
||||
// /mnt, etc will be converted to c:\mnt and break the destination
|
||||
var destDir = destParts.Path;
|
||||
var destFile = destParts.Filename;
|
||||
if(inputFile != args.WorkingFile && string.IsNullOrWhiteSpace(DestinationFile))
|
||||
{
|
||||
get => _DestinationFile;
|
||||
set { _DestinationFile = value ?? ""; }
|
||||
destFile = FileHelper.GetShortFileName(inputFile);
|
||||
}
|
||||
string dest = FileHelper.Combine(destParts.Path, destFile);
|
||||
|
||||
//bool copied = args.CopyFile(args.WorkingFile, dest, updateWorkingFile: true);
|
||||
//if (!copied)
|
||||
// return -1;
|
||||
args.Logger?.ILog("File to copy: " + inputFile);
|
||||
args.Logger?.ILog("Destination: " + dest);
|
||||
|
||||
if (args.FileService.FileCopy(inputFile, dest, true).Failed(out string error))
|
||||
{
|
||||
args.FailureReason = "Failed to copy file: " + error;
|
||||
args.Logger?.ELog(args.FailureReason);
|
||||
return -1;
|
||||
}
|
||||
|
||||
[Boolean(4)]
|
||||
public bool CopyFolder { get; set; }
|
||||
|
||||
[StringArray(5)]
|
||||
public string[] AdditionalFiles { get; set; }
|
||||
|
||||
[Boolean(6)]
|
||||
public bool AdditionalFilesFromOriginal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the original files creation and last write time dates should be preserved
|
||||
/// </summary>
|
||||
[Boolean(7)]
|
||||
public bool PreserverOriginalDates { get; set; }
|
||||
|
||||
private bool Canceled;
|
||||
|
||||
public override Task Cancel()
|
||||
if (inputFile == args.WorkingFile)
|
||||
{
|
||||
Canceled = true;
|
||||
return base.Cancel();
|
||||
}
|
||||
args.Logger?.ILog("Setting working file to: " + dest);
|
||||
args.SetWorkingFile(dest);
|
||||
|
||||
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
Canceled = false;
|
||||
|
||||
|
||||
var destParts = MoveFile.GetDestinationPathParts(args, DestinationPath, DestinationFile, CopyFolder);
|
||||
if (destParts.Filename == null)
|
||||
return -1;
|
||||
|
||||
string inputFile = args.ReplaceVariables(InputFile ?? string.Empty, stripMissing: true)?.EmptyAsNull() ?? args.WorkingFile;
|
||||
|
||||
// cant use new FileInfo(dest).Directory.Name here since
|
||||
// if the folder is a linux folder and this node is running on windows
|
||||
// /mnt, etc will be converted to c:\mnt and break the destination
|
||||
var destDir = destParts.Path;
|
||||
var destFile = destParts.Filename;
|
||||
if(inputFile != args.WorkingFile && string.IsNullOrWhiteSpace(DestinationFile))
|
||||
if (PreserverOriginalDates)
|
||||
{
|
||||
destFile = FileHelper.GetShortFileName(inputFile);
|
||||
}
|
||||
string dest = FileHelper.Combine(destParts.Path, destFile);
|
||||
|
||||
//bool copied = args.CopyFile(args.WorkingFile, dest, updateWorkingFile: true);
|
||||
//if (!copied)
|
||||
// return -1;
|
||||
args.Logger?.ILog("File to copy: " + inputFile);
|
||||
args.Logger?.ILog("Destination: " + dest);
|
||||
|
||||
if (args.FileService.FileCopy(inputFile, dest, true).Failed(out string error))
|
||||
{
|
||||
args.FailureReason = "Failed to copy file: " + error;
|
||||
args.Logger?.ELog(args.FailureReason);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (inputFile == args.WorkingFile)
|
||||
{
|
||||
args.Logger?.ILog("Setting working file to: " + dest);
|
||||
args.SetWorkingFile(dest);
|
||||
|
||||
if (PreserverOriginalDates)
|
||||
if (args.Variables.TryGetValue("ORIGINAL_CREATE_UTC", out object oCreateTimeUtc) &&
|
||||
args.Variables.TryGetValue("ORIGINAL_LAST_WRITE_UTC", out object oLastWriteUtc) &&
|
||||
oCreateTimeUtc is DateTime dtCreateTimeUtc && oLastWriteUtc is DateTime dtLastWriteUtc)
|
||||
{
|
||||
if (args.Variables.TryGetValue("ORIGINAL_CREATE_UTC", out object oCreateTimeUtc) &&
|
||||
args.Variables.TryGetValue("ORIGINAL_LAST_WRITE_UTC", out object oLastWriteUtc) &&
|
||||
oCreateTimeUtc is DateTime dtCreateTimeUtc && oLastWriteUtc is DateTime dtLastWriteUtc)
|
||||
{
|
||||
args.Logger?.ILog("Preserving dates");
|
||||
args.FileService.SetLastWriteTimeUtc(dest, dtLastWriteUtc);
|
||||
args.FileService.SetCreationTimeUtc(dest, dtCreateTimeUtc);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Logger?.WLog("Preserve dates is on but failed to get original dates from variables");
|
||||
}
|
||||
args.Logger?.ILog("Preserving dates");
|
||||
args.FileService.SetLastWriteTimeUtc(dest, dtLastWriteUtc);
|
||||
args.FileService.SetCreationTimeUtc(dest, dtCreateTimeUtc);
|
||||
}
|
||||
else
|
||||
{
|
||||
args.Logger?.WLog("Preserve dates is on but failed to get original dates from variables");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var srcDir = FileHelper.GetDirectory(AdditionalFilesFromOriginal
|
||||
? args.FileName
|
||||
: inputFile);
|
||||
var srcDir = FileHelper.GetDirectory(AdditionalFilesFromOriginal
|
||||
? args.FileName
|
||||
: inputFile);
|
||||
|
||||
if (AdditionalFiles?.Any() == true)
|
||||
if (AdditionalFiles?.Any() == true)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
foreach (var additional in AdditionalFiles)
|
||||
{
|
||||
foreach (var additional in AdditionalFiles)
|
||||
foreach(var addFile in args.FileService.GetFiles(srcDir, additional).ValueOrDefault ?? new string[] {})
|
||||
{
|
||||
foreach(var addFile in args.FileService.GetFiles(srcDir, additional).ValueOrDefault ?? new string[] {})
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
string shortName = FileHelper.GetShortFileName(addFile);
|
||||
|
||||
string addFileDest = destDir + args.FileService.PathSeparator + shortName;
|
||||
args.FileService.FileCopy(addFile, addFileDest, true);
|
||||
//args.CopyFile(addFile, addFileDest, updateWorkingFile: false);
|
||||
string shortName = FileHelper.GetShortFileName(addFile);
|
||||
|
||||
string addFileDest = destDir + args.FileService.PathSeparator + shortName;
|
||||
args.FileService.FileCopy(addFile, addFileDest, true);
|
||||
//args.CopyFile(addFile, addFileDest, updateWorkingFile: false);
|
||||
|
||||
//FileHelper.ChangeOwner(args.Logger, addFileDest, file: true);
|
||||
//FileHelper.ChangeOwner(args.Logger, addFileDest, file: true);
|
||||
|
||||
args.Logger?.ILog("Copied file: \"" + addFile + "\" to \"" + addFileDest + "\"");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
args.Logger?.ILog("Failed copying file: \"" + addFile + "\": " + ex.Message);
|
||||
}
|
||||
args.Logger?.ILog("Copied file: \"" + addFile + "\" to \"" + addFileDest + "\"");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
args.Logger?.ILog("Failed copying file: \"" + addFile + "\": " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
args.Logger.WLog("Error copying additional files: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
// not needed as args.CopyFile does this
|
||||
//args?.SetWorkingFile(dest);
|
||||
return 1;
|
||||
catch (Exception ex)
|
||||
{
|
||||
args.Logger.WLog("Error copying additional files: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
// not needed as args.CopyFile does this
|
||||
//args?.SetWorkingFile(dest);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -19,8 +19,8 @@ public class PatternReplacer : Node
|
||||
public override FlowElementType Type => FlowElementType.Process;
|
||||
/// <inheritdoc />
|
||||
public override string Icon => "fas fa-exchange-alt";
|
||||
|
||||
public string Group => "File";
|
||||
/// <inheritdoc />
|
||||
public override string Group => "File";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/filename-pattern-replacer";
|
||||
@@ -108,7 +108,10 @@ public class PatternReplacer : Node
|
||||
// this might not be a regex, but try it first
|
||||
updated = Regex.Replace(updated, replacement.Key, value, RegexOptions.IgnoreCase);
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignored
|
||||
}
|
||||
|
||||
updated = updated.Replace(replacement.Key, value);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#if (DEBUG)
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
#if (DEBUG)
|
||||
|
||||
namespace BasicNodes.Tests
|
||||
{
|
||||
@@ -25,11 +27,13 @@ namespace BasicNodes.Tests
|
||||
{
|
||||
if (args == null || args.Length == 0)
|
||||
return;
|
||||
#pragma warning disable IL2026
|
||||
string message = type + " -> " +
|
||||
string.Join(", ", args.Select(x =>
|
||||
x == null ? "null" :
|
||||
x.GetType().IsPrimitive || x is string ? x.ToString() :
|
||||
System.Text.Json.JsonSerializer.Serialize(x)));
|
||||
#pragma warning restore IL2026
|
||||
Messages.Add(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -460,23 +460,6 @@ public class LocalFileService : IFileService
|
||||
FileHelper.ChangeOwner(logger, path, file: isFile, ownerGroup: OwnerGroup);
|
||||
|
||||
logMethod(logger.ToString());
|
||||
|
||||
return;
|
||||
|
||||
|
||||
if (OperatingSystem.IsLinux())
|
||||
{
|
||||
var filePermissions = FileHelper.ConvertLinuxPermissionsToUnixFileMode(permissions.Value);
|
||||
if (filePermissions == UnixFileMode.None)
|
||||
{
|
||||
logMethod("SetPermissions: Invalid file permissions: " + permissions.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
File.SetUnixFileMode(path, filePermissions);
|
||||
logMethod($"SetPermissions: Permission [{filePermissions}] set on file: " + path);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,9 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using FileFlows.Plugin;
|
||||
using FileFlows.Plugin.Attributes;
|
||||
using System.IO.Compression;
|
||||
using FileFlows.BasicNodes;
|
||||
using SharpCompress.Archives;
|
||||
using System.IO;
|
||||
|
||||
namespace BasicNodes.Tools;
|
||||
@@ -13,9 +10,13 @@ namespace BasicNodes.Tools;
|
||||
/// </summary>
|
||||
public class Unpack: Node
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override int Inputs => 1;
|
||||
/// <inheritdoc />
|
||||
public override int Outputs => 1;
|
||||
/// <inheritdoc />
|
||||
public override FlowElementType Type => FlowElementType.Process;
|
||||
/// <inheritdoc />
|
||||
public override string Icon => "fas fa-file-archive";
|
||||
/// <summary>
|
||||
/// Gets the Help URL for this element
|
||||
@@ -25,6 +26,9 @@ public class Unpack: Node
|
||||
private string _DestinationPath = string.Empty;
|
||||
private string _file = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the destination path
|
||||
/// </summary>
|
||||
[Folder(1)]
|
||||
public string DestinationPath
|
||||
{
|
||||
@@ -32,13 +36,17 @@ public class Unpack: Node
|
||||
set { _DestinationPath = value ?? ""; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the file to unpack
|
||||
/// </summary>
|
||||
[TextVariable(2)]
|
||||
public string File
|
||||
{
|
||||
get => _file;
|
||||
set { _file = value ?? ""; }
|
||||
set => _file = value ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
try
|
||||
@@ -58,10 +66,11 @@ public class Unpack: Node
|
||||
if (Directory.Exists(destDir) == false)
|
||||
Directory.CreateDirectory(destDir);
|
||||
|
||||
if (fileInfo.Extension.ToLower() == ".zip")
|
||||
ZipFile.ExtractToDirectory(filename, destDir, true);
|
||||
else
|
||||
Extract(args, args.WorkingFile, destDir);
|
||||
args.ArchiveHelper.Extract(filename, destDir, (percent) =>
|
||||
{
|
||||
args.PartPercentageUpdate(percent);
|
||||
});
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -71,59 +80,4 @@ public class Unpack: Node
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Unpacks a file
|
||||
/// </summary>
|
||||
/// <param name="args">the node parameters</param>
|
||||
/// <param name="workingFile">the file to extract</param>
|
||||
/// <param name="destinationPath">the location to extract to</param>
|
||||
private void Extract(NodeParameters args, string workingFile, string destinationPath)
|
||||
{
|
||||
bool isRar = workingFile.ToLowerInvariant().EndsWith(".cbr") || workingFile.ToLowerInvariant().EndsWith(".rar");
|
||||
try
|
||||
{
|
||||
ArchiveFactory.WriteToDirectory(workingFile, destinationPath, new ()
|
||||
{
|
||||
ExtractFullPath = true
|
||||
});
|
||||
}
|
||||
catch (Exception ex) when (isRar && ex.Message.Contains("Unknown Rar Header"))
|
||||
{
|
||||
UnrarCommandLineExtract(args, workingFile, destinationPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Unpacks a folder
|
||||
/// </summary>
|
||||
/// <param name="args">the node parameters</param>
|
||||
/// <param name="workingFile">the file to extract</param>
|
||||
/// <param name="destinationPath">the location to extract to</param>
|
||||
void UnrarCommandLineExtract(NodeParameters args, string workingFile, string destinationPath)
|
||||
{
|
||||
var process = new Process();
|
||||
string unrar = args.GetToolPath("unrar")?.EmptyAsNull() ?? "unrar";
|
||||
process.StartInfo.FileName = unrar;
|
||||
process.StartInfo.ArgumentList.Add("x");
|
||||
process.StartInfo.ArgumentList.Add("-o+");
|
||||
process.StartInfo.ArgumentList.Add(workingFile);
|
||||
process.StartInfo.ArgumentList.Add(destinationPath);
|
||||
process.StartInfo.UseShellExecute = false;
|
||||
process.StartInfo.RedirectStandardOutput = true;
|
||||
process.StartInfo.RedirectStandardError = true;
|
||||
process.StartInfo.CreateNoWindow = true;
|
||||
process.Start();
|
||||
string output = process.StandardError.ReadToEnd();
|
||||
string error = process.StandardError.ReadToEnd();
|
||||
process.WaitForExit();
|
||||
|
||||
args.Logger?.ILog("Unrar output:\n" + output);
|
||||
if (string.IsNullOrWhiteSpace(error) == false)
|
||||
args.Logger?.ELog("Unrar error:\n" + error);
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
throw new Exception(error?.EmptyAsNull() ?? "Failed to extract rar file");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
using BasicNodes.Tools;
|
||||
using FileFlows.Plugin;
|
||||
using FileFlows.Plugin.Attributes;
|
||||
|
||||
namespace FileFlows.BasicNodes.File;
|
||||
|
||||
/// <summary>
|
||||
/// Node that unzips a file
|
||||
/// </summary>
|
||||
public class Unzip : Node
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets that this node is obsolete
|
||||
/// </summary>
|
||||
public override bool Obsolete => true;
|
||||
/// <summary>
|
||||
/// Gets the obsolete message
|
||||
/// </summary>
|
||||
public override string ObsoleteMessage => "This has been replaced with the Unpack flow element.\n\nUse that instead.";
|
||||
public override int Inputs => 1;
|
||||
public override int Outputs => 1;
|
||||
public override FlowElementType Type => FlowElementType.Process;
|
||||
public override string Icon => "fas fa-file-archive";
|
||||
/// <summary>
|
||||
/// Gets the Help URL for this element
|
||||
/// </summary>
|
||||
public override string HelpUrl => "https://fileflows.com/docs/plugins/basic-nodes/unzip";
|
||||
|
||||
private string _DestinationPath = string.Empty;
|
||||
private string _zip = string.Empty;
|
||||
|
||||
[Folder(1)]
|
||||
public string DestinationPath
|
||||
{
|
||||
get => _DestinationPath;
|
||||
set { _DestinationPath = value ?? ""; }
|
||||
}
|
||||
|
||||
[TextVariable(2)]
|
||||
public string Zip
|
||||
{
|
||||
get => _zip;
|
||||
set { _zip = value ?? ""; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the node
|
||||
/// </summary>
|
||||
/// <param name="args">the arguments</param>
|
||||
/// <returns>the output</returns>
|
||||
public override int Execute(NodeParameters args)
|
||||
{
|
||||
var unpack = new Unpack();
|
||||
unpack.File = Zip;
|
||||
unpack.DestinationPath = DestinationPath;
|
||||
return unpack.Execute(args);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public class Zip : Node
|
||||
public string DestinationPath
|
||||
{
|
||||
get => _DestinationPath;
|
||||
set { _DestinationPath = value ?? ""; }
|
||||
set => _DestinationPath = value ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,7 +52,7 @@ public class Zip : Node
|
||||
public string DestinationFile
|
||||
{
|
||||
get => _DestinationFile;
|
||||
set { _DestinationFile = value ?? ""; }
|
||||
set => _DestinationFile = value ?? string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -121,39 +121,16 @@ public class Zip : Node
|
||||
args.Logger?.ELog("Cannot zip remote directories");
|
||||
return -1;
|
||||
}
|
||||
var dir = new DirectoryInfo(args.WorkingFile);
|
||||
var files = dir.GetFiles("*.*", SearchOption.AllDirectories);
|
||||
using FileStream fs = new FileStream(tempZip, FileMode.Create);
|
||||
using ZipArchive arch = new ZipArchive(fs, ZipArchiveMode.Create);
|
||||
args?.PartPercentageUpdate(0);
|
||||
float current = 0;
|
||||
float count = files.Length;
|
||||
foreach (var file in files)
|
||||
args.ArchiveHelper.Compress(args.WorkingFile, tempZip, allDirectories: true, percentCallback:(percent) =>
|
||||
{
|
||||
++count;
|
||||
if (string.Equals(file.FullName, destFile, StringComparison.CurrentCultureIgnoreCase))
|
||||
continue; // cant zip the zip we are creating
|
||||
string relative = file.FullName[(dir.FullName.Length + 1)..];
|
||||
try
|
||||
{
|
||||
arch.CreateEntryFromFile(file.FullName, relative, CompressionLevel.SmallestSize);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
args.Logger?.WLog("Failed to add file to zip: " + file.FullName + " => " + ex.Message);
|
||||
}
|
||||
|
||||
args?.PartPercentageUpdate((current / count) * 100);
|
||||
}
|
||||
|
||||
args.PartPercentageUpdate(percent);
|
||||
});
|
||||
args?.PartPercentageUpdate(100);
|
||||
}
|
||||
else
|
||||
{
|
||||
string localFile = args.FileService.GetLocalPath(args.WorkingFile);
|
||||
using FileStream fs = new FileStream(tempZip, FileMode.Create);
|
||||
using ZipArchive arch = new ZipArchive(fs, ZipArchiveMode.Create);
|
||||
arch.CreateEntryFromFile(localFile, FileHelper.GetShortFileName(args.LibraryFileName));
|
||||
args.ArchiveHelper.Compress(localFile, tempZip);
|
||||
}
|
||||
|
||||
if (System.IO.File.Exists(tempZip) == false)
|
||||
|
||||
Reference in New Issue
Block a user