Ensure consistency in output file path checking (fixes #755)

This commit is contained in:
Matt Nadareski
2024-10-16 01:56:48 -04:00
parent 8a44fa3355
commit e1122fa976
4 changed files with 9 additions and 29 deletions

View File

@@ -15,6 +15,7 @@
- Fix trimming of header output
- Use fake filename for Redumper DAT
- Ensure that the full base path is being used
- Ensure consistency in output file path checking
### 3.2.2 (2024-09-24)

View File

@@ -52,18 +52,9 @@ namespace MPF.Processors
_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)
/// <inheritdoc/>
public override bool Exists()
{
// If the base directory is invalid
if (string.IsNullOrEmpty(baseDirectory))
return false;
if (!Directory.Exists(baseDirectory))
return false;
foreach (string filename in Filenames)
{
// Check for invalid filenames
@@ -72,8 +63,7 @@ namespace MPF.Processors
try
{
string possiblePath = Path.Combine(baseDirectory, filename);
if (_existsFunc(possiblePath))
if (_existsFunc(filename))
return true;
}
catch { }

View File

@@ -192,15 +192,8 @@ namespace MPF.Processors
/// <summary>
/// Indicates if an output file exists in a base directory
/// </summary>
/// <param name="baseDirectory">Base directory to check in</param>
public virtual bool Exists(string baseDirectory)
public virtual bool Exists()
{
// If the base directory is invalid
if (string.IsNullOrEmpty(baseDirectory))
return false;
if (!Directory.Exists(baseDirectory))
return false;
foreach (string filename in Filenames)
{
// Check for invalid filenames
@@ -209,8 +202,7 @@ namespace MPF.Processors
try
{
string possiblePath = Path.Combine(baseDirectory, filename);
if (File.Exists(possiblePath))
if (File.Exists(filename))
return true;
}
catch { }

View File

@@ -45,13 +45,10 @@ namespace MPF.Processors
}
/// <inheritdoc/>
public override bool Exists(string baseDirectory)
public override bool Exists()
{
// If the base directory is invalid
if (string.IsNullOrEmpty(baseDirectory))
return false;
if (!Directory.Exists(baseDirectory))
return false;
// Get the base directory for the first path
string baseDirectory = Path.GetDirectoryName(Filenames[0]) ?? string.Empty;
// Get list of all files in directory
var directoryFiles = Directory.GetFiles(baseDirectory);