mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-08 18:06:41 +00:00
Remove NoWarn and fix issues
This commit is contained in:
@@ -16,6 +16,6 @@ namespace SabreTools.Data.Models.CDROM
|
||||
/// <summary>
|
||||
/// ISO9660 volume within the data track
|
||||
/// </summary>
|
||||
public Volume Volume { get; set; }
|
||||
public Volume Volume { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace SabreTools.Serialization.Readers
|
||||
/// </summary>
|
||||
/// <param name="data">Stream to parse</param>
|
||||
/// <returns>Filled byte[] on success, null on error</returns>
|
||||
public static byte[]? ParseCDROMSystemArea(Stream data)
|
||||
public static byte[] ParseCDROMSystemArea(Stream data)
|
||||
{
|
||||
var systemArea = new byte[Constants.SystemAreaSectors * Constants.MinimumSectorSize];
|
||||
// Process in sectors
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
||||
<IncludeSymbols>true</IncludeSymbols>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<!-- Added due to StormLibSharp -->
|
||||
<NoWarn>CS8600;CS8601;CS8603;CS8604;CS8618;CS8625;CS8634;IL3000</NoWarn>
|
||||
<Nullable>enable</Nullable>
|
||||
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
|
||||
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
|
||||
@@ -43,18 +41,7 @@
|
||||
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Exclude certain parts of external modules for by default -->
|
||||
<PropertyGroup>
|
||||
<DefaultItemExcludes>
|
||||
$(DefaultItemExcludes);
|
||||
**\AssemblyInfo.cs;
|
||||
_EXTERNAL\stormlibsharp\lib\**;
|
||||
_EXTERNAL\stormlibsharp\src\CascLibSharp\**;
|
||||
_EXTERNAL\stormlibsharp\src\TestConsole\**
|
||||
</DefaultItemExcludes>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Exclude all external modules for .NET Framework 2.0, .NET Framework 3.5, or non-Windows builds -->
|
||||
<!-- Exclude all external modules for .NET Framework 2.0 and .NET Framework 3.5 -->
|
||||
<PropertyGroup Condition="$(TargetFramework.StartsWith(`net2`)) OR $(TargetFramework.StartsWith(`net3`))">
|
||||
<DefaultItemExcludes>
|
||||
$(DefaultItemExcludes);
|
||||
|
||||
@@ -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<T>(ref T target, IntPtr hModule, string procName)
|
||||
private static void SetFn<T>(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";
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
/// <exception cref="ObjectDisposedException">Thrown if the Stream has been disposed.</exception>
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
/// </summary>
|
||||
public class CascFoundFile
|
||||
{
|
||||
#if NET20 || NET35 || NET40
|
||||
private WeakReference _ownerContext;
|
||||
#else
|
||||
private WeakReference<CascStorageContext> _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<CascStorageContext>(ownerContext);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full path to this file.
|
||||
/// </summary>
|
||||
public string FileName { get; private set; }
|
||||
public string? FileName { get; private set; }
|
||||
/// <summary>
|
||||
/// Gets the plain (no directory-qualified) file name of this file.
|
||||
/// </summary>
|
||||
public string PlainFileName { get; private set; }
|
||||
public string? PlainFileName { get; private set; }
|
||||
/// <summary>
|
||||
/// Gets the CASC encoding key for this file.
|
||||
/// </summary>
|
||||
@@ -52,9 +56,14 @@ namespace CascLibSharp
|
||||
/// <returns>A CascFileStream, which acts as a Stream for a CASC stored file.</returns>
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<bool> _hasListfile;
|
||||
private Lazy<CascKnownClient> _clientType;
|
||||
private Lazy<long> _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.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
/// <param name="indexKey">The index key to search.</param>
|
||||
@@ -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
|
||||
/// <param name="mask">The mask to search. * and ? are valid tokens for substitution.</param>
|
||||
/// <param name="listFilePath">A path to a listfile. Required if the CASC container is for World of Warcraft.</param>
|
||||
/// <returns>An enumeration of matching file references in the CASC container.</returns>
|
||||
public IEnumerable<CascFoundFile> SearchFiles(string mask, string listFilePath = null)
|
||||
public IEnumerable<CascFoundFile> 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
|
||||
/// <param name="disposing">True if this is being called via the Dispose() method; false if it's being called by the finalizer.</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
if (disposing && _handle != null)
|
||||
{
|
||||
if (!_handle.IsInvalid)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<CascGameId, CascKnownClient> GameClientMap = new Dictionary<CascGameId, CascKnownClient>
|
||||
private static Dictionary<CascGameId, CascKnownClient> GameClientMap = new Dictionary<CascGameId, CascKnownClient>
|
||||
{
|
||||
{ CascGameId.Hots, CascKnownClient.HeroesOfTheStorm },
|
||||
{ CascGameId.Wow6, CascKnownClient.WorldOfWarcraft },
|
||||
@@ -57,7 +53,7 @@ namespace CascLibSharp.Native
|
||||
{ CascGameId.Starcraft2, CascKnownClient.Starcraft2 },
|
||||
};
|
||||
|
||||
private static Dictionary<CascKnownClient, CascGameId> ClientGameMap = new Dictionary<CascKnownClient, CascGameId>()
|
||||
private static Dictionary<CascKnownClient, CascGameId> ClientGameMap = new Dictionary<CascKnownClient, CascGameId>()
|
||||
{
|
||||
{ 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));
|
||||
|
||||
@@ -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<MpqFileStream> _openFiles = new List<MpqFileStream>();
|
||||
private FileAccess _accessType;
|
||||
private List<MpqArchiveCompactingEventHandler> _compactCallbacks = new List<MpqArchiveCompactingEventHandler>();
|
||||
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
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StormLibSharp
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StormLibSharp.Native
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace StormLibSharp.Native
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user