From 3ea294f4d96b64f3be7de590fe36f527840c7bfc Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 19 May 2022 22:32:58 -0700 Subject: [PATCH] DefaultFileImpl -> FileStream --- .../External/libmspack/CAB/DecompressState.cs | 5 +- .../External/libmspack/CAB/Decompressor.cs | 21 ++++---- .../External/libmspack/CHM/DecompressState.cs | 5 +- .../External/libmspack/CHM/Implementation.cs | 15 +++--- .../Compression/CompressionStream.cs | 5 +- .../External/libmspack/Compression/LZSS.cs | 4 +- .../External/libmspack/Compression/LZX.cs | 5 +- .../External/libmspack/Compression/MSZIP.cs | 5 +- .../External/libmspack/Compression/None.cs | 26 ++++----- .../libmspack/Compression/NoneState.cs | 6 ++- .../External/libmspack/Compression/QTM.cs | 3 +- .../External/libmspack/DefaultFileImpl.cs | 20 ------- .../External/libmspack/KWAJ/HeaderImpl.cs | 4 +- .../External/libmspack/KWAJ/Implementation.cs | 11 ++-- .../External/libmspack/OAB/Implementation.cs | 19 +++---- .../External/libmspack/OAB/InternalFile.cs | 6 ++- .../External/libmspack/SZDD/HeaderImpl.cs | 4 +- .../External/libmspack/SZDD/Implementation.cs | 9 ++-- BurnOutSharp/External/libmspack/SystemImpl.cs | 53 ++++++++----------- 19 files changed, 107 insertions(+), 119 deletions(-) delete mode 100644 BurnOutSharp/External/libmspack/DefaultFileImpl.cs diff --git a/BurnOutSharp/External/libmspack/CAB/DecompressState.cs b/BurnOutSharp/External/libmspack/CAB/DecompressState.cs index 501c71b7..94cceab6 100644 --- a/BurnOutSharp/External/libmspack/CAB/DecompressState.cs +++ b/BurnOutSharp/External/libmspack/CAB/DecompressState.cs @@ -8,6 +8,7 @@ */ using System; +using System.IO; namespace LibMSPackSharp.CAB { @@ -66,12 +67,12 @@ namespace LibMSPackSharp.CAB /// /// Input file handle /// - public DefaultFileImpl InputFileHandle { get; set; } + public FileStream InputFileHandle { get; set; } /// /// Output file handle /// - public DefaultFileImpl OutputFileHandle { get; set; } + public FileStream OutputFileHandle { get; set; } /// /// Input data consumed diff --git a/BurnOutSharp/External/libmspack/CAB/Decompressor.cs b/BurnOutSharp/External/libmspack/CAB/Decompressor.cs index 99f40ad6..7fbf2140 100644 --- a/BurnOutSharp/External/libmspack/CAB/Decompressor.cs +++ b/BurnOutSharp/External/libmspack/CAB/Decompressor.cs @@ -15,6 +15,7 @@ */ using System; +using System.IO; using System.Text; using LibMSPackSharp.Compression; using static LibMSPackSharp.CAB.Constants; @@ -72,7 +73,7 @@ namespace LibMSPackSharp.CAB /// public Cabinet Open(string filename) { - DefaultFileImpl fileHandle = System.Open(filename, OpenMode.MSPACK_SYS_OPEN_READ); + FileStream fileHandle = System.Open(filename, OpenMode.MSPACK_SYS_OPEN_READ); if (fileHandle == null) { Error = Error.MSPACK_ERR_OPEN; @@ -211,7 +212,7 @@ namespace LibMSPackSharp.CAB } // Open file and get its full file length - DefaultFileImpl fh; Cabinet cab = null; + FileStream fh; Cabinet cab = null; if ((fh = System.Open(filename, OpenMode.MSPACK_SYS_OPEN_READ)) != null) { long firstlen = 0; @@ -402,7 +403,7 @@ namespace LibMSPackSharp.CAB } // Open file for output - DefaultFileImpl fh = System.Open(filename, OpenMode.MSPACK_SYS_OPEN_WRITE); + FileStream fh = System.Open(filename, OpenMode.MSPACK_SYS_OPEN_WRITE); if (fh == null) return Error = Error.MSPACK_ERR_OPEN; @@ -634,9 +635,9 @@ namespace LibMSPackSharp.CAB return bytes - todo; } - else if (file is DefaultFileImpl impl) + else if (file is FileStream impl) { - return SystemImpl.DefaultSystem.Read(file, buffer, pointer, bytes); + return SystemImpl.DefaultSystem.Read(impl, buffer, pointer, bytes); } return -1; @@ -658,9 +659,9 @@ namespace LibMSPackSharp.CAB return bytes; } - else if (file is DefaultFileImpl impl) + else if (file is FileStream impl) { - return SystemImpl.DefaultSystem.Write(file, buffer, pointer, bytes); + return SystemImpl.DefaultSystem.Write(impl, buffer, pointer, bytes); } // Unknown file to write to @@ -870,7 +871,7 @@ namespace LibMSPackSharp.CAB /// The inner loop of , to make it easier to /// break out of the loop and be sure that all resources are freed /// - private Error Find(byte[] buf, DefaultFileImpl fh, string filename, long flen, ref long firstlen, out Cabinet firstcab) + private Error Find(byte[] buf, FileStream fh, string filename, long flen, ref long firstlen, out Cabinet firstcab) { firstcab = null; Cabinet cab, link = null; @@ -1213,7 +1214,7 @@ namespace LibMSPackSharp.CAB /// Fills out a pre-existing Cabinet structure, allocates memory /// for folders and files as necessary /// - private Error ReadHeaders(DefaultFileImpl fh, Cabinet cab, long offset, bool salvage, bool quiet) + private Error ReadHeaders(FileStream fh, Cabinet cab, long offset, bool salvage, bool quiet) { Error err = Error.MSPACK_ERR_OK; Folder fol, linkfol = null; @@ -1436,7 +1437,7 @@ namespace LibMSPackSharp.CAB return Error.MSPACK_ERR_OK; } - private string ReadString(DefaultFileImpl fh, bool permitEmpty, ref Error error) + private string ReadString(FileStream fh, bool permitEmpty, ref Error error) { long position = System.Tell(fh); byte[] buf = new byte[256]; diff --git a/BurnOutSharp/External/libmspack/CHM/DecompressState.cs b/BurnOutSharp/External/libmspack/CHM/DecompressState.cs index 6cab3a6c..b1d87eec 100644 --- a/BurnOutSharp/External/libmspack/CHM/DecompressState.cs +++ b/BurnOutSharp/External/libmspack/CHM/DecompressState.cs @@ -7,6 +7,7 @@ * For further details, see the file COPYING.LIB distributed with libmspack */ +using System.IO; using LibMSPackSharp.Compression; namespace LibMSPackSharp.CHM @@ -41,11 +42,11 @@ namespace LibMSPackSharp.CHM /// /// Input file handle /// - public DefaultFileImpl InputFileHandle { get; set; } + public FileStream InputFileHandle { get; set; } /// /// Output file handle /// - public DefaultFileImpl OutputFileHandle { get; set; } + public FileStream OutputFileHandle { get; set; } } } diff --git a/BurnOutSharp/External/libmspack/CHM/Implementation.cs b/BurnOutSharp/External/libmspack/CHM/Implementation.cs index c5cbe079..d6b21d3b 100644 --- a/BurnOutSharp/External/libmspack/CHM/Implementation.cs +++ b/BurnOutSharp/External/libmspack/CHM/Implementation.cs @@ -8,6 +8,7 @@ */ using System; +using System.IO; using System.Linq; using System.Text; using LibMSPackSharp.Compression; @@ -152,7 +153,7 @@ namespace LibMSPackSharp.CHM SystemImpl sys = self.System; - DefaultFileImpl fh; + FileStream fh; if ((fh = sys.Open(filename, OpenMode.MSPACK_SYS_OPEN_READ)) != null) { chm = new Header(); @@ -249,7 +250,7 @@ namespace LibMSPackSharp.CHM /// non-zero, all file entries will also be read. fills out a pre-existing /// mschmd_header structure, allocates memory for files as necessary /// - public static Error ReadHeaders(SystemImpl sys, DefaultFileImpl fh, Header chm, bool entire) + public static Error ReadHeaders(SystemImpl sys, FileStream fh, Header chm, bool entire) { uint section, nameLen, x, errors, numChunks; byte[] buf = new byte[0x54]; @@ -569,7 +570,7 @@ namespace LibMSPackSharp.CHM { DecompressorImpl self = d as DecompressorImpl; SystemImpl sys; - DefaultFileImpl fh; + FileStream fh; // p and end are initialised to prevent MSVC warning about "potentially" // uninitialised usage. This is provably untrue, but MS won't fix: @@ -699,7 +700,7 @@ namespace LibMSPackSharp.CHM /// Reads the given chunk into memory, storing it in a chunk cache /// so it doesn't need to be read from disk more than once /// - public static byte[] ReadChunk(DecompressorImpl self, Header chm, DefaultFileImpl fh, uint chunkNum) + public static byte[] ReadChunk(DecompressorImpl self, Header chm, FileStream fh, uint chunkNum) { SystemImpl sys = self.System; @@ -1003,7 +1004,7 @@ namespace LibMSPackSharp.CHM } // Open file for output - DefaultFileImpl fh; + FileStream fh; if ((fh = sys.Open(filename, OpenMode.MSPACK_SYS_OPEN_WRITE)) == null) return self.Error = Error.MSPACK_ERR_OPEN; @@ -1120,9 +1121,9 @@ namespace LibMSPackSharp.CHM return bytes; } - else if (file is DefaultFileImpl impl) + else if (file is FileStream impl) { - return SystemImpl.DefaultSystem.Write(file, buffer, offset, bytes); + return SystemImpl.DefaultSystem.Write(impl, buffer, offset, bytes); } // Unknown file to write to diff --git a/BurnOutSharp/External/libmspack/Compression/CompressionStream.cs b/BurnOutSharp/External/libmspack/Compression/CompressionStream.cs index 9b0d8fa4..c8f10825 100644 --- a/BurnOutSharp/External/libmspack/Compression/CompressionStream.cs +++ b/BurnOutSharp/External/libmspack/Compression/CompressionStream.cs @@ -11,6 +11,7 @@ */ using System; +using System.IO; namespace LibMSPackSharp.Compression { @@ -28,12 +29,12 @@ namespace LibMSPackSharp.Compression /// /// Input file handle /// - public object Input { get; set; } + public FileStream Input { get; set; } /// /// Output file handle /// - public object Output { get; set; } + public FileStream Output { get; set; } public Error Error { get; set; } diff --git a/BurnOutSharp/External/libmspack/Compression/LZSS.cs b/BurnOutSharp/External/libmspack/Compression/LZSS.cs index d667a206..a0573af3 100644 --- a/BurnOutSharp/External/libmspack/Compression/LZSS.cs +++ b/BurnOutSharp/External/libmspack/Compression/LZSS.cs @@ -11,6 +11,8 @@ * For further details, see the file COPYING.LIB distributed with libmspack */ +using System.IO; + namespace LibMSPackSharp.Compression { public class LZSS @@ -54,7 +56,7 @@ namespace LibMSPackSharp.Compression /// /// one of LZSSMode values /// an error code, or MSPACK_ERR_OK if successful - public static Error Decompress(SystemImpl system, object input, object output, int inputBufferSize, LZSSMode mode) + public static Error Decompress(SystemImpl system, FileStream input, FileStream output, int inputBufferSize, LZSSMode mode) { uint i, c, mpos, len; int read; diff --git a/BurnOutSharp/External/libmspack/Compression/LZX.cs b/BurnOutSharp/External/libmspack/Compression/LZX.cs index 6e305897..325f8475 100644 --- a/BurnOutSharp/External/libmspack/Compression/LZX.cs +++ b/BurnOutSharp/External/libmspack/Compression/LZX.cs @@ -75,6 +75,7 @@ */ using System; +using System.IO; namespace LibMSPackSharp.Compression { @@ -267,7 +268,7 @@ namespace LibMSPackSharp.Compression /// a pointer to an initialised LZXDStream structure, or null if /// there was not enough memory or parameters to the function were wrong. /// - public static LZXDStream Init(SystemImpl system, DefaultFileImpl input, DefaultFileImpl output, int windowBits, int resetInterval, int inputBufferSize, long outputLength, bool isDelta) + public static LZXDStream Init(SystemImpl system, FileStream input, FileStream output, int windowBits, int resetInterval, int inputBufferSize, long outputLength, bool isDelta) { uint windowSize = (uint)(1 << windowBits); @@ -354,7 +355,7 @@ namespace LibMSPackSharp.Compression /// than the LZX window size. /// /// an error code, or MSPACK_ERR_OK if successful - public static Error SetReferenceData(LZXDStream lzx, SystemImpl system, object input, uint length) + public static Error SetReferenceData(LZXDStream lzx, SystemImpl system, FileStream input, uint length) { if (lzx == null) return Error.MSPACK_ERR_ARGS; diff --git a/BurnOutSharp/External/libmspack/Compression/MSZIP.cs b/BurnOutSharp/External/libmspack/Compression/MSZIP.cs index d3394628..242fbea9 100644 --- a/BurnOutSharp/External/libmspack/Compression/MSZIP.cs +++ b/BurnOutSharp/External/libmspack/Compression/MSZIP.cs @@ -11,6 +11,7 @@ */ using System; +using System.IO; namespace LibMSPackSharp.Compression { @@ -93,7 +94,7 @@ namespace LibMSPackSharp.Compression /// and 'holes' left will be filled with zero bytes. This allows at least /// a partial recovery of erroneous data. /// - public static MSZIPDStream Init(SystemImpl system, DefaultFileImpl input, DefaultFileImpl output, int input_buffer_size, bool repair_mode) + public static MSZIPDStream Init(SystemImpl system, FileStream input, FileStream output, int input_buffer_size, bool repair_mode) { if (system == null) return null; @@ -237,7 +238,7 @@ namespace LibMSPackSharp.Compression // Write a frame i = (out_bytes < zip.BytesOutput) ? (int)out_bytes : zip.BytesOutput; - if (zip.Output is DefaultFileImpl) + if (zip.Output is FileStream) { if (SystemImpl.DefaultSystem.Write(zip.Output, zip.Window, zip.OutputPointer, i) != i) return zip.Error = Error.MSPACK_ERR_WRITE; diff --git a/BurnOutSharp/External/libmspack/Compression/None.cs b/BurnOutSharp/External/libmspack/Compression/None.cs index d298779d..3d26968a 100644 --- a/BurnOutSharp/External/libmspack/Compression/None.cs +++ b/BurnOutSharp/External/libmspack/Compression/None.cs @@ -7,28 +7,22 @@ * For further details, see the file COPYING.LIB distributed with libmspack */ +using System.IO; + namespace LibMSPackSharp.Compression { public class None { - public static NoneState Init(SystemImpl sys, DefaultFileImpl input, DefaultFileImpl output, int bufsize) + public static NoneState Init(SystemImpl sys, FileStream input, FileStream output, int bufsize) { - NoneState state = new NoneState(); - byte[] buf = new byte[bufsize]; - if (state != null && buf != null) + return new NoneState() { - state.Sys = sys; - state.Input = input; - state.Output = output; - state.Buffer = buf; - state.BufferSize = bufsize; - } - else - { - state = null; - } - - return state; + Sys = sys, + Input = input, + Output = output, + Buffer = new byte[bufsize], + BufferSize = bufsize, + }; } public static Error Decompress(object s, long bytes) diff --git a/BurnOutSharp/External/libmspack/Compression/NoneState.cs b/BurnOutSharp/External/libmspack/Compression/NoneState.cs index 17d047c5..ccbba111 100644 --- a/BurnOutSharp/External/libmspack/Compression/NoneState.cs +++ b/BurnOutSharp/External/libmspack/Compression/NoneState.cs @@ -7,6 +7,8 @@ * For further details, see the file COPYING.LIB distributed with libmspack */ +using System.IO; + namespace LibMSPackSharp.Compression { /// @@ -16,9 +18,9 @@ namespace LibMSPackSharp.Compression { public SystemImpl Sys { get; set; } - public object Input { get; set; } + public FileStream Input { get; set; } - public object Output { get; set; } + public FileStream Output { get; set; } public byte[] Buffer { get; set; } diff --git a/BurnOutSharp/External/libmspack/Compression/QTM.cs b/BurnOutSharp/External/libmspack/Compression/QTM.cs index 82e75ac8..2977e1c2 100644 --- a/BurnOutSharp/External/libmspack/Compression/QTM.cs +++ b/BurnOutSharp/External/libmspack/Compression/QTM.cs @@ -21,6 +21,7 @@ */ using System; +using System.IO; namespace LibMSPackSharp.Compression { @@ -91,7 +92,7 @@ namespace LibMSPackSharp.Compression /// - window_bits is the size of the Quantum window, from 1Kb(10) to 2Mb(21). /// - input_buffer_size is the number of bytes to use to store bitstream data. /// - public static QTMDStream Init(SystemImpl system, DefaultFileImpl input, DefaultFileImpl output, int window_bits, int input_buffer_size) + public static QTMDStream Init(SystemImpl system, FileStream input, FileStream output, int window_bits, int input_buffer_size) { uint window_size = (uint)(1 << window_bits); diff --git a/BurnOutSharp/External/libmspack/DefaultFileImpl.cs b/BurnOutSharp/External/libmspack/DefaultFileImpl.cs deleted file mode 100644 index b51b3afd..00000000 --- a/BurnOutSharp/External/libmspack/DefaultFileImpl.cs +++ /dev/null @@ -1,20 +0,0 @@ -/* This file is part of libmspack. - * (C) 2003-2004 Stuart Caie. - * - * libmspack is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License (LGPL) version 2.1 - * - * For further details, see the file COPYING.LIB distributed with libmspack - */ - -using System.IO; - -namespace LibMSPackSharp -{ - public class DefaultFileImpl - { - public Stream FileHandle { get; set; } - - public string Name { get; set; } - }; -} diff --git a/BurnOutSharp/External/libmspack/KWAJ/HeaderImpl.cs b/BurnOutSharp/External/libmspack/KWAJ/HeaderImpl.cs index 7589c20e..77e1d5b0 100644 --- a/BurnOutSharp/External/libmspack/KWAJ/HeaderImpl.cs +++ b/BurnOutSharp/External/libmspack/KWAJ/HeaderImpl.cs @@ -7,10 +7,12 @@ * For further details, see the file COPYING.LIB distributed with libmspack */ +using System.IO; + namespace LibMSPackSharp.KWAJ { public class HeaderImpl : Header { - public DefaultFileImpl FileHandle { get; set; } + public FileStream FileHandle { get; set; } } } diff --git a/BurnOutSharp/External/libmspack/KWAJ/Implementation.cs b/BurnOutSharp/External/libmspack/KWAJ/Implementation.cs index 0049e20a..43f6276a 100644 --- a/BurnOutSharp/External/libmspack/KWAJ/Implementation.cs +++ b/BurnOutSharp/External/libmspack/KWAJ/Implementation.cs @@ -8,6 +8,7 @@ */ using System; +using System.IO; using System.Text; using LibMSPackSharp.Compression; @@ -76,7 +77,7 @@ namespace LibMSPackSharp.KWAJ SystemImpl sys = self.System; - DefaultFileImpl fh = sys.Open(filename, OpenMode.MSPACK_SYS_OPEN_READ); + FileStream fh = sys.Open(filename, OpenMode.MSPACK_SYS_OPEN_READ); HeaderImpl hdr = new HeaderImpl(); if (fh != null && hdr != null) { @@ -130,7 +131,7 @@ namespace LibMSPackSharp.KWAJ /// /// Reads the headers of a KWAJ format file /// - public static Error ReadHeaders(SystemImpl sys, DefaultFileImpl fh, Header hdr) + public static Error ReadHeaders(SystemImpl sys, FileStream fh, Header hdr) { int i; @@ -283,7 +284,7 @@ namespace LibMSPackSharp.KWAJ return self.Error = Error.MSPACK_ERR_ARGS; SystemImpl sys = self.System; - DefaultFileImpl fh = (hdr as HeaderImpl)?.FileHandle; + FileStream fh = (hdr as HeaderImpl)?.FileHandle; if (fh == null) return Error.MSPACK_ERR_ARGS; @@ -292,7 +293,7 @@ namespace LibMSPackSharp.KWAJ return self.Error = Error.MSPACK_ERR_SEEK; // Open file for output - DefaultFileImpl outfh; + FileStream outfh; if ((outfh = sys.Open(filename, OpenMode.MSPACK_SYS_OPEN_WRITE)) == null) return self.Error = Error.MSPACK_ERR_OPEN; @@ -401,7 +402,7 @@ namespace LibMSPackSharp.KWAJ * 2 fake bytes in then stops), so we implement our own. */ - private static InternalStream LZHInit(SystemImpl sys, object input, object output) + private static InternalStream LZHInit(SystemImpl sys, FileStream input, FileStream output) { if (sys == null || input == null || output == null) return null; diff --git a/BurnOutSharp/External/libmspack/OAB/Implementation.cs b/BurnOutSharp/External/libmspack/OAB/Implementation.cs index 5023e235..b4e7d5ca 100644 --- a/BurnOutSharp/External/libmspack/OAB/Implementation.cs +++ b/BurnOutSharp/External/libmspack/OAB/Implementation.cs @@ -21,6 +21,7 @@ */ using System; +using System.IO; using LibMSPackSharp.Compression; namespace LibMSPackSharp.OAB @@ -93,7 +94,7 @@ namespace LibMSPackSharp.OAB return bytes_written; } - else if (baseFile is DefaultFileImpl impl) + else if (baseFile is FileStream impl) { return SystemImpl.DefaultSystem.Write(impl, buf, pointer, size); } @@ -118,7 +119,7 @@ namespace LibMSPackSharp.OAB SystemImpl sys = self.System; - DefaultFileImpl infh = sys.Open(input, OpenMode.MSPACK_SYS_OPEN_READ); + FileStream infh = sys.Open(input, OpenMode.MSPACK_SYS_OPEN_READ); if (infh == null) { ret = Error.MSPACK_ERR_OPEN; @@ -150,7 +151,7 @@ namespace LibMSPackSharp.OAB uint block_max = BitConverter.ToUInt32(hdrbuf, oabhead_BlockMax); uint target_size = BitConverter.ToUInt32(hdrbuf, oabhead_TargetSize); - DefaultFileImpl outfh = sys.Open(output, OpenMode.MSPACK_SYS_OPEN_WRITE); + FileStream outfh = sys.Open(output, OpenMode.MSPACK_SYS_OPEN_WRITE); if (outfh == null) { ret = Error.MSPACK_ERR_OPEN; @@ -243,7 +244,7 @@ namespace LibMSPackSharp.OAB in_ofh.Available = (int)blk_csize; out_ofh.CRC = 0xffffffff; - lzx = LZX.Init(oabd_sys, in_ofh, out_ofh, window_bits, 0, self.BufferSize, blk_dsize, true); + lzx = LZX.Init(oabd_sys, in_ofh.OrigFile, out_ofh.OrigFile, window_bits, 0, self.BufferSize, blk_dsize, true); if (lzx == null) { ret = Error.MSPACK_ERR_NOMEMORY; @@ -321,7 +322,7 @@ namespace LibMSPackSharp.OAB SystemImpl sys = self.System; - DefaultFileImpl infh = sys.Open(input, OpenMode.MSPACK_SYS_OPEN_READ); + FileStream infh = sys.Open(input, OpenMode.MSPACK_SYS_OPEN_READ); if (infh == null) { ret = Error.MSPACK_ERR_OPEN; @@ -357,7 +358,7 @@ namespace LibMSPackSharp.OAB if (block_max < patchblk_SIZEOF) block_max = patchblk_SIZEOF; - DefaultFileImpl basefh = sys.Open(basePath, OpenMode.MSPACK_SYS_OPEN_READ); + FileStream basefh = sys.Open(basePath, OpenMode.MSPACK_SYS_OPEN_READ); if (basefh == null) { ret = Error.MSPACK_ERR_OPEN; @@ -369,7 +370,7 @@ namespace LibMSPackSharp.OAB return ret; } - DefaultFileImpl outfh = sys.Open(output, OpenMode.MSPACK_SYS_OPEN_WRITE); + FileStream outfh = sys.Open(output, OpenMode.MSPACK_SYS_OPEN_WRITE); if (outfh == null) { ret = Error.MSPACK_ERR_OPEN; @@ -440,7 +441,7 @@ namespace LibMSPackSharp.OAB in_ofh.Available = (int)blk_csize; out_ofh.CRC = 0xffffffff; - lzx = LZX.Init(oabd_sys, in_ofh, out_ofh, window_bits, 0, 4096, blk_dsize, true); + lzx = LZX.Init(oabd_sys, in_ofh.OrigFile, out_ofh.OrigFile, window_bits, 0, 4096, blk_dsize, true); if (lzx == null) { ret = Error.MSPACK_ERR_NOMEMORY; @@ -522,7 +523,7 @@ namespace LibMSPackSharp.OAB return ret; } - private static Error CopyFileHandle(SystemImpl sys, object infh, object outfh, int bytes_to_copy, byte[] buf, int buf_size) + private static Error CopyFileHandle(SystemImpl sys, FileStream infh, FileStream outfh, int bytes_to_copy, byte[] buf, int buf_size) { while (bytes_to_copy != 0) { diff --git a/BurnOutSharp/External/libmspack/OAB/InternalFile.cs b/BurnOutSharp/External/libmspack/OAB/InternalFile.cs index 1d04e89b..4cd8f81e 100644 --- a/BurnOutSharp/External/libmspack/OAB/InternalFile.cs +++ b/BurnOutSharp/External/libmspack/OAB/InternalFile.cs @@ -14,13 +14,15 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +using System.IO; + namespace LibMSPackSharp.OAB { - public class InternalFile : DefaultFileImpl + public class InternalFile { public SystemImpl OrigSys { get; set; } - public object OrigFile { get; set; } + public FileStream OrigFile { get; set; } public uint CRC { get; set; } diff --git a/BurnOutSharp/External/libmspack/SZDD/HeaderImpl.cs b/BurnOutSharp/External/libmspack/SZDD/HeaderImpl.cs index a0a1e310..57a4dee1 100644 --- a/BurnOutSharp/External/libmspack/SZDD/HeaderImpl.cs +++ b/BurnOutSharp/External/libmspack/SZDD/HeaderImpl.cs @@ -7,10 +7,12 @@ * For further details, see the file COPYING.LIB distributed with libmspack */ +using System.IO; + namespace LibMSPackSharp.SZDD { public class HeaderImpl : Header { - public DefaultFileImpl FileHandle { get; set; } + public FileStream FileHandle { get; set; } } } diff --git a/BurnOutSharp/External/libmspack/SZDD/Implementation.cs b/BurnOutSharp/External/libmspack/SZDD/Implementation.cs index e019b422..7d37412d 100644 --- a/BurnOutSharp/External/libmspack/SZDD/Implementation.cs +++ b/BurnOutSharp/External/libmspack/SZDD/Implementation.cs @@ -8,6 +8,7 @@ */ using System; +using System.IO; using System.Linq; using LibMSPackSharp.Compression; @@ -33,7 +34,7 @@ namespace LibMSPackSharp.SZDD SystemImpl sys = self.System; - DefaultFileImpl fh = sys.Open(filename, OpenMode.MSPACK_SYS_OPEN_READ); + FileStream fh = sys.Open(filename, OpenMode.MSPACK_SYS_OPEN_READ); HeaderImpl hdr = new HeaderImpl(); if (fh != null && hdr != null) { @@ -97,7 +98,7 @@ namespace LibMSPackSharp.SZDD /// /// Reads the headers of an SZDD format file /// - public static Error ReadHeaders(SystemImpl sys, object fh, Header hdr) + public static Error ReadHeaders(SystemImpl sys, FileStream fh, Header hdr) { // Read and check signature byte[] buf = new byte[8]; @@ -154,7 +155,7 @@ namespace LibMSPackSharp.SZDD SystemImpl sys = self.System; - DefaultFileImpl fh = (hdr as HeaderImpl)?.FileHandle; + FileStream fh = (hdr as HeaderImpl)?.FileHandle; if (fh == null) return Error.MSPACK_ERR_ARGS; @@ -164,7 +165,7 @@ namespace LibMSPackSharp.SZDD return self.Error = Error.MSPACK_ERR_SEEK; // Open file for output - DefaultFileImpl outfh; + FileStream outfh; if ((outfh = sys.Open(filename, OpenMode.MSPACK_SYS_OPEN_WRITE)) == null) return self.Error = Error.MSPACK_ERR_OPEN; diff --git a/BurnOutSharp/External/libmspack/SystemImpl.cs b/BurnOutSharp/External/libmspack/SystemImpl.cs index 9938c561..a672b805 100644 --- a/BurnOutSharp/External/libmspack/SystemImpl.cs +++ b/BurnOutSharp/External/libmspack/SystemImpl.cs @@ -50,40 +50,33 @@ namespace LibMSPackSharp /// /// One of the values /// - /// A pointer to a DefaultFileImpl structure. This structure officially + /// A pointer to a FileStream structure. This structure officially /// contains no members, its true contents are up to the /// SystemImpl implementor. It should contain whatever is needed /// for other SystemImpl methods to operate. Returning the null /// pointer indicates an error condition. /// - public DefaultFileImpl Open(string filename, OpenMode mode) + public FileStream Open(string filename, OpenMode mode) { try { - DefaultFileImpl fileHandle = new DefaultFileImpl(); switch (mode) { case OpenMode.MSPACK_SYS_OPEN_READ: - fileHandle.FileHandle = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - break; + return File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); case OpenMode.MSPACK_SYS_OPEN_WRITE: - fileHandle.FileHandle = File.Open(filename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); - break; + return File.Open(filename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite); case OpenMode.MSPACK_SYS_OPEN_UPDATE: - fileHandle.FileHandle = File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); - break; + return File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite); case OpenMode.MSPACK_SYS_OPEN_APPEND: - fileHandle.FileHandle = File.Open(filename, FileMode.Append, FileAccess.ReadWrite, FileShare.ReadWrite); - break; + return File.Open(filename, FileMode.Append, FileAccess.ReadWrite, FileShare.ReadWrite); default: return null; } - - return fileHandle; } catch (Exception ex) { @@ -98,7 +91,7 @@ namespace LibMSPackSharp /// /// the file to close /// - public void Close(DefaultFileImpl file) => file?.FileHandle?.Close(); + public void Close(FileStream file) => file?.Close(); /// /// Reads a given number of bytes from an open file. @@ -115,7 +108,7 @@ namespace LibMSPackSharp /// /// /// - public Func Read; + public Func Read; /// /// Writes a given number of bytes to an open file. @@ -132,7 +125,7 @@ namespace LibMSPackSharp /// /// /// - public Func Write; + public Func Write; /// /// Seeks to a specific file offset within an open file. @@ -152,8 +145,8 @@ namespace LibMSPackSharp /// One of the values /// zero for success, non-zero for an error /// - /// - public bool Seek(DefaultFileImpl self, long offset, SeekMode mode) + /// + public bool Seek(FileStream self, long offset, SeekMode mode) { if (self == null) return false; @@ -161,15 +154,15 @@ namespace LibMSPackSharp switch (mode) { case SeekMode.MSPACK_SYS_SEEK_START: - try { self.FileHandle.Seek(offset, SeekOrigin.Begin); return true; } + try { self.Seek(offset, SeekOrigin.Begin); return true; } catch { return false; } case SeekMode.MSPACK_SYS_SEEK_CUR: - try { self.FileHandle.Seek(offset, SeekOrigin.Current); return true; } + try { self.Seek(offset, SeekOrigin.Current); return true; } catch { return false; } case SeekMode.MSPACK_SYS_SEEK_END: - try { self.FileHandle.Seek(offset, SeekOrigin.End); return true; } + try { self.Seek(offset, SeekOrigin.End); return true; } catch { return false; } default: @@ -183,8 +176,8 @@ namespace LibMSPackSharp /// the file whose file position is wanted /// the current file position of the file /// - /// - public long Tell(DefaultFileImpl self) => (self != null ? self.FileHandle.Position : 0); + /// + public long Tell(FileStream self) => self?.Position ?? 0; /// /// Used to send messages from the library to the user. @@ -200,7 +193,7 @@ namespace LibMSPackSharp /// /// a printf() style format string. It does NOT include a trailing newline. /// - public void Message(DefaultFileImpl file, string format) + public void Message(FileStream file, string format) { if (file != null) Console.Error.Write($"{file.Name}: "); @@ -213,11 +206,11 @@ namespace LibMSPackSharp /// /// Returns the length of a file opened for reading /// - public Error GetFileLength(DefaultFileImpl file, out long length) + public Error GetFileLength(FileStream file, out long length) { try { - length = file?.FileHandle?.Length ?? 0; + length = file?.Length ?? 0; return Error.MSPACK_ERR_OK; } catch @@ -247,10 +240,10 @@ namespace LibMSPackSharp private static int DefaultRead(object file, byte[] buffer, int pointer, int bytes) { - DefaultFileImpl self = file as DefaultFileImpl; + FileStream self = file as FileStream; if (self != null && buffer != null && bytes >= 0) { - try { return self.FileHandle.Read(buffer, pointer, bytes); } + try { return self.Read(buffer, pointer, bytes); } catch { } } @@ -259,10 +252,10 @@ namespace LibMSPackSharp private static int DefaultWrite(object file, byte[] buffer, int pointer, int bytes) { - DefaultFileImpl self = file as DefaultFileImpl; + FileStream self = file as FileStream; if (self != null && buffer != null && bytes >= 0) { - try { self.FileHandle.Write(buffer, pointer, bytes); } + try { self.Write(buffer, pointer, bytes); } catch { return -1; } return bytes; }