Continue demacroization (nw)

This commit is contained in:
Matt Nadareski
2022-05-20 23:33:57 -07:00
parent f34b1ba5cf
commit cd38407e4e
11 changed files with 926 additions and 631 deletions

View File

@@ -36,7 +36,7 @@ namespace LibMSPackSharp.Compression
/// </summary>
public FileStream Output { get; set; }
public Error Error { get; set; }
public LibMSPackSharp.Error Error { get; set; }
#region I/O buffering
@@ -63,6 +63,7 @@ namespace LibMSPackSharp.Compression
#endregion
// TODO: These should be in a separate file
#region ReadBits Methods
/* This header defines macros that read data streams by
@@ -167,11 +168,11 @@ namespace LibMSPackSharp.Compression
bits_left -= (nbits);
}
public Error ReadInput()
public LibMSPackSharp.Error ReadInput()
{
int read = Sys.Read(Input, InputBuffer, 0, (int)InputBufferSize);
if (read < 0)
return Error = Error.MSPACK_ERR_READ;
return Error = LibMSPackSharp.Error.MSPACK_ERR_READ;
// We might overrun the input stream by asking for bits we don't use,
// so fake 2 more bytes at the end of input
@@ -180,7 +181,7 @@ namespace LibMSPackSharp.Compression
if (InputEnd != 0)
{
Console.WriteLine("out of input bytes");
return Error = Error.MSPACK_ERR_READ;
return Error = LibMSPackSharp.Error.MSPACK_ERR_READ;
}
else
{
@@ -193,11 +194,12 @@ namespace LibMSPackSharp.Compression
// Update i_ptr and i_end
InputPointer = 0;
InputLength = read;
return Error = Error.MSPACK_ERR_OK;
return Error = LibMSPackSharp.Error.MSPACK_ERR_OK;
}
#endregion
// TODO: These should be in a separate file
#region ReadHuff Methods
private const int HUFF_MAXBITS = 16;
@@ -214,7 +216,7 @@ namespace LibMSPackSharp.Compression
READ_BYTES;
}
if (Error != Error.MSPACK_ERR_OK)
if (Error != LibMSPackSharp.Error.MSPACK_ERR_OK)
return (int)Error;
int peek;
@@ -246,7 +248,7 @@ namespace LibMSPackSharp.Compression
bits_left -= i;
}
return (int)Error.MSPACK_ERR_OK;
return (int)LibMSPackSharp.Error.MSPACK_ERR_OK;
}
public int HUFF_TRAVERSE(ushort[] decodingTable, int tablebits, int maxsymbols, ref int i, ref ushort sym, uint bit_buffer, bool msb)
@@ -274,7 +276,7 @@ namespace LibMSPackSharp.Compression
} while (sym >= maxsymbols);
}
return (int)Error.MSPACK_ERR_OK;
return (int)LibMSPackSharp.Error.MSPACK_ERR_OK;
}
public abstract int HUFF_ERROR();

View File

@@ -9,81 +9,6 @@
namespace LibMSPackSharp.Compression
{
public enum InflateErrorCode
{
INF_ERR_OK = 0,
/// <summary>
/// Unknown block type
/// </summary>
INF_ERR_BLOCKTYPE = -1,
/// <summary>
/// Block size complement mismatch
/// </summary>
INF_ERR_COMPLEMENT = -2,
/// <summary>
/// Error from flush_window callback
/// </summary>
INF_ERR_FLUSH = -3,
/// <summary>
/// Too many bits in bit buffer
/// </summary>
INF_ERR_BITBUF = -4,
/// <summary>
/// Too many symbols in blocktype 2 header
/// </summary>
INF_ERR_SYMLENS = -5,
/// <summary>
/// Failed to build bitlens huffman table
/// </summary>
INF_ERR_BITLENTBL = -6,
/// <summary>
/// Failed to build literals huffman table
/// </summary>
INF_ERR_LITERALTBL = -7,
/// <summary>
/// Failed to build distance huffman table
/// </summary>
INF_ERR_DISTANCETBL = -8,
/// <summary>
/// Bitlen RLE code goes over table size
/// </summary>
INF_ERR_BITOVERRUN = -9,
/// <summary>
/// Invalid bit-length code
/// </summary>
INF_ERR_BADBITLEN = -10,
/// <summary>
/// Out-of-range literal code
/// </summary>
INF_ERR_LITCODE = -11,
/// <summary>
/// Out-of-range distance code
/// </summary>
INF_ERR_DISTCODE = -12,
/// <summary>
/// Somehow, distance is beyond 32k
/// </summary>
INF_ERR_DISTANCE = -13,
/// <summary>
/// Out of bits decoding huffman symbol
/// </summary>
INF_ERR_HUFFSYM = -14,
}
public enum LZSSMode
{
LZSS_MODE_EXPAND = 0,

View File

@@ -56,11 +56,11 @@ namespace LibMSPackSharp.Compression
/// </param>
/// <param name="mode">one of LZSSMode values</param>
/// <returns>an error code, or MSPACK_ERR_OK if successful</returns>
public static Error Decompress(SystemImpl system, FileStream input, FileStream output, int input_buffer_size, LZSSMode mode)
public static LibMSPackSharp.Error Decompress(SystemImpl system, FileStream input, FileStream output, int input_buffer_size, LZSSMode mode)
{
// Check parameters
if (system == null || input_buffer_size < 1 || (mode != LZSSMode.LZSS_MODE_EXPAND && mode != LZSSMode.LZSS_MODE_MSHELP && mode != LZSSMode.LZSS_MODE_QBASIC))
return Error.MSPACK_ERR_ARGS;
return LibMSPackSharp.Error.MSPACK_ERR_ARGS;
// Allocate memory
byte[] window = new byte[LZSS_WINDOW_SIZE + input_buffer_size];
@@ -85,7 +85,7 @@ namespace LibMSPackSharp.Compression
{
read = input.Read(window, inbuf, input_buffer_size);
if (read <= 0)
return (read < 0) ? Error.MSPACK_ERR_READ : Error.MSPACK_ERR_OK;
return (read < 0) ? LibMSPackSharp.Error.MSPACK_ERR_READ : LibMSPackSharp.Error.MSPACK_ERR_OK;
i_ptr = inbuf;
i_end = read;
@@ -104,7 +104,7 @@ namespace LibMSPackSharp.Compression
{
read = input.Read(window, inbuf, input_buffer_size);
if (read <= 0)
return (read < 0) ? Error.MSPACK_ERR_READ : Error.MSPACK_ERR_OK;
return (read < 0) ? LibMSPackSharp.Error.MSPACK_ERR_READ : LibMSPackSharp.Error.MSPACK_ERR_OK;
i_ptr = inbuf;
i_end = read;
@@ -116,7 +116,7 @@ namespace LibMSPackSharp.Compression
//WRITE_BYTE
{
try { output.Write(window, (int)pos, 1); }
catch { return Error.MSPACK_ERR_WRITE; }
catch { return LibMSPackSharp.Error.MSPACK_ERR_WRITE; }
}
pos++;
@@ -132,7 +132,7 @@ namespace LibMSPackSharp.Compression
{
read = input.Read(window, inbuf, input_buffer_size);
if (read <= 0)
return (read < 0) ? Error.MSPACK_ERR_READ : Error.MSPACK_ERR_OK;
return (read < 0) ? LibMSPackSharp.Error.MSPACK_ERR_READ : LibMSPackSharp.Error.MSPACK_ERR_OK;
i_ptr = inbuf;
i_end = read;
@@ -147,7 +147,7 @@ namespace LibMSPackSharp.Compression
{
read = input.Read(window, inbuf, input_buffer_size);
if (read <= 0)
return (read < 0) ? Error.MSPACK_ERR_READ : Error.MSPACK_ERR_OK;
return (read < 0) ? LibMSPackSharp.Error.MSPACK_ERR_READ : LibMSPackSharp.Error.MSPACK_ERR_OK;
i_ptr = inbuf;
i_end = read;
@@ -164,7 +164,7 @@ namespace LibMSPackSharp.Compression
//WRITE_BYTE
{
try { output.Write(window, (int)pos, 1); }
catch { return Error.MSPACK_ERR_WRITE; }
catch { return LibMSPackSharp.Error.MSPACK_ERR_WRITE; }
}
pos++;
@@ -177,7 +177,7 @@ namespace LibMSPackSharp.Compression
}
/* not reached */
return Error.MSPACK_ERR_OK;
return LibMSPackSharp.Error.MSPACK_ERR_OK;
}
}
}

View File

@@ -322,7 +322,7 @@ namespace LibMSPackSharp.Compression
ResetInterval = (uint)reset_interval,
IntelFileSize = 0,
IntelStarted = false,
Error = Error.MSPACK_ERR_OK,
Error = LibMSPackSharp.Error.MSPACK_ERR_OK,
NumOffsets = position_slots[window_bits - 15] << 3,
IsDelta = is_delta,
@@ -362,33 +362,33 @@ namespace LibMSPackSharp.Compression
/// than the LZX window size.
/// </param>
/// <returns>an error code, or MSPACK_ERR_OK if successful</returns>
public static Error SetReferenceData(LZXDStream lzx, SystemImpl system, FileStream input, uint length)
public static LibMSPackSharp.Error SetReferenceData(LZXDStream lzx, SystemImpl system, FileStream input, uint length)
{
if (lzx == null)
return Error.MSPACK_ERR_ARGS;
return LibMSPackSharp.Error.MSPACK_ERR_ARGS;
if (!lzx.IsDelta)
{
Console.WriteLine("Only LZX DELTA streams support reference data");
return Error.MSPACK_ERR_ARGS;
return LibMSPackSharp.Error.MSPACK_ERR_ARGS;
}
if (lzx.Offset != 0)
{
Console.WriteLine("Too late to set reference data after decoding starts");
return Error.MSPACK_ERR_ARGS;
return LibMSPackSharp.Error.MSPACK_ERR_ARGS;
}
if (length > lzx.WindowSize)
{
Console.WriteLine($"Reference length ({length}) is longer than the window");
return Error.MSPACK_ERR_ARGS;
return LibMSPackSharp.Error.MSPACK_ERR_ARGS;
}
if (length > 0 && (system == null || input == null))
{
Console.WriteLine("Length > 0 but no system or input");
return Error.MSPACK_ERR_ARGS;
return LibMSPackSharp.Error.MSPACK_ERR_ARGS;
}
lzx.ReferenceDataSize = length;
@@ -400,11 +400,11 @@ namespace LibMSPackSharp.Compression
// Length can't be more than 2^25, so no signedness problem
if (bytes < (int)length)
return Error.MSPACK_ERR_READ;
return LibMSPackSharp.Error.MSPACK_ERR_READ;
}
lzx.ReferenceDataSize = length;
return Error.MSPACK_ERR_OK;
return LibMSPackSharp.Error.MSPACK_ERR_OK;
}
// See description of outputLength in lzxd_init()
@@ -440,11 +440,11 @@ namespace LibMSPackSharp.Compression
/// <param name="out_bytes">the number of bytes of data to decompress.</param>
/// <returns>an error code, or MSPACK_ERR_OK if successful</returns>
// TODO: Huffman tree implementation
public static Error Decompress(object o, long out_bytes)
public static LibMSPackSharp.Error Decompress(object o, long out_bytes)
{
LZXDStream lzx = o as LZXDStream;
if (lzx == null)
return Error.MSPACK_ERR_ARGS;
return LibMSPackSharp.Error.MSPACK_ERR_ARGS;
// Bitstream and huffman reading variables
uint bit_buffer;
@@ -461,9 +461,9 @@ namespace LibMSPackSharp.Compression
// Easy answers
if (lzx == null || (out_bytes < 0))
return Error.MSPACK_ERR_ARGS;
return LibMSPackSharp.Error.MSPACK_ERR_ARGS;
if (lzx.Error != Error.MSPACK_ERR_OK)
if (lzx.Error != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
// Flush out any stored-up bytes before we begin
@@ -474,7 +474,7 @@ namespace LibMSPackSharp.Compression
if (i != 0)
{
try { lzx.Output.Write(lzx.e8_buf, lzx.OutputPointer, i); }
catch { return lzx.Error = Error.MSPACK_ERR_WRITE; }
catch { return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_WRITE; }
lzx.OutputPointer += i;
lzx.Offset += i;
@@ -482,7 +482,7 @@ namespace LibMSPackSharp.Compression
}
if (out_bytes == 0)
return Error.MSPACK_ERR_OK;
return LibMSPackSharp.Error.MSPACK_ERR_OK;
// Restore local state
@@ -538,7 +538,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -552,7 +552,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -597,7 +597,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -611,7 +611,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -653,7 +653,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -667,7 +667,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -707,7 +707,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -721,7 +721,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -775,7 +775,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -800,7 +800,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -814,7 +814,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -854,7 +854,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -868,7 +868,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -908,7 +908,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -922,7 +922,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -972,7 +972,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -986,7 +986,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1067,7 +1067,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1081,7 +1081,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1110,7 +1110,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1129,7 +1129,7 @@ namespace LibMSPackSharp.Compression
default:
Console.WriteLine("Bad block type");
return lzx.Error = Error.MSPACK_ERR_DECRUNCH;
return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
}
@@ -1170,7 +1170,7 @@ namespace LibMSPackSharp.Compression
if (lzx.LENGTH_empty != 0)
{
Console.WriteLine("LENGTH symbol needed but tree is empty");
return lzx.Error = Error.MSPACK_ERR_DECRUNCH;
return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
READ_HUFFSYM(LENGTH, length_footer);
@@ -1222,7 +1222,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1236,7 +1236,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1291,7 +1291,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1305,7 +1305,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1363,7 +1363,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1377,7 +1377,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1437,7 +1437,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1451,7 +1451,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1491,7 +1491,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1505,7 +1505,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1555,7 +1555,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1569,7 +1569,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1621,7 +1621,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1635,7 +1635,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1687,7 +1687,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1701,7 +1701,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1736,7 +1736,7 @@ namespace LibMSPackSharp.Compression
if ((window_posn + match_length) > lzx.WindowSize)
{
Console.WriteLine("Match ran over window wrap");
return lzx.Error = Error.MSPACK_ERR_DECRUNCH;
return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
// Copy match
@@ -1749,7 +1749,7 @@ namespace LibMSPackSharp.Compression
if (match_offset > lzx.Offset && (match_offset - window_posn) > lzx.ReferenceDataSize)
{
Console.WriteLine("Match offset beyond LZX stream");
return lzx.Error = Error.MSPACK_ERR_DECRUNCH;
return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
// j = length from match offset to end of window
@@ -1757,7 +1757,7 @@ namespace LibMSPackSharp.Compression
if (j > (int)lzx.WindowSize)
{
Console.WriteLine("Match offset beyond window boundaries");
return lzx.Error = Error.MSPACK_ERR_DECRUNCH;
return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
runsrc = (int)(lzx.WindowSize - j);
@@ -1807,7 +1807,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1830,7 +1830,7 @@ namespace LibMSPackSharp.Compression
break;
default:
return lzx.Error = Error.MSPACK_ERR_DECRUNCH; // Might as well
return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH; // Might as well
}
// Did the final match overrun our desired this_run length?
@@ -1839,7 +1839,7 @@ namespace LibMSPackSharp.Compression
if ((uint)(-this_run) > lzx.BlockRemaining)
{
Console.WriteLine($"Overrun went past end of block by {-this_run} ({lzx.BlockRemaining} remaining)");
return lzx.Error = Error.MSPACK_ERR_DECRUNCH;
return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
lzx.BlockRemaining -= (uint)-this_run;
@@ -1850,7 +1850,7 @@ namespace LibMSPackSharp.Compression
if ((window_posn - lzx.FramePosition) != frame_size)
{
Console.WriteLine($"Decode beyond output frame limits! {window_posn - lzx.FramePosition} != {frame_size}");
return lzx.Error = Error.MSPACK_ERR_DECRUNCH;
return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
// Re-align input bitstream
@@ -1866,7 +1866,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1880,7 +1880,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -1913,7 +1913,7 @@ namespace LibMSPackSharp.Compression
if (lzx.OutputPointer != lzx.OutputLength)
{
Console.WriteLine($"{lzx.OutputLength - lzx.OutputPointer} avail bytes, new {frame_size} frame");
return lzx.Error = Error.MSPACK_ERR_DECRUNCH;
return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
// Does this intel block _really_ need decoding?
@@ -1956,7 +1956,7 @@ namespace LibMSPackSharp.Compression
// Write a frame
i = (int)((out_bytes < frame_size) ? out_bytes : frame_size);
try { lzx.Output.Write(lzx.e8_buf, lzx.OutputPointer, i); }
catch { return lzx.Error = Error.MSPACK_ERR_WRITE; }
catch { return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_WRITE; }
}
else
{
@@ -1966,7 +1966,7 @@ namespace LibMSPackSharp.Compression
// Write a frame
i = (int)((out_bytes < frame_size) ? out_bytes : frame_size);
try { lzx.Output.Write(lzx.Window, lzx.OutputPointer, i); }
catch { return lzx.Error = Error.MSPACK_ERR_WRITE; }
catch { return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_WRITE; }
}
lzx.OutputPointer += i;
@@ -1988,7 +1988,7 @@ namespace LibMSPackSharp.Compression
if (out_bytes != 0)
{
Console.WriteLine("Bytes left to output");
return lzx.Error = Error.MSPACK_ERR_DECRUNCH;
return lzx.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
// Store local state
@@ -2006,11 +2006,11 @@ namespace LibMSPackSharp.Compression
lzx.R1 = R1;
lzx.R2 = R2;
return Error.MSPACK_ERR_OK;
return LibMSPackSharp.Error.MSPACK_ERR_OK;
}
// TODO: Huffman tree implementation
private static Error ReadLens(LZXDStream lzx, byte[] lens, uint first, uint last)
private static LibMSPackSharp.Error ReadLens(LZXDStream lzx, byte[] lens, uint first, uint last)
{
// Bit buffer and huffman symbol decode variables
uint bit_buffer;
@@ -2044,7 +2044,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -2058,7 +2058,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -2110,7 +2110,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -2124,7 +2124,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -2174,7 +2174,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -2188,7 +2188,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -2238,7 +2238,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -2252,7 +2252,7 @@ namespace LibMSPackSharp.Compression
{
if (i_ptr >= i_end)
{
if (lzx.ReadInput() != Error.MSPACK_ERR_OK)
if (lzx.ReadInput() != LibMSPackSharp.Error.MSPACK_ERR_OK)
return lzx.Error;
i_ptr = lzx.InputPointer;
@@ -2313,7 +2313,7 @@ namespace LibMSPackSharp.Compression
lzx.BitsLeft = bits_left;
}
return Error.MSPACK_ERR_OK;
return LibMSPackSharp.Error.MSPACK_ERR_OK;
}
}
}

View File

@@ -137,6 +137,6 @@ namespace LibMSPackSharp.Compression
// This is used purely for doing the intel E8 transform
public byte[] e8_buf { get; set; } = new byte[LZX.LZX_FRAME_SIZE];
public override int HUFF_ERROR() => (int)(Error = Error.MSPACK_ERR_DECRUNCH);
public override int HUFF_ERROR() => (int)(Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -29,7 +29,7 @@ namespace LibMSPackSharp.Compression
/// <summary>
/// inflate() will call this whenever the window should be emptied.
/// </summary>
public Func<MSZIPDStream, uint, Error> FlushWindow;
public Func<MSZIPDStream, uint, LibMSPackSharp.Error> FlushWindow;
public bool RepairMode { get; set; }
@@ -49,6 +49,6 @@ namespace LibMSPackSharp.Compression
#endregion
public override int HUFF_ERROR() => (int)InflateErrorCode.INF_ERR_HUFFSYM;
public override int HUFF_ERROR() => (int)Error.INF_ERR_HUFFSYM;
}
}

View File

@@ -25,11 +25,11 @@ namespace LibMSPackSharp.Compression
};
}
public static Error Decompress(object s, long bytes)
public static LibMSPackSharp.Error Decompress(object s, long bytes)
{
NoneState state = (NoneState)s;
if (state == null)
return Error.MSPACK_ERR_ARGS;
return LibMSPackSharp.Error.MSPACK_ERR_ARGS;
int run;
while (bytes > 0)
@@ -37,14 +37,14 @@ namespace LibMSPackSharp.Compression
run = (bytes > state.BufferSize) ? state.BufferSize : (int)bytes;
if (state.Sys.Read(state.Input, state.Buffer, 0, run) != run)
return Error.MSPACK_ERR_READ;
return LibMSPackSharp.Error.MSPACK_ERR_READ;
if (state.Sys.Write(state.Output, state.Buffer, 0, run) != run)
return Error.MSPACK_ERR_WRITE;
return LibMSPackSharp.Error.MSPACK_ERR_WRITE;
bytes -= run;
}
return Error.MSPACK_ERR_OK;
return LibMSPackSharp.Error.MSPACK_ERR_OK;
}
}
}

View File

@@ -123,7 +123,7 @@ namespace LibMSPackSharp.Compression
qtm.WindowPosition = 0;
qtm.FrameTODO = QTM_FRAME_SIZE;
qtm.HeaderRead = 0;
qtm.Error = Error.MSPACK_ERR_OK;
qtm.Error = LibMSPackSharp.Error.MSPACK_ERR_OK;
qtm.InputPointer = qtm.InputLength = 0;
qtm.OutputPointer = qtm.OutputLength = 0;
@@ -170,11 +170,11 @@ namespace LibMSPackSharp.Compression
/// qtmd_init(). This will continue until system.read() returns 0 bytes,
/// or an error.
/// </summary>
public static Error Decompress(object o, long out_bytes)
public static LibMSPackSharp.Error Decompress(object o, long out_bytes)
{
QTMDStream qtm = o as QTMDStream;
if (qtm == null)
return Error.MSPACK_ERR_ARGS;
return LibMSPackSharp.Error.MSPACK_ERR_ARGS;
uint frame_end, match_offset, range = 0, extra = 0;
int i_ptr = 0, i_end = 0, runsrc, rundest;
@@ -186,9 +186,9 @@ namespace LibMSPackSharp.Compression
// Easy answers
if (qtm == null || (out_bytes < 0))
return Error.MSPACK_ERR_ARGS;
return LibMSPackSharp.Error.MSPACK_ERR_ARGS;
if (qtm.Error != Error.MSPACK_ERR_OK)
if (qtm.Error != LibMSPackSharp.Error.MSPACK_ERR_OK)
return qtm.Error;
// Flush out any stored-up bytes before we begin
@@ -199,14 +199,14 @@ namespace LibMSPackSharp.Compression
if (i != 0)
{
if (qtm.Sys.Write(qtm.Output, qtm.Window, qtm.OutputPointer, i) != i)
return qtm.Error = Error.MSPACK_ERR_WRITE;
return qtm.Error = LibMSPackSharp.Error.MSPACK_ERR_WRITE;
qtm.OutputPointer += i;
out_bytes -= i;
}
if (out_bytes == 0)
return Error.MSPACK_ERR_OK;
return LibMSPackSharp.Error.MSPACK_ERR_OK;
// Restore local state
@@ -407,7 +407,7 @@ namespace LibMSPackSharp.Compression
default:
// Should be impossible, model7 can only return 0-6
Console.WriteLine("got %d from selector", selector);
return qtm.Error = Error.MSPACK_ERR_DECRUNCH;
return qtm.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
rundest = (int)window_posn;
@@ -436,11 +436,11 @@ namespace LibMSPackSharp.Compression
if (i > out_bytes)
{
Console.WriteLine($"during window-wrap match; {i} bytes to flush but only need {out_bytes}");
return qtm.Error = Error.MSPACK_ERR_DECRUNCH;
return qtm.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
if (qtm.Sys.Write(qtm.Output, qtm.Window, qtm.OutputPointer, i) != i)
return qtm.Error = Error.MSPACK_ERR_WRITE;
return qtm.Error = LibMSPackSharp.Error.MSPACK_ERR_WRITE;
out_bytes -= i;
qtm.OutputPointer = 0;
@@ -471,7 +471,7 @@ namespace LibMSPackSharp.Compression
if (j > (int)qtm.WindowSize)
{
Console.WriteLine("match offset beyond window boundaries");
return qtm.Error = Error.MSPACK_ERR_DECRUNCH;
return qtm.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
runsrc = (int)(qtm.WindowSize - j);
@@ -513,7 +513,7 @@ namespace LibMSPackSharp.Compression
if (frame_todo > QTM_FRAME_SIZE)
{
Console.WriteLine("overshot frame alignment");
return qtm.Error = Error.MSPACK_ERR_DECRUNCH;
return qtm.Error = LibMSPackSharp.Error.MSPACK_ERR_DECRUNCH;
}
// Another frame completed?
@@ -564,7 +564,7 @@ namespace LibMSPackSharp.Compression
break;
if (qtm.Sys.Write(qtm.Output, qtm.Window, qtm.OutputPointer, i) != i)
return qtm.Error = Error.MSPACK_ERR_WRITE;
return qtm.Error = LibMSPackSharp.Error.MSPACK_ERR_WRITE;
out_bytes -= i;
qtm.OutputPointer = 0;
@@ -577,7 +577,7 @@ namespace LibMSPackSharp.Compression
{
i = (int)out_bytes;
if (qtm.Sys.Write(qtm.Output, qtm.Window, qtm.OutputPointer, i) != i)
return qtm.Error = Error.MSPACK_ERR_WRITE;
return qtm.Error = LibMSPackSharp.Error.MSPACK_ERR_WRITE;
qtm.OutputPointer += i;
}
@@ -596,7 +596,7 @@ namespace LibMSPackSharp.Compression
qtm.Low = low;
qtm.Current = (ushort)current;
return Error.MSPACK_ERR_OK;
return LibMSPackSharp.Error.MSPACK_ERR_OK;
}
/// <summary>
@@ -661,7 +661,7 @@ namespace LibMSPackSharp.Compression
READ_BYTES;
}
if (qtm.Error != Error.MSPACK_ERR_OK)
if (qtm.Error != LibMSPackSharp.Error.MSPACK_ERR_OK)
return;
current = (ushort)((current << 1) | (bit_buffer >> (LZXDStream.BITBUF_WIDTH - (1)))); //PEEK_BITS(1)

View File

@@ -120,6 +120,6 @@ namespace LibMSPackSharp.Compression
public QTMDModelSym[] Model7Symbols { get; set; } = new QTMDModelSym[7 + 1];
public override int HUFF_ERROR() => (int)Error.MSPACK_ERR_OK;
public override int HUFF_ERROR() => (int)LibMSPackSharp.Error.MSPACK_ERR_OK;
}
}

View File

@@ -24,6 +24,8 @@ namespace LibMSPackSharp
/// </summary>
public enum Error
{
#region MSPACK Errors
/// <summary>
/// Used to indicate success.
/// This error code is defined as zero, all other code are non-zero.
@@ -84,6 +86,82 @@ namespace LibMSPackSharp
/// Error during decompression
/// </summary>
MSPACK_ERR_DECRUNCH = 11,
#endregion
#region Inflate Errors
/// <summary>
/// Unknown block type
/// </summary>
INF_ERR_BLOCKTYPE = -1,
/// <summary>
/// Block size complement mismatch
/// </summary>
INF_ERR_COMPLEMENT = -2,
/// <summary>
/// Error from flush_window callback
/// </summary>
INF_ERR_FLUSH = -3,
/// <summary>
/// Too many bits in bit buffer
/// </summary>
INF_ERR_BITBUF = -4,
/// <summary>
/// Too many symbols in blocktype 2 header
/// </summary>
INF_ERR_SYMLENS = -5,
/// <summary>
/// Failed to build bitlens huffman table
/// </summary>
INF_ERR_BITLENTBL = -6,
/// <summary>
/// Failed to build literals huffman table
/// </summary>
INF_ERR_LITERALTBL = -7,
/// <summary>
/// Failed to build distance huffman table
/// </summary>
INF_ERR_DISTANCETBL = -8,
/// <summary>
/// Bitlen RLE code goes over table size
/// </summary>
INF_ERR_BITOVERRUN = -9,
/// <summary>
/// Invalid bit-length code
/// </summary>
INF_ERR_BADBITLEN = -10,
/// <summary>
/// Out-of-range literal code
/// </summary>
INF_ERR_LITCODE = -11,
/// <summary>
/// Out-of-range distance code
/// </summary>
INF_ERR_DISTCODE = -12,
/// <summary>
/// Somehow, distance is beyond 32k
/// </summary>
INF_ERR_DISTANCE = -13,
/// <summary>
/// Out of bits decoding huffman symbol
/// </summary>
INF_ERR_HUFFSYM = -14,
#endregion
}
/// <summary>