2024-08-23 21:36:04 -04:00
|
|
|
using System;
|
2024-12-03 15:38:59 -05:00
|
|
|
using System.Collections.Generic;
|
2024-08-23 21:36:04 -04:00
|
|
|
using System.IO;
|
2025-10-07 17:33:01 -04:00
|
|
|
#if NET462_OR_GREATER || NETCOREAPP
|
|
|
|
|
using SharpCompress.Archives.Zip;
|
2024-08-23 21:36:04 -04:00
|
|
|
#endif
|
|
|
|
|
|
2025-10-11 09:34:00 -04:00
|
|
|
namespace MPF.Processors.OutputFiles
|
2024-08-23 21:36:04 -04:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a single output file with custom detection rules
|
|
|
|
|
/// </summary>
|
2024-08-23 21:39:50 -04:00
|
|
|
internal class CustomOutputFile : OutputFile
|
2024-08-23 21:36:04 -04:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Optional func for determining if a file exists
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly Func<string, bool> _existsFunc;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create an OutputFile with a single filename
|
|
|
|
|
/// </summary>
|
|
|
|
|
public CustomOutputFile(string filename, OutputFileFlags flags, Func<string, bool> existsFunc)
|
|
|
|
|
: base([filename], flags)
|
|
|
|
|
{
|
|
|
|
|
_existsFunc = existsFunc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create an OutputFile with a single filename
|
|
|
|
|
/// </summary>
|
|
|
|
|
public CustomOutputFile(string filename, OutputFileFlags flags, string artifactKey, Func<string, bool> existsFunc)
|
|
|
|
|
: base([filename], flags, artifactKey)
|
|
|
|
|
{
|
|
|
|
|
_existsFunc = existsFunc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create an OutputFile with set of filenames
|
|
|
|
|
/// </summary>
|
|
|
|
|
public CustomOutputFile(string[] filenames, OutputFileFlags flags, Func<string, bool> existsFunc)
|
|
|
|
|
: base(filenames, flags)
|
|
|
|
|
{
|
|
|
|
|
_existsFunc = existsFunc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Create an OutputFile with set of filenames
|
|
|
|
|
/// </summary>
|
|
|
|
|
public CustomOutputFile(string[] filenames, OutputFileFlags flags, string artifactKey, Func<string, bool> existsFunc)
|
|
|
|
|
: base(filenames, flags, artifactKey)
|
|
|
|
|
{
|
|
|
|
|
_existsFunc = existsFunc;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-16 01:56:48 -04:00
|
|
|
/// <inheritdoc/>
|
2024-12-29 14:12:04 -05:00
|
|
|
public override bool Exists(string outputDirectory)
|
2024-08-23 21:36:04 -04:00
|
|
|
{
|
2024-10-16 12:04:39 -04:00
|
|
|
// Ensure the directory exists
|
2024-12-29 14:12:04 -05:00
|
|
|
if (!Directory.Exists(outputDirectory))
|
2024-10-16 12:04:39 -04:00
|
|
|
return false;
|
2025-11-11 15:52:26 -05:00
|
|
|
|
2024-08-23 21:36:04 -04:00
|
|
|
foreach (string filename in Filenames)
|
|
|
|
|
{
|
|
|
|
|
// Check for invalid filenames
|
|
|
|
|
if (string.IsNullOrEmpty(filename))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-12-29 14:12:04 -05:00
|
|
|
string possibleFile = Path.Combine(outputDirectory, filename);
|
2024-10-16 11:45:06 -04:00
|
|
|
if (_existsFunc(possibleFile))
|
2024-08-23 21:36:04 -04:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch { }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-07 17:33:01 -04:00
|
|
|
#if NET462_OR_GREATER || NETCOREAPP
|
2024-12-03 15:38:59 -05:00
|
|
|
/// <inheritdoc/>
|
2024-08-23 21:36:04 -04:00
|
|
|
public override bool Exists(ZipArchive? archive)
|
|
|
|
|
{
|
|
|
|
|
// Files aren't extracted so this check can't be done
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-10-11 09:27:55 -04:00
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override bool Extract(ZipArchive? archive, string outputDirectory)
|
|
|
|
|
{
|
|
|
|
|
// Files aren't extracted so this check can't be done
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2024-08-23 21:36:04 -04:00
|
|
|
#endif
|
2024-12-03 15:38:59 -05:00
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
2024-12-29 14:12:04 -05:00
|
|
|
public override List<string> GetPaths(string outputDirectory)
|
2024-12-03 15:38:59 -05:00
|
|
|
{
|
|
|
|
|
List<string> paths = [];
|
|
|
|
|
|
|
|
|
|
foreach (string filename in Filenames)
|
|
|
|
|
{
|
2024-12-29 14:12:04 -05:00
|
|
|
string possibleFile = Path.Combine(outputDirectory, filename);
|
2024-12-03 15:38:59 -05:00
|
|
|
if (!_existsFunc(possibleFile))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
paths.Add(possibleFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return paths;
|
|
|
|
|
}
|
2024-08-23 21:36:04 -04:00
|
|
|
}
|
2025-11-11 15:52:26 -05:00
|
|
|
}
|