diff --git a/SabreTools.Library/External/CHDFile.cs b/SabreTools.Library/External/CHDFile.cs index 4561fb08..5795bf0d 100644 --- a/SabreTools.Library/External/CHDFile.cs +++ b/SabreTools.Library/External/CHDFile.cs @@ -1,15 +1,13 @@ using System; using SabreTools.Library.Data; -using SabreTools.Library.Items; -using SabreTools.Library.Tools; #if MONO using System.IO; #else using BinaryReader = System.IO.BinaryReader; -using FileStream = System.IO.FileStream; using SeekOrigin = System.IO.SeekOrigin; +using Stream = System.IO.Stream; #endif namespace SabreTools.Library.External @@ -89,8 +87,6 @@ namespace SabreTools.Library.External #endregion - #region Instance Methods - #region Constructors /// @@ -313,86 +309,5 @@ namespace SabreTools.Library.External } #endregion - - #endregion // Instance Methods - - #region Static Methods - - #region File Information - - /// - /// Get internal metadata from a CHD - /// - /// Filename of possible CHD - /// A Disk object with internal SHA-1 on success, null on error, empty Disk otherwise - /// - /// Original code had a "writable" param. This is not required for metadata checking - /// - public static DatItem GetCHDInfo(string filename) - { - FileStream fs = FileTools.TryOpenRead(filename); - DatItem datItem = GetCHDInfo(fs); - fs.Dispose(); - return datItem; - } - - /// - /// Get if file is a valid CHD - /// - /// Filename of possible CHD - /// True if a the file is a valid CHD, false otherwise - public static bool IsValidCHD(string filename) - { - DatItem datItem = GetCHDInfo(filename); - return datItem != null - && datItem.Type == ItemType.Disk - && ((Disk)datItem).SHA1 != null; - } - - #endregion - - #region Stream Information - - /// - /// Get internal metadata from a CHD - /// - /// Stream of possible CHD - /// A Disk object with internal SHA-1 on success, null on error, empty Disk otherwise - /// - /// Original code had a "writable" param. This is not required for metadata checking - /// - public static DatItem GetCHDInfo(Stream fs) - { - // Create a blank Disk to populate and return - Disk datItem = new Disk(); - - // Get a CHD object to store the data - CHDFile chd = new CHDFile(fs); - - // Get the SHA-1 from the chd - byte[] sha1 = chd.GetSHA1FromHeader(); - - // Set the SHA-1 of the Disk to return - datItem.SHA1 = (sha1 == null ? null : BitConverter.ToString(sha1).Replace("-", string.Empty).ToLowerInvariant()); - - return datItem; - } - - /// - /// Get if stream is a valid CHD - /// - /// Stream of possible CHD - /// True if a the file is a valid CHD, false otherwise - public static bool IsValidCHD(Stream fs) - { - DatItem datItem = GetCHDInfo(fs); - return datItem != null - && datItem.Type == ItemType.Disk - && ((Disk)datItem).SHA1 != null; - } - - #endregion - - #endregion //Static Methods } } diff --git a/SabreTools.Library/Tools/FileTools.cs b/SabreTools.Library/Tools/FileTools.cs index 1557981d..001b1e50 100644 --- a/SabreTools.Library/Tools/FileTools.cs +++ b/SabreTools.Library/Tools/FileTools.cs @@ -267,6 +267,35 @@ namespace SabreTools.Library.Tools return datItem; } + /// + /// Get internal metadata from a CHD + /// + /// Filename of possible CHD + /// A Disk object with internal SHA-1 on success, null on error, empty Disk otherwise + /// + /// Original code had a "writable" param. This is not required for metadata checking + /// + public static DatItem GetCHDInfo(string input) + { + FileStream fs = FileTools.TryOpenRead(input); + DatItem datItem = GetCHDInfo(fs); + fs.Dispose(); + return datItem; + } + + /// + /// Get if file is a valid CHD + /// + /// Filename of possible CHD + /// True if a the file is a valid CHD, false otherwise + public static bool IsValidCHD(string input) + { + DatItem datItem = GetCHDInfo(input); + return datItem != null + && datItem.Type == ItemType.Disk + && ((Disk)datItem).SHA1 != null; + } + /// /// Retrieve a list of files from a directory recursively in proper order /// @@ -739,7 +768,7 @@ namespace SabreTools.Library.Tools long offset = 0, bool keepReadOpen = false, bool ignorechd = true) { // We first check to see if it's a CHD - if (ignorechd == false && CHDFile.IsValidCHD(input)) + if (ignorechd == false && IsValidCHD(input)) { // Seek to the starting position, if one is set try @@ -763,7 +792,7 @@ namespace SabreTools.Library.Tools } // Get the Disk from the information - DatItem disk = CHDFile.GetCHDInfo(input); + DatItem disk = GetCHDInfo(input); // Seek to the beginning of the stream if possible try @@ -931,6 +960,44 @@ namespace SabreTools.Library.Tools return rom; } + /// + /// Get internal metadata from a CHD + /// + /// Stream of possible CHD + /// A Disk object with internal SHA-1 on success, null on error, empty Disk otherwise + /// + /// Original code had a "writable" param. This is not required for metadata checking + /// + public static DatItem GetCHDInfo(Stream input) + { + // Create a blank Disk to populate and return + Disk datItem = new Disk(); + + // Get a CHD object to store the data + CHDFile chd = new CHDFile(input); + + // Get the SHA-1 from the chd + byte[] sha1 = chd.GetSHA1FromHeader(); + + // Set the SHA-1 of the Disk to return + datItem.SHA1 = (sha1 == null ? null : BitConverter.ToString(sha1).Replace("-", string.Empty).ToLowerInvariant()); + + return datItem; + } + + /// + /// Get if stream is a valid CHD + /// + /// Stream of possible CHD + /// True if a the file is a valid CHD, false otherwise + public static bool IsValidCHD(Stream input) + { + DatItem datItem = GetCHDInfo(input); + return datItem != null + && datItem.Type == ItemType.Disk + && ((Disk)datItem).SHA1 != null; + } + #endregion #region Stream Manipulation