-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e1777a
commit a35c13b
Showing
5 changed files
with
112 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.IO; | ||
#if NET452_OR_GREATER || NETCOREAPP | ||
using System.IO.Compression; | ||
#endif | ||
using System.Linq; | ||
|
||
namespace MPF.Processors | ||
{ | ||
/// <summary> | ||
/// Represents a single output file with custom detection rules | ||
/// </summary> | ||
public class CustomOutputFile : OutputFile | ||
{ | ||
/// <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; | ||
} | ||
|
||
/// <summary> | ||
/// Indicates if an output file exists in a base directory | ||
/// </summary> | ||
/// <param name="baseDirectory">Base directory to check in</param> | ||
public override bool Exists(string baseDirectory) | ||
{ | ||
foreach (string filename in Filenames) | ||
{ | ||
// Check for invalid filenames | ||
if (string.IsNullOrEmpty(filename)) | ||
continue; | ||
|
||
try | ||
{ | ||
string possiblePath = Path.Combine(baseDirectory, filename); | ||
if (_existsFunc(possiblePath)) | ||
return true; | ||
} | ||
catch { } | ||
} | ||
|
||
return false; | ||
} | ||
|
||
#if NET452_OR_GREATER || NETCOREAPP | ||
/// <summary> | ||
/// Indicates if an output file exists in an archive | ||
/// </summary> | ||
/// <param name="archive">Zip archive to check in</param> | ||
public override bool Exists(ZipArchive? archive) | ||
{ | ||
// Files aren't extracted so this check can't be done | ||
return false; | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters