"as" not "cast"

This commit is contained in:
Matt Nadareski
2022-05-19 11:56:38 -07:00
parent 7e100a261c
commit c54181e9ac
14 changed files with 100 additions and 146 deletions

View File

@@ -1,58 +0,0 @@
/* This file is part of libmspack.
* (C) 2003-2018 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;
namespace LibMSPackSharp.CAB
{
public class DataBlockHeader
{
#region Fields
/// <summary>
/// CRC32 checksum of the data
/// </summary>
public uint Checksum { get; private set; }
/// <summary>
/// Compressed size of the data
/// </summary>
public ushort CompressedSize { get; private set; }
/// <summary>
/// Uncompressed size of the data
/// </summary>
public ushort UncompressedSize { get; private set; }
#endregion
/// <summary>
/// Private constructor
/// </summary>
private DataBlockHeader() { }
/// <summary>
/// Constructor
/// </summary>
public static Error Create(byte[] data, out DataBlockHeader header)
{
header = null;
if (data == null || data.Length < 0x08)
return Error.MSPACK_ERR_READ;
header = new DataBlockHeader();
header.Checksum = BitConverter.ToUInt32(data, 0x00);
header.CompressedSize = BitConverter.ToUInt16(data, 0x04);
header.UncompressedSize = BitConverter.ToUInt16(data, 0x06);
return Error.MSPACK_ERR_OK;
}
}
}

View File

@@ -23,8 +23,8 @@ namespace LibMSPackSharp.CAB
///
/// All fields are READ ONLY.
/// </summary>
/// <see cref="mspack_create_cab_decompressor()"/>
/// <see cref="mspack_destroy_cab_decompressor()"/>
/// <see cref="Library.CreateCABDecompressor(SystemImpl)"/>
/// <see cref="Library.DestroyCABDecompressor(Decompressor)"/>
public class Decompressor
{
/// <summary>

View File

@@ -142,7 +142,7 @@ namespace LibMSPackSharp.CAB
/// </summary>
public static CabinetImpl Open(Decompressor d, string filename)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
CabinetImpl cab = null;
if (self == null)
@@ -181,7 +181,7 @@ namespace LibMSPackSharp.CAB
/// </summary>
public static void Close(Decompressor d, Cabinet origcab)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
FolderData dat, ndat;
Cabinet cab, ncab;
@@ -222,7 +222,7 @@ namespace LibMSPackSharp.CAB
}
// Free folder data segments
for (dat = ((FolderImpl)fol).Data.Next; dat != null; dat = ndat)
for (dat = (fol as FolderImpl).Data.Next; dat != null; dat = ndat)
{
ndat = dat.Next;
sys.Free(dat);
@@ -472,7 +472,7 @@ namespace LibMSPackSharp.CAB
file.Folder = ifol;
// Set "merge next" pointer
fol = (FolderImpl)ifol;
fol = ifol as FolderImpl;
if (fol.MergeNext == null)
fol.MergeNext = file;
}
@@ -483,7 +483,7 @@ namespace LibMSPackSharp.CAB
file.Folder = cab.Folders;
// Set "merge prev" pointer
fol = (FolderImpl)file.Folder;
fol = file.Folder as FolderImpl;
if (fol.MergePrev == null)
fol.MergePrev = file;
}
@@ -594,7 +594,7 @@ namespace LibMSPackSharp.CAB
/// </summary>
public static Cabinet Search(Decompressor d, string filename)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
if (self == null)
return null;
@@ -839,7 +839,7 @@ namespace LibMSPackSharp.CAB
/// </summary>
public static Error Merge(Decompressor d, Cabinet lcab, Cabinet rcab)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
FolderData data, ndata;
FolderImpl lfol, rfol;
@@ -891,11 +891,11 @@ namespace LibMSPackSharp.CAB
sys.Message(null, "WARNING; merged cabinets with odd order.");
// Merging the last folder in lcab with the first folder in rcab
lfol = (FolderImpl)lcab.Folders;
rfol = (FolderImpl)rcab.Folders;
lfol = lcab.Folders as FolderImpl;
rfol = rcab.Folders as FolderImpl;
while (lfol.Next != null)
{
lfol = (FolderImpl)lfol.Next;
lfol = lfol.Next as FolderImpl;
}
// Do we need to merge folders?
@@ -1086,7 +1086,7 @@ namespace LibMSPackSharp.CAB
/// </summary>
public static Error Extract(Decompressor d, InternalFile file, string filename)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
object fh;
if (self == null)
@@ -1095,7 +1095,7 @@ namespace LibMSPackSharp.CAB
return self.Error = Error.MSPACK_ERR_ARGS;
SystemImpl sys = self.System;
FolderImpl fol = (FolderImpl)file.Folder;
FolderImpl fol = file.Folder as FolderImpl;
// If offset is beyond 2GB, nothing can be extracted
if (file.Offset > CAB_LENGTHMAX)
@@ -1278,19 +1278,19 @@ namespace LibMSPackSharp.CAB
switch (self.State.CompressionType & CompressionType.COMPTYPE_MASK)
{
case CompressionType.COMPTYPE_NONE:
NoneFree((NoneState)self.State.DecompressorState);
NoneFree(self.State.DecompressorState);
break;
case CompressionType.COMPTYPE_MSZIP:
MSZIP.Free((MSZIPDStream)self.State.DecompressorState);
MSZIP.Free(self.State.DecompressorState);
break;
case CompressionType.COMPTYPE_QUANTUM:
QTM.Free((QTMDStream)self.State.DecompressorState);
QTM.Free(self.State.DecompressorState);
break;
case CompressionType.COMPTYPE_LZX:
LZX.Free((LZXDStream)self.State.DecompressorState);
LZX.Free(self.State.DecompressorState);
break;
}
@@ -1309,7 +1309,7 @@ namespace LibMSPackSharp.CAB
/// </summary>
private static int SysRead(object file, byte[] buffer, int pointer, int bytes)
{
DecompressorImpl self = (DecompressorImpl)file;
DecompressorImpl self = file as DecompressorImpl;
SystemImpl sys = self.System;
int avail, todo, outlen = 0;
@@ -1370,7 +1370,7 @@ namespace LibMSPackSharp.CAB
{
// Special LZX hack -- on the last block, inform LZX of the
// size of the output data stream.
LZX.SetOutputLength((LZXDStream)self.State.DecompressorState, self.State.Outlen);
LZX.SetOutputLength(self.State.DecompressorState as LZXDStream, self.State.Outlen);
}
}
}
@@ -1387,7 +1387,7 @@ namespace LibMSPackSharp.CAB
/// </summary>
private static int SysWrite(object file, byte[] buffer, int pointer, int bytes)
{
DecompressorImpl self = (DecompressorImpl)file;
DecompressorImpl self = file as DecompressorImpl;
self.State.Offset += (uint)bytes;
if (self.State.OutputFileHandle != null)
return self.System.Write(self.State.OutputFileHandle, buffer, pointer, bytes);
@@ -1576,7 +1576,7 @@ namespace LibMSPackSharp.CAB
internal static void NoneFree(object s)
{
NoneState state = (NoneState)s;
NoneState state = s as NoneState;
if (state != null)
{
SystemImpl sys = state.Sys;
@@ -1594,7 +1594,7 @@ namespace LibMSPackSharp.CAB
/// </summary>
public static Error Param(Decompressor d, Parameters param, int value)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
if (self == null)
return Error.MSPACK_ERR_ARGS;
@@ -1638,7 +1638,7 @@ namespace LibMSPackSharp.CAB
/// </summary>
public static Error LastError(Decompressor d)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
return (self != null) ? self.Error : Error.MSPACK_ERR_ARGS;
}

View File

@@ -144,7 +144,7 @@ namespace LibMSPackSharp.CHM
/// </summary>
private static Header RealOpen(Decompressor d, string filename, bool entire)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
Header chm = null;
if (d == null)
@@ -194,7 +194,7 @@ namespace LibMSPackSharp.CHM
/// </summary>
public static void Close(Decompressor d, Header chm)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
DecompressFile fi, nfi;
uint i;
@@ -529,7 +529,7 @@ namespace LibMSPackSharp.CHM
fi.Next = null;
fi.Filename = Encoding.UTF8.GetString(chunk, name, (int)nameLen) + "\0";
fi.Section = (section == 0) ? (Section)chm.Sec0 : (Section)chm.Sec1;
fi.Section = (section == 0) ? chm.Sec0 as Section : chm.Sec1 as Section;
fi.Offset = offset;
fi.Length = length;
@@ -590,7 +590,7 @@ namespace LibMSPackSharp.CHM
/// </summary>
public static Error FastFind(Decompressor d, Header chm, string filename, DecompressFile f_ptr)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
SystemImpl sys;
object fh;
@@ -682,7 +682,7 @@ namespace LibMSPackSharp.CHM
sec = (uint)((sec << 7) | (chunk[p] & 0x7F));
} while ((chunk[p++] & 0x80) != 0);
f_ptr.Section = (sec == 0) ? (Section)chm.Sec0 : (Section)chm.Sec1;
f_ptr.Section = sec == 0 ? chm.Sec0 as Section : chm.Sec1 as Section;
// READ_ENCINT(f_ptr.Offset)
f_ptr.Offset = 0;
@@ -996,7 +996,7 @@ namespace LibMSPackSharp.CHM
/// </summary>
public static Error Extract(Decompressor d, DecompressFile file, string filename)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
if (self == null)
return Error.MSPACK_ERR_ARGS;
@@ -1154,7 +1154,7 @@ namespace LibMSPackSharp.CHM
/// </summary>
private static int SysWrite(object file, byte[] buffer, int offset, int bytes)
{
DecompressorImpl self = (DecompressorImpl)file;
DecompressorImpl self = file as DecompressorImpl;
self.State.Offset += bytes;
if (self.State.OutputFileHandle != null)
return self.System.Write(self.State.OutputFileHandle, buffer, offset, bytes);
@@ -1175,10 +1175,9 @@ namespace LibMSPackSharp.CHM
{
int window_size, window_bits, reset_interval, entry;
SystemImpl sys = self.System;
MSCompressedSection sec;
byte[] data;
sec = (MSCompressedSection)file.Section;
MSCompressedSection sec = file.Section as MSCompressedSection;
// Ensure we have a mscompressed content section
DecompressFile contentFile = null;
@@ -1531,7 +1530,7 @@ namespace LibMSPackSharp.CHM
/// <returns></returns>
public static Error LastError(Decompressor d)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
return (self != null ? self.Error : Error.MSPACK_ERR_ARGS);
}

View File

@@ -9,7 +9,7 @@
namespace LibMSPackSharp.Compression
{
public class des
public class DES
{
}
}

View File

@@ -426,7 +426,7 @@ namespace LibMSPackSharp.Compression
/// <returns>an error code, or MSPACK_ERR_OK if successful</returns>
public static Error Decompress(object o, long outBytes)
{
LZXDStream lzx = (LZXDStream)o;
LZXDStream lzx = o as LZXDStream;
if (lzx == null)
return Error.MSPACK_ERR_ARGS;
@@ -1055,8 +1055,9 @@ namespace LibMSPackSharp.Compression
/// system.free() using the system pointer given in lzxd_init().
/// </summary>
/// <param name="lzx">LZX decompression state to free.</param>
public static void Free(LZXDStream lzx)
public static void Free(object s)
{
LZXDStream lzx = s as LZXDStream;
if (lzx != null)
{
SystemImpl sys = lzx.Sys;

View File

@@ -162,7 +162,7 @@ namespace LibMSPackSharp.Compression
/// </summary>
public static Error Decompress(object o, long out_bytes)
{
MSZIPDStream zip = (MSZIPDStream)o;
MSZIPDStream zip = o as MSZIPDStream;
if (zip == null)
return Error.MSPACK_ERR_ARGS;
@@ -328,8 +328,9 @@ namespace LibMSPackSharp.Compression
///
/// - calls system.free() using the system pointer given in mszipd_init()
/// </summary>
public static void Free(MSZIPDStream zip)
public static void Free(object s)
{
MSZIPDStream zip = s as MSZIPDStream;
if (zip != null)
{
SystemImpl sys = zip.Sys;

View File

@@ -171,7 +171,7 @@ namespace LibMSPackSharp.Compression
/// </summary>
public static Error Decompress(object o, long out_bytes)
{
QTMDStream qtm = (QTMDStream)o;
QTMDStream qtm = o as QTMDStream;
if (qtm == null)
return Error.MSPACK_ERR_ARGS;
@@ -466,8 +466,9 @@ namespace LibMSPackSharp.Compression
/// Frees all state associated with a Quantum data stream
/// - calls system.free() using the system pointer given in qtmd_init()
/// </summary>
public static void Free(QTMDStream qtm)
public static void Free(object s)
{
QTMDStream qtm = s as QTMDStream;
if (qtm != null)
{
SystemImpl sys = qtm.Sys;
@@ -489,28 +490,28 @@ namespace LibMSPackSharp.Compression
ref int i_ptr, ref int i_end, ref uint bit_buffer, ref uint bits_left)
{
range = (uint)(((high - low) & 0xFFFF) + 1);
symf = (ushort)(((((current - low + 1) * model.Syms[0].CumFreq) - 1) / range) & 0xFFFF);
symf = (ushort)(((((current - low + 1) * model.Syms[0].CumulativeFrequency) - 1) / range) & 0xFFFF);
int i;
for (i = 1; i < model.Entries; i++)
{
if (model.Syms[i].CumFreq <= symf)
if (model.Syms[i].CumulativeFrequency <= symf)
break;
}
var = model.Syms[i - 1].Sym;
range = (ushort)((high - low) + 1);
symf = model.Syms[0].CumFreq;
high = (ushort)(low + ((model.Syms[i - 1].CumFreq * range) / symf) - 1);
low = (ushort)(low + ((model.Syms[i].CumFreq * range) / symf));
symf = model.Syms[0].CumulativeFrequency;
high = (ushort)(low + ((model.Syms[i - 1].CumulativeFrequency * range) / symf) - 1);
low = (ushort)(low + ((model.Syms[i].CumulativeFrequency * range) / symf));
do
{
model.Syms[--i].CumFreq += 8;
model.Syms[--i].CumulativeFrequency += 8;
} while (i > 0);
if (model.Syms[0].CumFreq > 3800)
if (model.Syms[0].CumulativeFrequency > 3800)
UpdateModel(model);
while (true)
@@ -548,10 +549,10 @@ namespace LibMSPackSharp.Compression
for (i = model.Entries - 1; i >= 0; i--)
{
/* -1, not -2; the 0 entry saves this */
model.Syms[i].CumFreq >>= 1;
if (model.Syms[i].CumFreq <= model.Syms[i + 1].CumFreq)
model.Syms[i].CumulativeFrequency >>= 1;
if (model.Syms[i].CumulativeFrequency <= model.Syms[i + 1].CumulativeFrequency)
{
model.Syms[i].CumFreq = (ushort)(model.Syms[i + 1].CumFreq + 1);
model.Syms[i].CumulativeFrequency = (ushort)(model.Syms[i + 1].CumulativeFrequency + 1);
}
}
}
@@ -563,9 +564,9 @@ namespace LibMSPackSharp.Compression
// No -1, want to include the 0 entry
// This converts CumFreqs into frequencies, then shifts right
model.Syms[i].CumFreq -= model.Syms[i + 1].CumFreq;
model.Syms[i].CumFreq++; // Avoid losing things entirely
model.Syms[i].CumFreq >>= 1;
model.Syms[i].CumulativeFrequency -= model.Syms[i + 1].CumulativeFrequency;
model.Syms[i].CumulativeFrequency++; // Avoid losing things entirely
model.Syms[i].CumulativeFrequency >>= 1;
}
// Now sort by frequencies, decreasing order -- this must be an
@@ -575,7 +576,7 @@ namespace LibMSPackSharp.Compression
{
for (j = i + 1; j < model.Entries; j++)
{
if (model.Syms[i].CumFreq < model.Syms[j].CumFreq)
if (model.Syms[i].CumulativeFrequency < model.Syms[j].CumulativeFrequency)
{
tmp = model.Syms[i];
model.Syms[i] = model.Syms[j];
@@ -587,7 +588,7 @@ namespace LibMSPackSharp.Compression
// Then convert frequencies back to CumFreq
for (i = model.Entries - 1; i >= 0; i--)
{
model.Syms[i].CumFreq += model.Syms[i + 1].CumFreq;
model.Syms[i].CumulativeFrequency += model.Syms[i + 1].CumulativeFrequency;
}
}
}
@@ -604,7 +605,7 @@ namespace LibMSPackSharp.Compression
syms[i].Sym = (ushort)(start + i);
// Current frequency of that symbol
syms[i].CumFreq = (ushort)(len - i);
syms[i].CumulativeFrequency = (ushort)(len - i);
}
}
}

View File

@@ -16,6 +16,6 @@ namespace LibMSPackSharp.Compression
{
public ushort Sym { get; set; }
public ushort CumFreq { get; set; }
public ushort CumulativeFrequency { get; set; }
}
}

View File

@@ -109,7 +109,7 @@ namespace LibMSPackSharp.KWAJ
/// </summary>
public static Header Open(Decompressor d, string filename)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
if (self == null)
return null;
@@ -151,10 +151,10 @@ namespace LibMSPackSharp.KWAJ
/// </summary>
public static void Close(Decompressor d, Header hdr)
{
DecompressorImpl self = (DecompressorImpl)d;
HeaderImpl hdr_p = (HeaderImpl)hdr;
DecompressorImpl self = d as DecompressorImpl;
HeaderImpl hdr_p = hdr as HeaderImpl;
if (self == null || self.System == null)
if (self?.System == null || hdr_p == null)
return;
// Close the file handle associated
@@ -319,14 +319,16 @@ namespace LibMSPackSharp.KWAJ
/// </summary>
public static Error Extract(Decompressor d, Header hdr, string filename)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
if (self == null)
return Error.MSPACK_ERR_ARGS;
if (hdr == null)
return self.Error = Error.MSPACK_ERR_ARGS;
SystemImpl sys = self.System;
object fh = ((HeaderImpl)hdr).FileHandle;
object fh = (hdr as HeaderImpl)?.FileHandle;
if (fh == null)
return Error.MSPACK_ERR_ARGS;
// Seek to the compressed data
if (sys.Seek(fh, hdr.DataOffset, SeekMode.MSPACK_SYS_SEEK_START))
@@ -405,7 +407,7 @@ namespace LibMSPackSharp.KWAJ
/// </summary>
public static Error Decompress(Decompressor d, string input, string output)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
if (self == null)
return Error.MSPACK_ERR_ARGS;
@@ -427,7 +429,7 @@ namespace LibMSPackSharp.KWAJ
/// </summary>
public static Error LastError(Decompressor d)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
return (self != null) ? self.Error : Error.MSPACK_ERR_ARGS;
}

View File

@@ -196,7 +196,7 @@ namespace LibMSPackSharp
/// <param name="d">the <see cref="CAB.Decompressor"/> to destroy</param>
public static void DestroyCABDecompressor(CAB.Decompressor d)
{
CAB.DecompressorImpl self = (CAB.DecompressorImpl)d;
CAB.DecompressorImpl self = d as CAB.DecompressorImpl;
if (self != null)
{
SystemImpl sys = self.System;
@@ -269,7 +269,7 @@ namespace LibMSPackSharp
/// <param name="d">the <see cref="CHM.Decompressor"/> to destroy</param>
public static void DestroyCHMDecompressor(CHM.Decompressor d)
{
CHM.DecompressorImpl self = (CHM.DecompressorImpl)d;
CHM.DecompressorImpl self = d as CHM.DecompressorImpl;
if (self != null)
{
SystemImpl sys = self.System;
@@ -429,7 +429,7 @@ namespace LibMSPackSharp
/// <param name="d">the <see cref="SZDD.Decompressor"/> to destroy</param>
public static void DestroySZDDDecompressor(SZDD.Decompressor d)
{
SZDD.DecompressorImpl self = (SZDD.DecompressorImpl)d;
SZDD.DecompressorImpl self = d as SZDD.DecompressorImpl;
if (self != null)
{
SystemImpl sys = self.System;
@@ -491,7 +491,7 @@ namespace LibMSPackSharp
/// <param name="d">the <see cref="KWAJ.Decompressor"/> to destroy</param>
public static void DestroyKWAJDecompressor(KWAJ.Decompressor d)
{
KWAJ.DecompressorImpl self = (KWAJ.DecompressorImpl)d;
KWAJ.DecompressorImpl self = d as KWAJ.DecompressorImpl;
if (self != null)
{
SystemImpl sys = self.System;
@@ -551,7 +551,7 @@ namespace LibMSPackSharp
/// <param name="d">the <see cref="OAB.Decompressor"/> to destroy</param>
public static void DestroyOABDecompressor(OAB.Decompressor d)
{
OAB.DecompressorImpl self = (OAB.DecompressorImpl)d;
OAB.DecompressorImpl self = d as OAB.DecompressorImpl;
if (self != null)
{
SystemImpl sys = self.System;

View File

@@ -62,7 +62,10 @@ namespace LibMSPackSharp.OAB
private static int SysRead(object baseFile, byte[] buf, int pointer, int size)
{
InternalFile file = (InternalFile)baseFile;
InternalFile file = baseFile as InternalFile;
if (file == null)
return 0;
int bytes_read;
if (size > file.Available)
@@ -82,7 +85,10 @@ namespace LibMSPackSharp.OAB
private static int SysWrite(object baseFile, byte[] buf, int pointer, int size)
{
InternalFile file = (InternalFile)baseFile;
InternalFile file = baseFile as InternalFile;
if (file == null)
return 0;
int bytes_written = file.OrigSys.Write(file.OrigFile, buf, pointer, size);
if (bytes_written > 0)
@@ -97,7 +103,7 @@ namespace LibMSPackSharp.OAB
public static Error Decompress(Decompressor d, string input, string output)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
byte[] hdrbuf = new byte[oabhead_SIZEOF];
LZXDStream lzx = null;
Error ret = Error.MSPACK_ERR_OK;
@@ -332,7 +338,7 @@ namespace LibMSPackSharp.OAB
public static Error DecompressIncremental(Decompressor d, string input, string basePath, string output)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
byte[] hdrbuf = new byte[patchhead_SIZEOF];
LZXDStream lzx = null;
int window_bits;
@@ -604,7 +610,7 @@ namespace LibMSPackSharp.OAB
public static Error Param(Decompressor d, Parameters param, int value)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
if (self != null && param == Parameters.MSOABD_PARAM_DECOMPBUF && value >= 16)
{
// must be at least 16 bytes (patchblk_SIZEOF, oabblk_SIZEOF)

View File

@@ -27,7 +27,7 @@ namespace LibMSPackSharp.SZDD
/// </summary>
public static Header Open(Decompressor d, string filename)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
if (self == null)
return null;
@@ -69,10 +69,10 @@ namespace LibMSPackSharp.SZDD
/// </summary>
public static void Close(Decompressor d, Header hdr)
{
DecompressorImpl self = (DecompressorImpl)d;
HeaderImpl hdr_p = (HeaderImpl)hdr;
DecompressorImpl self = d as DecompressorImpl;
HeaderImpl hdr_p = hdr as HeaderImpl;
if (self == null || self.System == null)
if (self?.System == null || hdr == null)
return;
// Close the file handle associated
@@ -150,7 +150,7 @@ namespace LibMSPackSharp.SZDD
/// </summary>
public static Error Extract(Decompressor d, Header hdr, string filename)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
if (self == null)
return Error.MSPACK_ERR_ARGS;
if (hdr == null)
@@ -158,7 +158,9 @@ namespace LibMSPackSharp.SZDD
SystemImpl sys = self.System;
object fh = ((HeaderImpl)hdr).FileHandle;
object fh = (hdr as HeaderImpl)?.FileHandle;
if (fh == null)
return Error.MSPACK_ERR_ARGS;
// Seek to the compressed data
long dataOffset = (hdr.Format == Format.MSSZDD_FMT_NORMAL) ? 14 : 12;
@@ -195,7 +197,7 @@ namespace LibMSPackSharp.SZDD
/// </summary>
public static Error Decompress(Decompressor d, string input, string output)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
if (self == null)
return Error.MSPACK_ERR_ARGS;
@@ -217,7 +219,7 @@ namespace LibMSPackSharp.SZDD
/// </summary>
public static Error LastError(Decompressor d)
{
DecompressorImpl self = (DecompressorImpl)d;
DecompressorImpl self = d as DecompressorImpl;
return (self != null) ? self.Error : Error.MSPACK_ERR_ARGS;
}

View File

@@ -261,19 +261,19 @@ namespace LibMSPackSharp
switch (mode)
{
case OpenMode.MSPACK_SYS_OPEN_READ:
fileHandle.FileHandle = File.Open(filename, FileMode.Open, FileAccess.Read);
fileHandle.FileHandle = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
break;
case OpenMode.MSPACK_SYS_OPEN_WRITE:
fileHandle.FileHandle = File.Open(filename, FileMode.Open, FileAccess.Write);
fileHandle.FileHandle = File.Open(filename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite);
break;
case OpenMode.MSPACK_SYS_OPEN_UPDATE:
fileHandle.FileHandle = File.Open(filename, FileMode.Open, FileAccess.ReadWrite);
fileHandle.FileHandle = File.Open(filename, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
break;
case OpenMode.MSPACK_SYS_OPEN_APPEND:
fileHandle.FileHandle = File.Open(filename, FileMode.Append);
fileHandle.FileHandle = File.Open(filename, FileMode.Append, FileAccess.ReadWrite, FileShare.ReadWrite);
break;
default: