diff --git a/SabreTools.Serialization/Models/CDROM/DataTrack.cs b/SabreTools.Serialization/Models/CDROM/DataTrack.cs index 982f0f30..95bf5cbf 100644 --- a/SabreTools.Serialization/Models/CDROM/DataTrack.cs +++ b/SabreTools.Serialization/Models/CDROM/DataTrack.cs @@ -16,6 +16,6 @@ namespace SabreTools.Data.Models.CDROM /// /// ISO9660 volume within the data track /// - public Volume Volume { get; set; } + public Volume Volume { get; set; } = new(); } } diff --git a/SabreTools.Serialization/Readers/CDROMVolume.cs b/SabreTools.Serialization/Readers/CDROMVolume.cs index e16c489e..73874b57 100644 --- a/SabreTools.Serialization/Readers/CDROMVolume.cs +++ b/SabreTools.Serialization/Readers/CDROMVolume.cs @@ -58,7 +58,7 @@ namespace SabreTools.Serialization.Readers /// /// Stream to parse /// Filled byte[] on success, null on error - public static byte[]? ParseCDROMSystemArea(Stream data) + public static byte[] ParseCDROMSystemArea(Stream data) { var systemArea = new byte[Constants.SystemAreaSectors * Constants.MinimumSectorSize]; // Process in sectors diff --git a/SabreTools.Serialization/SabreTools.Serialization.csproj b/SabreTools.Serialization/SabreTools.Serialization.csproj index 0132febc..96eab79e 100644 --- a/SabreTools.Serialization/SabreTools.Serialization.csproj +++ b/SabreTools.Serialization/SabreTools.Serialization.csproj @@ -8,8 +8,6 @@ false true latest - - CS8600;CS8601;CS8603;CS8604;CS8618;CS8625;CS8634;IL3000 enable true snupkg @@ -43,18 +41,7 @@ net6.0;net7.0;net8.0;net9.0 - - - - $(DefaultItemExcludes); - **\AssemblyInfo.cs; - _EXTERNAL\stormlibsharp\lib\**; - _EXTERNAL\stormlibsharp\src\CascLibSharp\**; - _EXTERNAL\stormlibsharp\src\TestConsole\** - - - - + $(DefaultItemExcludes); diff --git a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascApi.cs b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascApi.cs index d3e1390b..92d2ca7b 100644 --- a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascApi.cs +++ b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascApi.cs @@ -1,13 +1,9 @@ -using CascLibSharp.Native; -using System; -using System.Collections.Generic; +using System; using System.ComponentModel; using System.IO; -using System.Linq; using System.Reflection; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; +using CascLibSharp.Native; namespace CascLibSharp { @@ -30,7 +26,7 @@ namespace CascLibSharp ref uint pcbLengthNeeded); [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Winapi)] - internal delegate bool FnCascCloseStorage( IntPtr hStorage); + internal delegate bool FnCascCloseStorage(IntPtr hStorage); [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Winapi)] @@ -73,14 +69,14 @@ namespace CascLibSharp out uint dwRead); [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Winapi)] - internal delegate bool FnCascCloseFile( IntPtr hFile); + internal delegate bool FnCascCloseFile(IntPtr hFile); [UnmanagedFunctionPointer(CallingConvention.Winapi)] internal delegate CascFileEnumerationSafeHandle FnCascFindFirstFile( CascStorageSafeHandle hStorage, [MarshalAs(UnmanagedType.LPStr)] string szMask, ref CascFindData pFindData, - [MarshalAs(UnmanagedType.LPTStr)] string szListFile); + [MarshalAs(UnmanagedType.LPTStr)] string? szListFile); [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Winapi)] internal delegate bool FnCascFindNextFile( @@ -88,28 +84,28 @@ namespace CascLibSharp ref CascFindData pFindData); [return: MarshalAs(UnmanagedType.I1)] [UnmanagedFunctionPointer(CallingConvention.Winapi)] - internal delegate bool FnCascFindClose( IntPtr hFind); + internal delegate bool FnCascFindClose(IntPtr hFind); #endregion #region Field and method defs - public readonly FnCascOpenStorage CascOpenStorage; - public readonly FnCascGetStorageInfo CascGetStorageInfo; - public readonly FnCascCloseStorage CascCloseStorage; + public readonly FnCascOpenStorage? CascOpenStorage; + public readonly FnCascGetStorageInfo? CascGetStorageInfo; + public readonly FnCascCloseStorage? CascCloseStorage; - public readonly FnCascOpenFileByIndexKey CascOpenFileByIndexKey; - public readonly FnCascOpenFileByEncodingKey CascOpenFileByEncodingKey; - public readonly FnCascOpenFile CascOpenFile; + public readonly FnCascOpenFileByIndexKey? CascOpenFileByIndexKey; + public readonly FnCascOpenFileByEncodingKey? CascOpenFileByEncodingKey; + public readonly FnCascOpenFile? CascOpenFile; - public readonly FnCascGetFileSize CascGetFileSizeBase; + public readonly FnCascGetFileSize? CascGetFileSizeBase; public long CascGetFileSize(CascStorageFileSafeHandle hFile) { uint high; - uint low = CascGetFileSizeBase(hFile, out high); + uint low = CascGetFileSizeBase!(hFile, out high); long result = (high << 32) | low; return result; } - public readonly FnCascSetFilePointer CascSetFilePointerBase; + public readonly FnCascSetFilePointer? CascSetFilePointerBase; public long CascSetFilePointer(CascStorageFileSafeHandle hFile, long filePos, SeekOrigin moveMethod) { uint low, high; @@ -119,18 +115,18 @@ namespace CascLibSharp high = (uint)(((ulong)filePos & 0xffffffff00000000) >> 32); } - low = CascSetFilePointerBase(hFile, low, ref high, moveMethod); + low = CascSetFilePointerBase!(hFile, low, ref high, moveMethod); long result = (high << 32) | low; return result; } - public readonly FnCascReadFile CascReadFile; - public readonly FnCascCloseFile CascCloseFile; + public readonly FnCascReadFile? CascReadFile; + public readonly FnCascCloseFile? CascCloseFile; - public readonly FnCascFindFirstFile CascFindFirstFile; - public readonly FnCascFindNextFile CascFindNextFile; - public readonly FnCascFindClose CascFindClose; + public readonly FnCascFindFirstFile? CascFindFirstFile; + public readonly FnCascFindNextFile? CascFindNextFile; + public readonly FnCascFindClose? CascFindClose; #endregion internal CascApi(IntPtr hModule) @@ -152,7 +148,7 @@ namespace CascLibSharp SetFn(ref CascFindClose, hModule, "CascFindClose"); } - private static void SetFn(ref T target, IntPtr hModule, string procName) + private static void SetFn(ref T? target, IntPtr hModule, string procName) where T : class { IntPtr procAddr = NativeMethods.GetProcAddress(hModule, procName); @@ -164,7 +160,7 @@ namespace CascLibSharp private static CascApi Load() { string myPath = Assembly.GetExecutingAssembly().Location; - string directory = Path.GetDirectoryName(myPath); + string directory = Path.GetDirectoryName(myPath) ?? string.Empty; string arch = IntPtr.Size == 8 ? "x64" : "x86"; #if DEBUG string build = "dbg"; diff --git a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascException.cs b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascException.cs index d6a3dec9..83a94531 100644 --- a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascException.cs +++ b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascException.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; +using System.ComponentModel; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace CascLibSharp { diff --git a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascFileStream.cs b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascFileStream.cs index 2a197720..6f4b46da 100644 --- a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascFileStream.cs +++ b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascFileStream.cs @@ -1,11 +1,7 @@ -using CascLibSharp.Native; -using System; -using System.Collections.Generic; +using System; using System.Diagnostics; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using CascLibSharp.Native; namespace CascLibSharp { @@ -17,13 +13,13 @@ namespace CascLibSharp private CascStorageFileSafeHandle _handle; private CascApi _api; - internal CascFileStream(CascStorageFileSafeHandle handle, CascApi api) + internal CascFileStream(CascStorageFileSafeHandle? handle, CascApi? api) { Debug.Assert(handle != null); - Debug.Assert(!handle.IsInvalid); + Debug.Assert(!handle!.IsInvalid); Debug.Assert(api != null); - _api = api; + _api = api!; _handle = handle; } @@ -72,10 +68,10 @@ namespace CascLibSharp /// Thrown if the Stream has been disposed. public override long Length { - get + get { AssertValidHandle(); - return _api.CascGetFileSize(_handle); + return _api!.CascGetFileSize(_handle); } } @@ -89,12 +85,12 @@ namespace CascLibSharp get { AssertValidHandle(); - return _api.CascSetFilePointer(_handle, 0, SeekOrigin.Current); + return _api!.CascSetFilePointer(_handle, 0, SeekOrigin.Current); } set { AssertValidHandle(); - long result = _api.CascSetFilePointer(_handle, value, SeekOrigin.Begin); + long result = _api!.CascSetFilePointer(_handle, value, SeekOrigin.Begin); if (result != value) throw new CascException(); } @@ -123,7 +119,7 @@ namespace CascLibSharp uint read = 0; fixed (byte* pBuffer = &buffer[0]) { - if (!_api.CascReadFile(_handle, new IntPtr((void*)pBuffer), unchecked((uint)count), out read)) + if (!_api.CascReadFile!(_handle, new IntPtr((void*)pBuffer), unchecked((uint)count), out read)) throw new CascException(); } diff --git a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascFoundFile.cs b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascFoundFile.cs index af3594e4..a7576400 100644 --- a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascFoundFile.cs +++ b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascFoundFile.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace CascLibSharp { @@ -12,9 +8,13 @@ namespace CascLibSharp /// public class CascFoundFile { +#if NET20 || NET35 || NET40 + private WeakReference _ownerContext; +#else private WeakReference _ownerContext; +#endif - internal CascFoundFile(string fileName, IntPtr plainName, byte[] encodingKey, CascLocales locales, long fileSize, CascStorageContext ownerContext) + internal CascFoundFile(string? fileName, IntPtr plainName, byte[] encodingKey, CascLocales locales, long fileSize, CascStorageContext ownerContext) { FileName = fileName; PlainFileName = Marshal.PtrToStringAnsi(plainName); @@ -22,17 +22,21 @@ namespace CascLibSharp Locales = locales; FileSize = fileSize; +#if NET20 || NET35 || NET40 + _ownerContext = new WeakReference(ownerContext); +#else _ownerContext = new WeakReference(ownerContext); +#endif } /// /// Gets the full path to this file. /// - public string FileName { get; private set; } + public string? FileName { get; private set; } /// /// Gets the plain (no directory-qualified) file name of this file. /// - public string PlainFileName { get; private set; } + public string? PlainFileName { get; private set; } /// /// Gets the CASC encoding key for this file. /// @@ -52,9 +56,14 @@ namespace CascLibSharp /// A CascFileStream, which acts as a Stream for a CASC stored file. public CascFileStream Open() { - CascStorageContext context; - if (!_ownerContext.TryGetTarget(out context)) +#if NET20 || NET35 || NET40 + CascStorageContext? context = _ownerContext.Target as CascStorageContext; + if (context == null) throw new ObjectDisposedException("The owning context has been closed."); +#else + if (!_ownerContext.TryGetTarget(out CascStorageContext? context) || context == null) + throw new ObjectDisposedException("The owning context has been closed."); +#endif return context.OpenFileByEncodingKey(EncodingKey); } diff --git a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascStorageContext.cs b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascStorageContext.cs index 7dbae534..27665adb 100644 --- a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascStorageContext.cs +++ b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/CascStorageContext.cs @@ -1,10 +1,6 @@ -using CascLibSharp.Native; -using System; +using System; using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; +using CascLibSharp.Native; namespace CascLibSharp { @@ -14,7 +10,7 @@ namespace CascLibSharp public class CascStorageContext : IDisposable { private CascApi _api; - private CascStorageSafeHandle _handle; + private CascStorageSafeHandle? _handle; private Lazy _hasListfile; private Lazy _clientType; private Lazy _fileCount; @@ -29,7 +25,7 @@ namespace CascLibSharp { _api = CascApi.Instance; - if (!_api.CascOpenStorage(dataPath, 0, out _handle) || _handle.IsInvalid) + if (!_api.CascOpenStorage!(dataPath, 0, out _handle) || _handle.IsInvalid) throw new CascException(); _handle.Api = _api; @@ -53,7 +49,7 @@ namespace CascLibSharp throw new ObjectDisposedException("CascStorageContext"); CascStorageFileSafeHandle hFile; - if (!_api.CascOpenFile(_handle, fileName, (uint)locale, 0, out hFile)) + if (!_api.CascOpenFile!(_handle, fileName, (uint)locale, 0, out hFile)) throw new CascException(); hFile.Api = _api; @@ -65,7 +61,7 @@ namespace CascLibSharp /// Opens a file by its index key. /// /// - /// An index key is a binary representation of a file. I do not know what it comes from; I know that it's used to identify files inside of CASC, + /// An index key is a binary representation of a file. I do not know what it comes from; I know that it's used to identify files inside of CASC, /// but I don't know how someone obtains the index key. They are not produced in the public API of CascLib. /// /// The index key to search. @@ -84,7 +80,7 @@ namespace CascLibSharp qk.pbData = mem.Pointer; CascStorageFileSafeHandle hFile; - if (!_api.CascOpenFileByIndexKey(_handle, ref qk, 0, out hFile)) + if (!_api.CascOpenFileByIndexKey!(_handle, ref qk, 0, out hFile)) throw new CascException(); hFile.Api = _api; @@ -112,7 +108,7 @@ namespace CascLibSharp qk.pbData = mem.Pointer; CascStorageFileSafeHandle hFile; - if (!_api.CascOpenFileByEncodingKey(_handle, ref qk, 0, out hFile)) + if (!_api.CascOpenFileByEncodingKey!(_handle, ref qk, 0, out hFile)) throw new CascException(); hFile.Api = _api; @@ -127,7 +123,7 @@ namespace CascLibSharp /// The mask to search. * and ? are valid tokens for substitution. /// A path to a listfile. Required if the CASC container is for World of Warcraft. /// An enumeration of matching file references in the CASC container. - public IEnumerable SearchFiles(string mask, string listFilePath = null) + public IEnumerable SearchFiles(string mask, string? listFilePath = null) { if (_handle == null || _handle.IsInvalid) throw new ObjectDisposedException("CascStorageContext"); @@ -136,7 +132,7 @@ namespace CascLibSharp throw new ArgumentNullException("listFilePath"); CascFindData cfd = new CascFindData(); - using (var handle = _api.CascFindFirstFile(_handle, mask, ref cfd, listFilePath)) + using (var handle = _api.CascFindFirstFile!(_handle, mask, ref cfd, listFilePath)) { if (handle.IsInvalid) yield break; @@ -145,20 +141,20 @@ namespace CascLibSharp yield return cfd.ToFoundFile(this); - while (_api.CascFindNextFile(handle, ref cfd)) + while (_api.CascFindNextFile!(handle, ref cfd)) { yield return cfd.ToFoundFile(this); } } } - + private bool CheckHasListfile() { if (_handle == null || _handle.IsInvalid) throw new ObjectDisposedException("CascStorageContext"); uint storageInfo = 0, lengthNeeded = 4; - if (!_api.CascGetStorageInfo(_handle, CascStorageInfoClass.Features, ref storageInfo, new IntPtr(4), ref lengthNeeded)) + if (!_api.CascGetStorageInfo!(_handle, CascStorageInfoClass.Features, ref storageInfo, new IntPtr(4), ref lengthNeeded)) throw new CascException(); CascStorageFeatures features = (CascStorageFeatures)storageInfo; @@ -174,7 +170,7 @@ namespace CascLibSharp throw new ObjectDisposedException("CascStorageContext"); uint storageInfo = 0, lengthNeeded = 4; - if (!_api.CascGetStorageInfo(_handle, CascStorageInfoClass.GameInfo, ref storageInfo, new IntPtr(4), ref lengthNeeded)) + if (!_api.CascGetStorageInfo!(_handle, CascStorageInfoClass.GameInfo, ref storageInfo, new IntPtr(4), ref lengthNeeded)) throw new CascException(); CascGameId gameId = (CascGameId)storageInfo; @@ -188,7 +184,7 @@ namespace CascLibSharp throw new ObjectDisposedException("CascStorageContext"); uint storageInfo = 0, lengthNeeded = 4; - if (!_api.CascGetStorageInfo(_handle, CascStorageInfoClass.Features, ref storageInfo, new IntPtr(4), ref lengthNeeded)) + if (!_api.CascGetStorageInfo!(_handle, CascStorageInfoClass.Features, ref storageInfo, new IntPtr(4), ref lengthNeeded)) throw new CascException(); return storageInfo; @@ -200,7 +196,7 @@ namespace CascLibSharp throw new ObjectDisposedException("CascStorageContext"); uint storageInfo = 0, lengthNeeded = 4; - if (!_api.CascGetStorageInfo(_handle, CascStorageInfoClass.Features, ref storageInfo, new IntPtr(4), ref lengthNeeded)) + if (!_api.CascGetStorageInfo!(_handle, CascStorageInfoClass.Features, ref storageInfo, new IntPtr(4), ref lengthNeeded)) throw new CascException(); return unchecked((int)storageInfo); @@ -274,7 +270,7 @@ namespace CascLibSharp /// True if this is being called via the Dispose() method; false if it's being called by the finalizer. protected virtual void Dispose(bool disposing) { - if (disposing) + if (disposing && _handle != null) { if (!_handle.IsInvalid) { diff --git a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CascFileEnumerationSafeHandle.cs b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CascFileEnumerationSafeHandle.cs index a673cf70..41ea1269 100644 --- a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CascFileEnumerationSafeHandle.cs +++ b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CascFileEnumerationSafeHandle.cs @@ -1,9 +1,5 @@ -using Microsoft.Win32.SafeHandles; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System; +using Microsoft.Win32.SafeHandles; namespace CascLibSharp.Native { @@ -11,6 +7,7 @@ namespace CascLibSharp.Native { public CascFileEnumerationSafeHandle() : base(true) { } + public CascFileEnumerationSafeHandle(IntPtr handle) : this() { @@ -20,10 +17,10 @@ namespace CascLibSharp.Native protected override bool ReleaseHandle() { var api = Api ?? CascApi.Instance; - return api.CascFindClose(DangerousGetHandle()); + return api.CascFindClose!(DangerousGetHandle()); } - internal CascApi Api + internal CascApi? Api { get; set; diff --git a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CascStorageFileSafeHandle.cs b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CascStorageFileSafeHandle.cs index b6d2cc67..c72cc2da 100644 --- a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CascStorageFileSafeHandle.cs +++ b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CascStorageFileSafeHandle.cs @@ -1,9 +1,5 @@ -using Microsoft.Win32.SafeHandles; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System; +using Microsoft.Win32.SafeHandles; namespace CascLibSharp.Native { @@ -24,10 +20,10 @@ namespace CascLibSharp.Native protected override bool ReleaseHandle() { var api = Api ?? CascApi.Instance; - return api.CascCloseFile(DangerousGetHandle()); + return api.CascCloseFile!(DangerousGetHandle()); } - internal CascApi Api + internal CascApi? Api { get; set; diff --git a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CascStorageSafeHandle.cs b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CascStorageSafeHandle.cs index 83361901..1360e96a 100644 --- a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CascStorageSafeHandle.cs +++ b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CascStorageSafeHandle.cs @@ -1,9 +1,5 @@ -using Microsoft.Win32.SafeHandles; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System; +using Microsoft.Win32.SafeHandles; namespace CascLibSharp.Native { @@ -24,10 +20,10 @@ namespace CascLibSharp.Native protected override bool ReleaseHandle() { var api = Api ?? CascApi.Instance; - return api.CascCloseStorage(DangerousGetHandle()); + return api.CascCloseStorage!(DangerousGetHandle()); } - internal CascApi Api + internal CascApi? Api { get; set; diff --git a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CoTaskMem.cs b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CoTaskMem.cs index 78ddf58c..361d7654 100644 --- a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CoTaskMem.cs +++ b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/CoTaskMem.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace CascLibSharp.Native { @@ -31,12 +27,12 @@ namespace CascLibSharp.Native public IntPtr Pointer { - get + get { if (_mem == IntPtr.Zero) throw new ObjectDisposedException("CoTaskMem"); - return _mem; + return _mem; } } diff --git a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/NativeMethods.cs b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/NativeMethods.cs index 9bdf9409..1096d05f 100644 --- a/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/NativeMethods.cs +++ b/SabreTools.Serialization/_EXTERNAL/CascLibSharp/Native/NativeMethods.cs @@ -1,10 +1,6 @@ using System; using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace CascLibSharp.Native { @@ -48,7 +44,7 @@ namespace CascLibSharp.Native internal static class GameConverterExtensions { - private static Dictionary GameClientMap = new Dictionary + private static Dictionary GameClientMap = new Dictionary { { CascGameId.Hots, CascKnownClient.HeroesOfTheStorm }, { CascGameId.Wow6, CascKnownClient.WorldOfWarcraft }, @@ -57,7 +53,7 @@ namespace CascLibSharp.Native { CascGameId.Starcraft2, CascKnownClient.Starcraft2 }, }; - private static Dictionary ClientGameMap = new Dictionary() + private static Dictionary ClientGameMap = new Dictionary() { { CascKnownClient.HeroesOfTheStorm, CascGameId.Hots }, { CascKnownClient.WorldOfWarcraft, CascGameId.Wow6 }, @@ -106,7 +102,7 @@ namespace CascLibSharp.Native public unsafe CascFoundFile ToFoundFile(CascStorageContext ownerContext) { - string fileName = null; + string? fileName = null; fixed (void* pFileName = szFileName) { fileName = Marshal.PtrToStringAnsi(new IntPtr(pFileName)); diff --git a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/MpqArchive.cs b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/MpqArchive.cs index 4585dc50..d3866e11 100644 --- a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/MpqArchive.cs +++ b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/MpqArchive.cs @@ -1,23 +1,19 @@ -using StormLibSharp.Native; -using System; +using System; using System.Collections.Generic; using System.ComponentModel; -using System.Globalization; using System.IO; using System.IO.MemoryMappedFiles; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; +using StormLibSharp.Native; namespace StormLibSharp { public class MpqArchive : IDisposable { - private MpqArchiveSafeHandle _handle; + private MpqArchiveSafeHandle? _handle; private List _openFiles = new List(); private FileAccess _accessType; private List _compactCallbacks = new List(); - private SFILE_COMPACT_CALLBACK _compactCallback; + private SFILE_COMPACT_CALLBACK? _compactCallback; #region Constructors / Factories public MpqArchive(string filePath, FileAccess accessType) @@ -37,7 +33,7 @@ namespace StormLibSharp public MpqArchive(MemoryMappedFile file, FileAccess accessType) { _accessType = accessType; - string fileName = Win32Methods.GetFileNameOfMemoryMappedFile(file); + string? fileName = Win32Methods.GetFileNameOfMemoryMappedFile(file); if (fileName == null) throw new ArgumentException("Could not retrieve the name of the file to initialize."); @@ -301,7 +297,6 @@ namespace StormLibSharp } _openFiles.Clear(); - _openFiles = null; } // Release diff --git a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/MpqArchiveCompactingEventArgs.cs b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/MpqArchiveCompactingEventArgs.cs index c2a2ee7b..9a88fa15 100644 --- a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/MpqArchiveCompactingEventArgs.cs +++ b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/MpqArchiveCompactingEventArgs.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace StormLibSharp { diff --git a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/MpqFileStream.cs b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/MpqFileStream.cs index 18f6de25..97616360 100644 --- a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/MpqFileStream.cs +++ b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/MpqFileStream.cs @@ -1,19 +1,16 @@ -using StormLibSharp.Native; -using System; -using System.Collections.Generic; +using System; using System.ComponentModel; using System.IO; -using System.Linq; -using System.Text; using System.Threading; +using StormLibSharp.Native; namespace StormLibSharp { public class MpqFileStream : Stream { - private MpqFileSafeHandle _handle; + private MpqFileSafeHandle? _handle; private FileAccess _accessType; - private MpqArchive _owner; + private MpqArchive? _owner; internal MpqFileStream(MpqFileSafeHandle handle, FileAccess accessType, MpqArchive owner) { @@ -47,12 +44,12 @@ namespace StormLibSharp { VerifyHandle(); - _owner.Flush(); + _owner?.Flush(); } public override long Length { - get + get { VerifyHandle(); @@ -166,7 +163,7 @@ namespace StormLibSharp } // TODO: Seems like the right place for SFileGetFileInfo, but will need to determine - // what value add these features have except for sophisticated debugging purposes + // what value add these features have except for sophisticated debugging purposes // (like in Ladis' MPQ Editor app). public int ChecksumCrc32 diff --git a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/Callbacks.cs b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/Callbacks.cs index 58e7fa5e..2d257781 100644 --- a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/Callbacks.cs +++ b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/Callbacks.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; namespace StormLibSharp.Native { diff --git a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/MpqArchiveSafeHandle.cs b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/MpqArchiveSafeHandle.cs index 5e2df9c4..6813e927 100644 --- a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/MpqArchiveSafeHandle.cs +++ b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/MpqArchiveSafeHandle.cs @@ -1,9 +1,5 @@ -using Microsoft.Win32.SafeHandles; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; +using System; +using Microsoft.Win32.SafeHandles; namespace StormLibSharp.Native { diff --git a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/MpqFileSafeHandle.cs b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/MpqFileSafeHandle.cs index 495dd129..90d5e3a2 100644 --- a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/MpqFileSafeHandle.cs +++ b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/MpqFileSafeHandle.cs @@ -1,8 +1,5 @@ -using Microsoft.Win32.SafeHandles; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using System; +using Microsoft.Win32.SafeHandles; namespace StormLibSharp.Native { diff --git a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/NativeMethods.cs b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/NativeMethods.cs index acef5fbc..2e820e19 100644 --- a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/NativeMethods.cs +++ b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/NativeMethods.cs @@ -1,8 +1,5 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; namespace StormLibSharp.Native { @@ -43,25 +40,25 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileSetDownloadCallback( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.FunctionPtr)] SFILE_DOWNLOAD_CALLBACK pfnCallback, IntPtr pvUserData ); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] - public static extern bool SFileFlushArchive(MpqArchiveSafeHandle hMpq); + public static extern bool SFileFlushArchive(MpqArchiveSafeHandle? hMpq); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileCloseArchive(IntPtr hMpq); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] - public static extern bool SFileCloseArchive(MpqArchiveSafeHandle hMpq); + public static extern bool SFileCloseArchive(MpqArchiveSafeHandle? hMpq); #endregion #region Adds another listfile into MPQ. [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern int SFileAddListFile( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szListFile ); #endregion @@ -69,14 +66,14 @@ namespace StormLibSharp.Native #region Archive compacting [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileSetCompactCallback( - MpqArchiveSafeHandle hMpq, - SFILE_COMPACT_CALLBACK compactCB, + MpqArchiveSafeHandle? hMpq, + SFILE_COMPACT_CALLBACK? compactCB, IntPtr pvUserData ); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileCompactArchive( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szListFile, bool bReserved ); @@ -84,22 +81,22 @@ namespace StormLibSharp.Native #region Maximum file count [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] - public static extern uint SFileGetMaxFileCount(MpqArchiveSafeHandle hMpq); + public static extern uint SFileGetMaxFileCount(MpqArchiveSafeHandle? hMpq); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] - public static extern bool SFileSetMaxFileCount(MpqArchiveSafeHandle hMpq, uint dwMaxFileCount); + public static extern bool SFileSetMaxFileCount(MpqArchiveSafeHandle? hMpq, uint dwMaxFileCount); #endregion #region Changing (attributes) file [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] - public static extern uint SFileGetAttributes(MpqArchiveSafeHandle hMpq); + public static extern uint SFileGetAttributes(MpqArchiveSafeHandle? hMpq); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] - public static extern bool SFileSetAttributes(MpqArchiveSafeHandle hMpq, uint dwFlags); + public static extern bool SFileSetAttributes(MpqArchiveSafeHandle? hMpq, uint dwFlags); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileUpdateFileAttributes( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szFileName ); #endregion @@ -107,39 +104,39 @@ namespace StormLibSharp.Native #region Functions for manipulation with patch archives [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileOpenPatchArchive( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPTStr)] string szPatchMpqName, - [MarshalAs(UnmanagedType.LPStr)] string szPatchPathPrefix, + [MarshalAs(UnmanagedType.LPStr)] string? szPatchPathPrefix, uint dwFlags ); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] - public static extern bool SFileIsPatchedArchive(MpqArchiveSafeHandle hMpq); + public static extern bool SFileIsPatchedArchive(MpqArchiveSafeHandle? hMpq); #endregion #region Functions for file manipulation [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileHasFile( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szFileName ); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileOpenFileEx( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szFileName, uint dwSearchScope, out MpqFileSafeHandle phFile ); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] - public static extern uint SFileGetFileSize(MpqFileSafeHandle hFile, ref uint pdwFileSizeHigh); + public static extern uint SFileGetFileSize(MpqFileSafeHandle? hFile, ref uint pdwFileSizeHigh); public static unsafe uint SFileGetFilePointer( - MpqFileSafeHandle hFile + MpqFileSafeHandle? hFile ) { - if (hFile.IsInvalid || hFile.IsClosed) + if (hFile == null || hFile.IsInvalid || hFile.IsClosed) throw new InvalidOperationException(); IntPtr handle = hFile.DangerousGetHandle(); @@ -148,7 +145,7 @@ namespace StormLibSharp.Native } //public static unsafe uint SFileGetFileSize( - // MpqFileSafeHandle hFile + // MpqFileSafeHandle? hFile // ) //{ // if (hFile.IsInvalid || hFile.IsClosed) @@ -161,7 +158,7 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern uint SFileSetFilePointer( - MpqFileSafeHandle hFile, + MpqFileSafeHandle? hFile, uint lFilePos, ref uint plFilePosHigh, uint dwMoveMethod @@ -169,7 +166,7 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileReadFile( - MpqFileSafeHandle hFile, + MpqFileSafeHandle? hFile, IntPtr lpBuffer, uint dwToRead, out uint pdwRead, @@ -180,7 +177,7 @@ namespace StormLibSharp.Native public static extern bool SFileCloseFile(IntPtr hFile); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] - public static extern bool SFileCloseFile(MpqFileSafeHandle hFile); + public static extern bool SFileCloseFile(MpqFileSafeHandle? hFile); #region Retrieving info about a file in the archive [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] @@ -194,7 +191,7 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileGetFileInfo( - MpqArchiveSafeHandle hMpqOrFile, + MpqArchiveSafeHandle? hMpqOrFile, SFileInfoClass InfoClass, IntPtr pvFileInfo, uint cbFileInfoSize, @@ -212,7 +209,7 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileGetFileName( - MpqFileSafeHandle hFile, + MpqFileSafeHandle? hFile, [MarshalAs(UnmanagedType.LPStr)] out string szFileName ); @@ -225,7 +222,7 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileExtractFile( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szToExtract, [MarshalAs(UnmanagedType.LPTStr)] string szExtracted, uint dwSearchScope @@ -236,7 +233,7 @@ namespace StormLibSharp.Native #region Functions for file and archive verification [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileGetFileChecksums( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szFileName, out uint pdwCrc32, IntPtr pMD5 @@ -244,26 +241,26 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern uint SFileVerifyFile( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szFileName, uint dwFlags ); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern int SFileVerifyRawData( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, uint dwWhatToVerify, [MarshalAs(UnmanagedType.LPStr)] string szFileName ); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] - public static extern uint SFileVerifyArchive(MpqArchiveSafeHandle hMpq); + public static extern uint SFileVerifyArchive(MpqArchiveSafeHandle? hMpq); #endregion #region Functions for file searching [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern IntPtr SFileFindFirstFile( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szMask, out _SFILE_FIND_DATA lpFindFileData, [MarshalAs(UnmanagedType.LPStr)] string szListFile @@ -280,7 +277,7 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern IntPtr SListFileFindFirstFile( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szListFile, [MarshalAs(UnmanagedType.LPStr)] string szMask, [In, Out] ref _SFILE_FIND_DATA lpFindFileData @@ -299,7 +296,7 @@ namespace StormLibSharp.Native #region Locale support [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern int SFileEnumLocales( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szFileName, IntPtr plcLocales, ref uint pdwMaxLocales, @@ -310,7 +307,7 @@ namespace StormLibSharp.Native #region Support for adding files to the MPQ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileCreateFile( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szArchiveName, ulong fileTime, uint dwFileSize, @@ -321,18 +318,18 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileWriteFile( - MpqFileSafeHandle hFile, + MpqFileSafeHandle? hFile, IntPtr pvData, uint dwSize, uint dwCompression ); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] - public static extern bool SFileFinishFile(MpqFileSafeHandle hFile); + public static extern bool SFileFinishFile(MpqFileSafeHandle? hFile); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileAddFileEx( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPTStr)] string szFileName, [MarshalAs(UnmanagedType.LPStr)] string szArchivedName, uint dwFlags, @@ -342,7 +339,7 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileAddFile( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPTStr)] string szFileName, [MarshalAs(UnmanagedType.LPStr)] string szArchivedName, uint dwFlags @@ -350,7 +347,7 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileAddWave( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPTStr)] string szFileName, [MarshalAs(UnmanagedType.LPStr)] string szArchivedName, uint dwFlags, @@ -359,21 +356,21 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileRemoveFile( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szFileName, uint dwSearchScope ); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileRenameFile( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, [MarshalAs(UnmanagedType.LPStr)] string szOldFileName, [MarshalAs(UnmanagedType.LPStr)] string szNewFileName ); [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileSetFileLocale( - MpqFileSafeHandle hFile, + MpqFileSafeHandle? hFile, uint lcNewLocale ); @@ -382,7 +379,7 @@ namespace StormLibSharp.Native [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)] public static extern bool SFileSetAddFileCallback( - MpqArchiveSafeHandle hMpq, + MpqArchiveSafeHandle? hMpq, SFILE_ADDFILE_CALLBACK AddFileCB, IntPtr pvUserData ); diff --git a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/SFileInfoClass.cs b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/SFileInfoClass.cs index f8ef7a92..a53c2ba2 100644 --- a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/SFileInfoClass.cs +++ b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/SFileInfoClass.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace StormLibSharp.Native +namespace StormLibSharp.Native { internal enum SFileInfoClass { diff --git a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/SFileOpenArchiveFlags.cs b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/SFileOpenArchiveFlags.cs index d444f2be..24238c75 100644 --- a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/SFileOpenArchiveFlags.cs +++ b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/SFileOpenArchiveFlags.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace StormLibSharp.Native { diff --git a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/Win32Methods.cs b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/Win32Methods.cs index 15596c07..f0d19f26 100644 --- a/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/Win32Methods.cs +++ b/SabreTools.Serialization/_EXTERNAL/StormLibSharp/Native/Win32Methods.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.IO.MemoryMappedFiles; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; namespace StormLibSharp.Native { @@ -30,12 +27,12 @@ namespace StormLibSharp.Native [DllImport("kernel32", SetLastError = false, ExactSpelling = false)] public static extern int GetLastError(); - public static string GetFileNameOfMemoryMappedFile(MemoryMappedFile file) + public static string? GetFileNameOfMemoryMappedFile(MemoryMappedFile file) { const uint size = 522; IntPtr path = Marshal.AllocCoTaskMem(unchecked((int)size)); // MAX_PATH + 1 char - string result = null; + string? result; try { // constant 0x2 = VOLUME_NAME_NT