diff --git a/SabreTools.Library/DatFiles/DatHeader.cs b/SabreTools.Library/DatFiles/DatHeader.cs index 101256dc..82bd412b 100644 --- a/SabreTools.Library/DatFiles/DatHeader.cs +++ b/SabreTools.Library/DatFiles/DatHeader.cs @@ -4,6 +4,7 @@ using System.IO; using SabreTools.Library.Data; using Newtonsoft.Json; +using SabreTools.Library.Tools; namespace SabreTools.Library.DatFiles { @@ -770,7 +771,11 @@ namespace SabreTools.Library.DatFiles private string CreateOutFileNamesHelper(string outDir, string extension, bool overwrite) { string filename = (string.IsNullOrWhiteSpace(FileName) ? Description : FileName); - filename = Path.GetFileNameWithoutExtension(filename); + + // Strip off the extension if it's a holdover from the DAT + if (PathExtensions.HasValidDatExtension(filename)) + filename = Path.GetFileNameWithoutExtension(filename); + string outfile = $"{outDir}{filename}{extension}"; outfile = outfile.Replace($"{Path.DirectorySeparatorChar}{Path.DirectorySeparatorChar}", Path.DirectorySeparatorChar.ToString()); diff --git a/SabreTools.Library/Data/Constants.cs b/SabreTools.Library/Data/Constants.cs index d0dfd69a..abc53732 100644 --- a/SabreTools.Library/Data/Constants.cs +++ b/SabreTools.Library/Data/Constants.cs @@ -12,7 +12,7 @@ namespace SabreTools.Library.Data /// /// The current toolset version to be used by all child applications /// - public readonly static string Version = $"v1.0.0-{File.GetCreationTime(Assembly.GetExecutingAssembly().Location):yyyy-MM-dd HH:mm:ss}"; + public readonly static string Version = $"v1.0.1-{File.GetCreationTime(Assembly.GetExecutingAssembly().Location):yyyy-MM-dd HH:mm:ss}"; public const int HeaderHeight = 3; #region 0-byte file constants diff --git a/SabreTools.Library/Data/Globals.cs b/SabreTools.Library/Data/Globals.cs index 21ade87a..3cde4908 100644 --- a/SabreTools.Library/Data/Globals.cs +++ b/SabreTools.Library/Data/Globals.cs @@ -15,7 +15,6 @@ namespace SabreTools.Library.Data #region Private implementations private static Logger _logger = null; - private static int _maxDegreeOfParallelism = System.Environment.ProcessorCount; #endregion @@ -33,37 +32,18 @@ namespace SabreTools.Library.Data set { _logger = value; } } - public static int MaxThreads - { - get { return _maxDegreeOfParallelism; } - set { _maxDegreeOfParallelism = value; } - } + public static int MaxThreads { get; set; } = Environment.ProcessorCount; - public static ParallelOptions ParallelOptions + public static ParallelOptions ParallelOptions => new ParallelOptions() { - get - { - return new ParallelOptions() - { - MaxDegreeOfParallelism = _maxDegreeOfParallelism - }; - } - } + MaxDegreeOfParallelism = MaxThreads + }; - public static string ExeName - { - get { return new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath; } - } + public static string ExeName => new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath; - public static string ExeDir - { - get { return Path.GetDirectoryName(ExeName); } - } + public static string ExeDir => Path.GetDirectoryName(ExeName); - public static string CommandLineArgs - { - get { return string.Join(" ", Environment.GetCommandLineArgs()); } - } + public static string CommandLineArgs => string.Join(" ", Environment.GetCommandLineArgs()); #endregion } diff --git a/SabreTools.Library/FileTypes/CHDFile.cs b/SabreTools.Library/FileTypes/CHDFile.cs index a9ce5b14..c57c14a8 100644 --- a/SabreTools.Library/FileTypes/CHDFile.cs +++ b/SabreTools.Library/FileTypes/CHDFile.cs @@ -42,21 +42,28 @@ namespace SabreTools.Library.FileTypes /// Stream representing the CHD file public static CHDFile Create(Stream chdstream) { - // Read the standard CHD headers - (char[] tag, uint length, uint version) = GetHeaderValues(chdstream); - chdstream.Seek(-16, SeekOrigin.Current); // Seek back to start + try + { + // Read the standard CHD headers + (char[] tag, uint length, uint version) = GetHeaderValues(chdstream); + chdstream.Seek(-16, SeekOrigin.Current); // Seek back to start - // Validate that this is actually a valid CHD - uint validatedVersion = ValidateHeader(tag, length, version); - if (validatedVersion == 0) + // Validate that this is actually a valid CHD + uint validatedVersion = ValidateHeader(tag, length, version); + if (validatedVersion == 0) + return null; + + // Read and retrun the current CHD + CHDFile generated = ReadAsVersion(chdstream, version); + if (generated != null) + generated.Type = FileType.CHD; + + return generated; + } + catch + { return null; - - // Read and retrun the current CHD - CHDFile generated = ReadAsVersion(chdstream, version); - if (generated != null) - generated.Type = FileType.CHD; - - return generated; + } } #endregion @@ -85,7 +92,7 @@ namespace SabreTools.Library.FileTypes using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) { - parsedTag = br.ReadCharsBigEndian(8); + parsedTag = br.ReadChars(8); parsedLength = br.ReadUInt32BigEndian(); parsedVersion = br.ReadUInt32BigEndian(); } diff --git a/SabreTools.Library/FileTypes/CHDFileV1.cs b/SabreTools.Library/FileTypes/CHDFileV1.cs index a0d74d31..6a689975 100644 --- a/SabreTools.Library/FileTypes/CHDFileV1.cs +++ b/SabreTools.Library/FileTypes/CHDFileV1.cs @@ -62,7 +62,7 @@ namespace SabreTools.Library.FileTypes using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) { - chd.tag = br.ReadCharsBigEndian(8); + chd.tag = br.ReadChars(8); chd.length = br.ReadUInt32BigEndian(); chd.version = br.ReadUInt32BigEndian(); chd.flags = (Flags)br.ReadUInt32BigEndian(); @@ -72,8 +72,10 @@ namespace SabreTools.Library.FileTypes chd.cylinders = br.ReadUInt32BigEndian(); chd.heads = br.ReadUInt32BigEndian(); chd.sectors = br.ReadUInt32BigEndian(); - chd.md5 = br.ReadBytesBigEndian(16); - chd.parentmd5 = br.ReadBytesBigEndian(16); + chd.md5 = br.ReadBytes(16); + chd.parentmd5 = br.ReadBytes(16); + + chd.MD5 = chd.md5; } return chd; diff --git a/SabreTools.Library/FileTypes/CHDFileV2.cs b/SabreTools.Library/FileTypes/CHDFileV2.cs index da79752a..eabedd4a 100644 --- a/SabreTools.Library/FileTypes/CHDFileV2.cs +++ b/SabreTools.Library/FileTypes/CHDFileV2.cs @@ -63,7 +63,7 @@ namespace SabreTools.Library.FileTypes using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) { - chd.tag = br.ReadCharsBigEndian(8); + chd.tag = br.ReadChars(8); chd.length = br.ReadUInt32BigEndian(); chd.version = br.ReadUInt32BigEndian(); chd.flags = (Flags)br.ReadUInt32BigEndian(); @@ -73,9 +73,11 @@ namespace SabreTools.Library.FileTypes chd.cylinders = br.ReadUInt32BigEndian(); chd.heads = br.ReadUInt32BigEndian(); chd.sectors = br.ReadUInt32BigEndian(); - chd.md5 = br.ReadBytesBigEndian(16); - chd.parentmd5 = br.ReadBytesBigEndian(16); + chd.md5 = br.ReadBytes(16); + chd.parentmd5 = br.ReadBytes(16); chd.seclen = br.ReadUInt32BigEndian(); + + chd.MD5 = chd.md5; } return chd; diff --git a/SabreTools.Library/FileTypes/CHDFileV3.cs b/SabreTools.Library/FileTypes/CHDFileV3.cs index 840be663..9b7600a5 100644 --- a/SabreTools.Library/FileTypes/CHDFileV3.cs +++ b/SabreTools.Library/FileTypes/CHDFileV3.cs @@ -67,7 +67,7 @@ namespace SabreTools.Library.FileTypes using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) { - chd.tag = br.ReadCharsBigEndian(8); + chd.tag = br.ReadChars(8); chd.length = br.ReadUInt32BigEndian(); chd.version = br.ReadUInt32BigEndian(); chd.flags = (Flags)br.ReadUInt32BigEndian(); @@ -75,11 +75,14 @@ namespace SabreTools.Library.FileTypes chd.totalhunks = br.ReadUInt32BigEndian(); chd.logicalbytes = br.ReadUInt64BigEndian(); chd.metaoffset = br.ReadUInt64BigEndian(); - chd.md5 = br.ReadBytesBigEndian(16); - chd.parentmd5 = br.ReadBytesBigEndian(16); + chd.md5 = br.ReadBytes(16); + chd.parentmd5 = br.ReadBytes(16); chd.hunkbytes = br.ReadUInt32BigEndian(); - chd.sha1 = br.ReadBytesBigEndian(20); - chd.parentsha1 = br.ReadBytesBigEndian(20); + chd.sha1 = br.ReadBytes(20); + chd.parentsha1 = br.ReadBytes(20); + + chd.MD5 = chd.md5; + chd.SHA1 = chd.sha1; } return chd; diff --git a/SabreTools.Library/FileTypes/CHDFileV4.cs b/SabreTools.Library/FileTypes/CHDFileV4.cs index 3ecc8f5f..9f210897 100644 --- a/SabreTools.Library/FileTypes/CHDFileV4.cs +++ b/SabreTools.Library/FileTypes/CHDFileV4.cs @@ -67,7 +67,7 @@ namespace SabreTools.Library.FileTypes using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) { - chd.tag = br.ReadCharsBigEndian(8); + chd.tag = br.ReadChars(8); chd.length = br.ReadUInt32BigEndian(); chd.version = br.ReadUInt32BigEndian(); chd.flags = (Flags)br.ReadUInt32BigEndian(); @@ -76,9 +76,11 @@ namespace SabreTools.Library.FileTypes chd.logicalbytes = br.ReadUInt64BigEndian(); chd.metaoffset = br.ReadUInt64BigEndian(); chd.hunkbytes = br.ReadUInt32BigEndian(); - chd.sha1 = br.ReadBytesBigEndian(20); - chd.parentsha1 = br.ReadBytesBigEndian(20); - chd.rawsha1 = br.ReadBytesBigEndian(20); + chd.sha1 = br.ReadBytes(20); + chd.parentsha1 = br.ReadBytes(20); + chd.rawsha1 = br.ReadBytes(20); + + chd.SHA1 = chd.sha1; } return chd; diff --git a/SabreTools.Library/FileTypes/CHDFileV5.cs b/SabreTools.Library/FileTypes/CHDFileV5.cs index bcbd2388..5e5b7a9d 100644 --- a/SabreTools.Library/FileTypes/CHDFileV5.cs +++ b/SabreTools.Library/FileTypes/CHDFileV5.cs @@ -66,7 +66,7 @@ namespace SabreTools.Library.FileTypes using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true)) { - chd.tag = br.ReadCharsBigEndian(8); + chd.tag = br.ReadChars(8); chd.length = br.ReadUInt32BigEndian(); chd.version = br.ReadUInt32BigEndian(); chd.compressors = new uint[4]; @@ -79,9 +79,11 @@ namespace SabreTools.Library.FileTypes chd.metaoffset = br.ReadUInt64BigEndian(); chd.hunkbytes = br.ReadUInt32BigEndian(); chd.unitbytes = br.ReadUInt32BigEndian(); - chd.rawsha1 = br.ReadBytesBigEndian(20); - chd.sha1 = br.ReadBytesBigEndian(20); - chd.parentsha1 = br.ReadBytesBigEndian(20); + chd.rawsha1 = br.ReadBytes(20); + chd.sha1 = br.ReadBytes(20); + chd.parentsha1 = br.ReadBytes(20); + + chd.SHA1 = chd.sha1; } return chd; diff --git a/SabreTools/SabreTools.Help.cs b/SabreTools/SabreTools.Help.cs index 9582d7ae..1b856f05 100644 --- a/SabreTools/SabreTools.Help.cs +++ b/SabreTools/SabreTools.Help.cs @@ -2939,6 +2939,10 @@ Some special strings that can be used: public override void ProcessFeatures(Dictionary features) { + // Set threading flag, if necessary + if (features.ContainsKey(ThreadsInt32Value)) + Globals.MaxThreads = GetInt32(features, ThreadsInt32Value); + // Get feature flags bool addBlankFiles = GetBoolean(features, AddBlankFilesValue); bool addFileDates = GetBoolean(features, AddDateValue); @@ -3168,6 +3172,10 @@ The following systems have headers that this program can work with: public override void ProcessFeatures(Dictionary features) { + // Set threading flag, if necessary + if (features.ContainsKey(ThreadsInt32Value)) + Globals.MaxThreads = GetInt32(features, ThreadsInt32Value); + // Get feature flags bool chdsAsFiles = GetBoolean(features, ChdsAsFilesValue); bool date = GetBoolean(features, AddDateValue); @@ -3466,6 +3474,10 @@ The stats that are outputted are as follows: public override void ProcessFeatures(Dictionary features) { + // Set threading flag, if necessary + if (features.ContainsKey(ThreadsInt32Value)) + Globals.MaxThreads = GetInt32(features, ThreadsInt32Value); + // Get feature flags var datHeader = GetDatHeader(features); var updateFields = GetUpdateFields(features);