[Utilities] Add checking CHD header only

This commit is contained in:
Matt Nadareski
2017-12-15 14:53:20 -08:00
parent 06ecbe3cda
commit a137b9d9d1

View File

@@ -1217,11 +1217,24 @@ namespace SabreTools.Library.Tools
} }
} }
/// <summary>
/// Get if file has a known CHD header
/// </summary>
/// <param name="input">Filename of possible CHD</param>
/// <returns>True if the file has a valid CHD header, false otherwise</returns>
public static bool HasCHDHeader(string input)
{
FileStream fs = TryOpenRead(input);
bool output = HasCHDHeader(fs);
fs.Dispose();
return output;
}
/// <summary> /// <summary>
/// Get if file is a valid CHD /// Get if file is a valid CHD
/// </summary> /// </summary>
/// <param name="input">Filename of possible CHD</param> /// <param name="input">Filename of possible CHD</param>
/// <returns>True if a the file is a valid CHD, false otherwise</returns> /// <returns>True if the file is a valid CHD, false otherwise</returns>
public static bool IsValidCHD(string input) public static bool IsValidCHD(string input)
{ {
DatItem datItem = GetCHDInfo(input); DatItem datItem = GetCHDInfo(input);
@@ -1703,7 +1716,7 @@ namespace SabreTools.Library.Tools
long offset = 0, bool keepReadOpen = false, bool chdsAsFiles = true) long offset = 0, bool keepReadOpen = false, bool chdsAsFiles = true)
{ {
// We first check to see if it's a CHD // We first check to see if it's a CHD
if (chdsAsFiles == false && IsValidCHD(input)) if (chdsAsFiles == false && HasCHDHeader(input))
{ {
// Seek to the starting position, if one is set // Seek to the starting position, if one is set
try try
@@ -1930,11 +1943,27 @@ namespace SabreTools.Library.Tools
return datItem; return datItem;
} }
/// <summary>
/// Get if stream has a known CHD header
/// </summary>
/// <param name="input">Stream of possible CHD</param>
/// <returns>True if the stream has a valid CHD header, false otherwise</returns>
public static bool HasCHDHeader(Stream input)
{
// Get a CHD object to store the data
CHDFile chd = new CHDFile(input);
// Now try to get the header version
uint? version = chd.ValidateHeaderVersion();
return version != null;
}
/// <summary> /// <summary>
/// Get if stream is a valid CHD /// Get if stream is a valid CHD
/// </summary> /// </summary>
/// <param name="input">Stream of possible CHD</param> /// <param name="input">Stream of possible CHD</param>
/// <returns>True if a the file is a valid CHD, false otherwise</returns> /// <returns>True if the stream is a valid CHD, false otherwise</returns>
public static bool IsValidCHD(Stream input) public static bool IsValidCHD(Stream input)
{ {
DatItem datItem = GetCHDInfo(input); DatItem datItem = GetCHDInfo(input);
@@ -2347,7 +2376,7 @@ namespace SabreTools.Library.Tools
} }
/// <summary> /// <summary>
/// Get if the given path has a valid archive extension /// Get if the given path has a valid DAT extension
/// </summary> /// </summary>
/// <param name="path">Path to check</param> /// <param name="path">Path to check</param>
/// <returns>True if the extension is valid, false otherwise</returns> /// <returns>True if the extension is valid, false otherwise</returns>