mirror of
https://github.com/SabreTools/MPF.git
synced 2026-07-02 17:24:48 +00:00
Make helper class more robust
This commit is contained in:
@@ -32,6 +32,7 @@
|
||||
- Remove redundant drive calls
|
||||
- Start preparing for better output file checks
|
||||
- Create currently-unused helper class
|
||||
- Make helper class more robust
|
||||
|
||||
### 3.2.1 (2024-08-05)
|
||||
|
||||
|
||||
@@ -1,9 +1,49 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace MPF.Processors
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents attributes about an <see cref="OutputFile"/>
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum OutputFileFlags : ushort
|
||||
{
|
||||
/// <summary>
|
||||
/// Default state
|
||||
/// </summary>
|
||||
None = 0x0000,
|
||||
|
||||
/// <summary>
|
||||
/// File is required to exist
|
||||
/// </summary>
|
||||
Required = 0x0001,
|
||||
|
||||
/// <summary>
|
||||
/// File is included as an artifact
|
||||
/// </summary>
|
||||
Artifact = 0x0002,
|
||||
|
||||
/// <summary>
|
||||
/// File is included as a binary artifact
|
||||
/// </summary>
|
||||
Binary = 0x0004,
|
||||
|
||||
/// <summary>
|
||||
/// File can be deleted after processing
|
||||
/// </summary>
|
||||
Deleteable = 0x0008,
|
||||
|
||||
/// <summary>
|
||||
/// File can be zipped after processing
|
||||
/// </summary>
|
||||
Zippable = 0x0010,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents a single output file
|
||||
/// </summary>
|
||||
internal class OutputFile
|
||||
public class OutputFile
|
||||
{
|
||||
/// <summary>
|
||||
/// Set of all filename variants
|
||||
@@ -11,32 +51,127 @@ namespace MPF.Processors
|
||||
public string[] Filenames { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the file is a required output
|
||||
/// Indicates if the file is required
|
||||
/// </summary>
|
||||
public bool Required { get; private set; }
|
||||
public bool IsRequired
|
||||
{
|
||||
get
|
||||
{
|
||||
#if NET20 || NET35
|
||||
return (_flags & OutputFileFlags.Required) != 0;
|
||||
#else
|
||||
return _flags.HasFlag(OutputFileFlags.Required);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the file should be included as an artifact
|
||||
/// Indicates if the file is an artifact
|
||||
/// </summary>
|
||||
public bool IsArtifact { get; private set; }
|
||||
public bool IsArtifact
|
||||
{
|
||||
get
|
||||
{
|
||||
#if NET20 || NET35
|
||||
return (_flags & OutputFileFlags.Artifact) != 0
|
||||
|| (_flags & OutputFileFlags.Binary) != 0;
|
||||
#else
|
||||
return _flags.HasFlag(OutputFileFlags.Artifact)
|
||||
|| _flags.HasFlag(OutputFileFlags.Binary);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the file can be deleted after processing is finished
|
||||
/// Indicates if the file is a binary artifact
|
||||
/// </summary>
|
||||
public bool IsDeleteable { get; private set; }
|
||||
public bool IsBinaryArtifact
|
||||
{
|
||||
get
|
||||
{
|
||||
#if NET20 || NET35
|
||||
return (_flags & OutputFileFlags.Binary) != 0;
|
||||
#else
|
||||
return _flags.HasFlag(OutputFileFlags.Binary);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if the file can be zipped after processing is finished
|
||||
/// Indicates if the file is deleteable after processing
|
||||
/// </summary>
|
||||
public bool IsZippable { get; private set; }
|
||||
public bool IsDeleteable
|
||||
{
|
||||
get
|
||||
{
|
||||
#if NET20 || NET35
|
||||
return (_flags & OutputFileFlags.Deleteable) != 0;
|
||||
#else
|
||||
return _flags.HasFlag(OutputFileFlags.Deleteable);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public OutputFile(string filename, bool required, bool isArtifact, bool isDeleteable, bool isZippable)
|
||||
/// <summary>
|
||||
/// Indicates if the file is zippable after processing
|
||||
/// </summary>
|
||||
public bool IsZippable
|
||||
{
|
||||
get
|
||||
{
|
||||
#if NET20 || NET35
|
||||
return (_flags & OutputFileFlags.Zippable) != 0;
|
||||
#else
|
||||
return _flags.HasFlag(OutputFileFlags.Zippable);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents attributes about the current file
|
||||
/// </summary>
|
||||
private readonly OutputFileFlags _flags;
|
||||
|
||||
/// <summary>
|
||||
/// Create an OutputFile with a single filename
|
||||
/// </summary>
|
||||
public OutputFile(string filename, OutputFileFlags flags)
|
||||
{
|
||||
Filenames = [filename];
|
||||
Required = required;
|
||||
IsArtifact = isArtifact;
|
||||
IsDeleteable = IsDeleteable;
|
||||
IsZippable = IsZippable;
|
||||
_flags = flags;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create an OutputFile with set of filenames
|
||||
/// </summary>
|
||||
public OutputFile(string[] filenames, OutputFileFlags flags)
|
||||
{
|
||||
Filenames = filenames;
|
||||
_flags = flags;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates if an output file exists in a base directory
|
||||
/// </summary>
|
||||
/// <param name="baseDirectory">Base directory to check in</param>
|
||||
public 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 (File.Exists(possiblePath))
|
||||
return true;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user