From 01a365033e8a1cacc550332e88d85bf02a8f2040 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Fri, 16 Dec 2022 10:19:32 -0800 Subject: [PATCH] MIgrate some Quantum stuff to models --- BurnOutSharp.Models/MicrosoftCabinet/Enums.cs | 43 ++++++ .../MicrosoftCabinet/Quantum/Archive.cs | 49 ++++++ .../Quantum/FileDescriptor.cs | 36 +++++ .../MicrosoftCabinet/Quantum/Model.cs | 10 ++ .../MicrosoftCabinet/Quantum/ModelSymbol.cs | 10 ++ BurnOutSharp/FileType/MicrosoftCAB.Quantum.cs | 139 +----------------- 6 files changed, 150 insertions(+), 137 deletions(-) create mode 100644 BurnOutSharp.Models/MicrosoftCabinet/Quantum/Archive.cs create mode 100644 BurnOutSharp.Models/MicrosoftCabinet/Quantum/FileDescriptor.cs create mode 100644 BurnOutSharp.Models/MicrosoftCabinet/Quantum/Model.cs create mode 100644 BurnOutSharp.Models/MicrosoftCabinet/Quantum/ModelSymbol.cs diff --git a/BurnOutSharp.Models/MicrosoftCabinet/Enums.cs b/BurnOutSharp.Models/MicrosoftCabinet/Enums.cs index 6deced28..88037a91 100644 --- a/BurnOutSharp.Models/MicrosoftCabinet/Enums.cs +++ b/BurnOutSharp.Models/MicrosoftCabinet/Enums.cs @@ -184,4 +184,47 @@ namespace BurnOutSharp.Models.MicrosoftCabinet /// INVALID_7 = 0b111, } + + public enum QuantumSelectorModel + { + /// + /// Literal model, 64 entries, start at symbol 0 + /// + SELECTOR_0 = 0, + + /// + /// Literal model, 64 entries, start at symbol 64 + /// + SELECTOR_1 = 1, + + /// + /// Literal model, 64 entries, start at symbol 128 + /// + SELECTOR_2 = 2, + + /// + /// Literal model, 64 entries, start at symbol 192 + /// + SELECTOR_3 = 3, + + /// + /// LZ model, 3 character matches, max 24 entries, start at symbol 0 + /// + SELECTOR_4 = 4, + + /// + /// LZ model, 4 character matches, max 36 entries, start at symbol 0 + /// + SELECTOR_5 = 5, + + /// + /// LZ model, 5+ character matches, max 42 entries, start at symbol 0 + /// + SELECTOR_6_POSITION = 6, + + /// + /// LZ model, 5+ character matches, 27 entries, start at symbol 0 + /// + SELECTOR_6_LENGTH = 7, + } } diff --git a/BurnOutSharp.Models/MicrosoftCabinet/Quantum/Archive.cs b/BurnOutSharp.Models/MicrosoftCabinet/Quantum/Archive.cs new file mode 100644 index 00000000..04bf57ab --- /dev/null +++ b/BurnOutSharp.Models/MicrosoftCabinet/Quantum/Archive.cs @@ -0,0 +1,49 @@ +using System.Runtime.InteropServices; + +namespace BurnOutSharp.Models.MicrosoftCabinet.Quantum +{ + /// + /// Quantum archive file structure + /// + /// + [StructLayout(LayoutKind.Sequential)] + public class Archive + { + /// + /// Quantum signature: 0x44 0x53 + /// + public ushort Signature; + + /// + /// Quantum major version number + /// + public byte MajorVersion; + + /// + /// Quantum minor version number + /// + public byte MinorVersion; + + /// + /// Number of files within this archive + /// + public ushort FileCount; + + /// + /// Table size required for decompression + /// + public byte TableSize; + + /// + /// Compression flags + /// + public byte CompressionFlags; + + /// + /// This is immediately followed by the list of files + /// + public FileDescriptor[] FileList; + + // Immediately following the list of files is the compressed data. + } +} \ No newline at end of file diff --git a/BurnOutSharp.Models/MicrosoftCabinet/Quantum/FileDescriptor.cs b/BurnOutSharp.Models/MicrosoftCabinet/Quantum/FileDescriptor.cs new file mode 100644 index 00000000..b3c707aa --- /dev/null +++ b/BurnOutSharp.Models/MicrosoftCabinet/Quantum/FileDescriptor.cs @@ -0,0 +1,36 @@ +namespace BurnOutSharp.Models.MicrosoftCabinet.Quantum +{ + /// + /// Strings are prefixed with their length. If the length is less than + /// 128 then it is stored directly in one byte. If it is greater than 127 + /// then the high bit of the first byte is set to 1 and the remaining + /// fifteen bits contain the actual length in big-endian format. + /// + public class FileDescriptor + { + /// + /// File name, variable length string, not zero-terminated + /// + public string FileName; + + /// + /// Comment field, variable length string, not zero-terminated + /// + public string CommentField; + + /// + /// Fully expanded file size in bytes + /// + public uint ExpandedFileSize; + + /// + /// File time (DOS format) + /// + public ushort FileTime; + + /// + /// File date (DOS format) + /// + public ushort FileDate; + } +} \ No newline at end of file diff --git a/BurnOutSharp.Models/MicrosoftCabinet/Quantum/Model.cs b/BurnOutSharp.Models/MicrosoftCabinet/Quantum/Model.cs new file mode 100644 index 00000000..dea8adf8 --- /dev/null +++ b/BurnOutSharp.Models/MicrosoftCabinet/Quantum/Model.cs @@ -0,0 +1,10 @@ +namespace BurnOutSharp.Models.MicrosoftCabinet.Quantum +{ + /// + public class Model + { + public int Entries { get; set; } + + public ModelSymbol[] Symbols { get; set; } + } +} \ No newline at end of file diff --git a/BurnOutSharp.Models/MicrosoftCabinet/Quantum/ModelSymbol.cs b/BurnOutSharp.Models/MicrosoftCabinet/Quantum/ModelSymbol.cs new file mode 100644 index 00000000..00000416 --- /dev/null +++ b/BurnOutSharp.Models/MicrosoftCabinet/Quantum/ModelSymbol.cs @@ -0,0 +1,10 @@ +namespace BurnOutSharp.Models.MicrosoftCabinet.Quantum +{ + /// + public class ModelSymbol + { + public ushort Symbol { get; private set; } + + public ushort CumulativeFrequency { get; private set; } + } +} \ No newline at end of file diff --git a/BurnOutSharp/FileType/MicrosoftCAB.Quantum.cs b/BurnOutSharp/FileType/MicrosoftCAB.Quantum.cs index 19db2e12..fa7f2971 100644 --- a/BurnOutSharp/FileType/MicrosoftCAB.Quantum.cs +++ b/BurnOutSharp/FileType/MicrosoftCAB.Quantum.cs @@ -1,4 +1,4 @@ -using System.Runtime.InteropServices; +using BurnOutSharp.Models.MicrosoftCabinet.Quantum; /// /// @@ -8,49 +8,6 @@ /// namespace BurnOutSharp.FileType { - internal enum SelectorModel - { - /// - /// Literal model, 64 entries, start at symbol 0 - /// - SELECTOR_0 = 0, - - /// - /// Literal model, 64 entries, start at symbol 64 - /// - SELECTOR_1 = 1, - - /// - /// Literal model, 64 entries, start at symbol 128 - /// - SELECTOR_2 = 2, - - /// - /// Literal model, 64 entries, start at symbol 192 - /// - SELECTOR_3 = 3, - - /// - /// LZ model, 3 character matches, max 24 entries, start at symbol 0 - /// - SELECTOR_4 = 4, - - /// - /// LZ model, 4 character matches, max 36 entries, start at symbol 0 - /// - SELECTOR_5 = 5, - - /// - /// LZ model, 5+ character matches, max 42 entries, start at symbol 0 - /// - SELECTOR_6_POSITION = 6, - - /// - /// LZ model, 5+ character matches, 27 entries, start at symbol 0 - /// - SELECTOR_6_LENGTH = 7, - } - #region LZ Compression Tables public static class QuantumConstants @@ -118,84 +75,6 @@ namespace BurnOutSharp.FileType #endregion - /// - /// Quantum archive file structure - /// - [StructLayout(LayoutKind.Sequential)] - public class QuantumArchive - { - /// - /// Quantum signature: 0x44 0x53 - /// - public ushort Signature; - - /// - /// Quantum major version number - /// - public byte MajorVersion; - - /// - /// Quantum minor version number - /// - public byte MinorVersion; - - /// - /// Number of files within this archive - /// - public ushort FileCount; - - /// - /// Table size required for decompression - /// - public byte TableSize; - - /// - /// Compression flags - /// - public byte CompressionFlags; - - /// - /// This is immediately followed by the list of files - /// - public QuantumFileDescriptor[] FileList; - - // Immediately following the list of files is the compressed data. - } - - /// - /// Strings are prefixed with their length. If the length is less than - /// 128 then it is stored directly in one byte. If it is greater than 127 - /// then the high bit of the first byte is set to 1 and the remaining - /// fifteen bits contain the actual length in big-endian format. - /// - public class QuantumFileDescriptor - { - /// - /// File name, variable length string, not zero-terminated - /// - public string FileName; - - /// - /// Comment field, variable length string, not zero-terminated - /// - public string CommentField; - - /// - /// Fully expanded file size in bytes - /// - public uint ExpandedFileSize; - - /// - /// File time (DOS format) - /// - public ushort FileTime; - - /// - /// File date (DOS format) - /// - public ushort FileDate; - } - public static class QuantumCompressor { // TODO: Determine how these values are set @@ -248,7 +127,7 @@ namespace BurnOutSharp.FileType return 0; } - public static int GetSymbol(QuantumModel model) + public static int GetSymbol(Model model) { int freq = GetFrequency(model.Symbols[0].CumulativeFrequency); @@ -269,18 +148,4 @@ namespace BurnOutSharp.FileType return sym; } } - - public class QuantumModelSymbol - { - public ushort Symbol { get; private set; } - - public ushort CumulativeFrequency { get; private set; } - } - - public class QuantumModel - { - public int Entries { get; set; } - - public QuantumModelSymbol[] Symbols { get; set; } - } }