Add safety to GetInfo methods

This commit is contained in:
Matt Nadareski
2025-01-04 23:26:06 -05:00
parent 690693c1ad
commit d726b4195f

View File

@@ -47,6 +47,8 @@ namespace SabreTools.FileTypes
if (!File.Exists(input)) if (!File.Exists(input))
return new BaseFile(); return new BaseFile();
try
{
// Get input information // Get input information
var fileType = GetFileType(input); var fileType = GetFileType(input);
Stream inputStream = GetInfoStream(input, header); Stream inputStream = GetInfoStream(input, header);
@@ -76,6 +78,13 @@ namespace SabreTools.FileTypes
return baseFile; return baseFile;
} }
catch
{
// Exceptions are currently not logged
// TODO: Log exceptions
return new BaseFile();
}
}
/// <summary> /// <summary>
/// Retrieve file information for a single stream /// Retrieve file information for a single stream
@@ -120,6 +129,8 @@ namespace SabreTools.FileTypes
if (input == null) if (input == null)
return new BaseFile(); return new BaseFile();
try
{
// If we want to automatically set the size // If we want to automatically set the size
if (size == -1) if (size == -1)
size = input.Length; size = input.Length;
@@ -155,6 +166,13 @@ namespace SabreTools.FileTypes
return baseFile; return baseFile;
} }
catch
{
// Exceptions are currently not logged
// TODO: Log exceptions
return new BaseFile();
}
}
/// <summary> /// <summary>
/// Get the required stream for info hashing /// Get the required stream for info hashing