public MpqArchive(string filePath, FileAccess accessType) { FilePath = filePath; _openFiles = new ConcurentSet <MpqFileStream>(); _compactCallbacks = new List <MpqArchiveCompactingEventHandler>(); _accessType = accessType; SFileOpenArchiveFlags flags = SFileOpenArchiveFlags.TypeIsFile; if (accessType == FileAccess.Read) { flags |= SFileOpenArchiveFlags.AccessReadOnly; } else { flags |= SFileOpenArchiveFlags.AccessReadWriteShare; } // constant 2 = SFILE_OPEN_HARD_DISK_FILE if (!NativeMethods.SFileOpenArchive(filePath, 2, flags, out _handle)) { throw new Win32Exception(); // Implicitly calls GetLastError } }
protected virtual void Dispose(bool disposing) { if (disposing) { // Release owned files first. if (_openFiles != null) { foreach (MpqFileStream of in _openFiles) { of.Dispose(); } _openFiles.Clear(); _openFiles = null; } // Release if (_handle != null && !_handle.IsInvalid) { _handle.Close(); _handle = null; } } }