Esempio n. 1
0
        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
            }
        }
Esempio n. 2
0
        private MpqArchive(string filePath, MpqArchiveVersion version, MpqFileStreamAttributes listfileAttributes, MpqFileStreamAttributes attributesFileAttributes, int maxFileCount)
        {
            if (maxFileCount < 0)
            {
                throw new ArgumentException("maxFileCount");
            }

            SFileOpenArchiveFlags flags = SFileOpenArchiveFlags.TypeIsFile | SFileOpenArchiveFlags.AccessReadWriteShare;

            flags |= (SFileOpenArchiveFlags)version;

            //SFILE_CREATE_MPQ create = new SFILE_CREATE_MPQ()
            //{
            //    cbSize = unchecked((uint)Marshal.SizeOf(typeof(SFILE_CREATE_MPQ))),
            //    dwMaxFileCount = unchecked((uint)maxFileCount),
            //    dwMpqVersion = (uint)version,
            //    dwFileFlags1 = (uint)listfileAttributes,
            //    dwFileFlags2 = (uint)attributesFileAttributes,
            //    dwStreamFlags = (uint)flags,
            //};

            //if (!NativeMethods.SFileCreateArchive2(filePath, ref create, out _handle))
            //    throw new Win32Exception();
            if (!NativeMethods.SFileCreateArchive(filePath, (uint)flags, int.MaxValue, out _handle))
            {
                throw new Win32Exception();
            }
        }
Esempio n. 3
0
        public MpqArchive(MemoryMappedFile file, FileAccess accessType)
        {
            _accessType = accessType;
            string fileName = Win32Methods.GetFileNameOfMemoryMappedFile(file);

            if (fileName == null)
            {
                throw new ArgumentException("Could not retrieve the name of the file to initialize.");
            }

            SFileOpenArchiveFlags flags = SFileOpenArchiveFlags.TypeIsMemoryMapped;

            if (accessType == FileAccess.Read)
            {
                flags |= SFileOpenArchiveFlags.AccessReadOnly;
            }
            else
            {
                flags |= SFileOpenArchiveFlags.AccessReadWriteShare;
            }

            // constant 2 = SFILE_OPEN_HARD_DISK_FILE
            if (!NativeMethods.SFileOpenArchive(fileName, 2, flags, out _handle))
            {
                throw new Win32Exception(); // Implicitly calls GetLastError
            }
        }
Esempio n. 4
0
        private MpqArchive(string filePath, MpqArchiveVersion version, MpqFileStreamAttributes listfileAttributes, MpqFileStreamAttributes attributesFileAttributes, int maxFileCount)
        {
            if (maxFileCount < 0)
            {
                throw new ArgumentException("maxFileCount");
            }

            SFileOpenArchiveFlags flags = SFileOpenArchiveFlags.TypeIsFile | SFileOpenArchiveFlags.AccessReadWriteShare;

            flags |= (SFileOpenArchiveFlags)version;

            if (!NativeMethods.SFileCreateArchive(filePath, (uint)flags, int.MaxValue, out _handle))
            {
                throw new Win32Exception();
            }
        }
Esempio n. 5
0
        public MpqArchive(string filePath, FileAccess accessType)
        {
            _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
            }
        }
Esempio n. 6
0
 public static extern bool SFileOpenArchive(
     [MarshalAs(UnmanagedType.LPTStr)] string szMpqName,
     uint dwPriority,
     SFileOpenArchiveFlags dwFlags,
     out MpqArchiveSafeHandle phMpq
     );
Esempio n. 7
0
 public static extern bool SFileOpenArchive(
     [MarshalAs(UnmanagedType.LPTStr)] string szMpqName,
     uint dwPriority,
     SFileOpenArchiveFlags dwFlags,
     out MpqArchiveSafeHandle phMpq
     );