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(); } }
/// <summary> /// Appends to or creates a MPQ file /// <para>Picks the appropiate version based on the build number.</para> /// </summary> /// <param name="filename"></param> /// <param name="version"></param> public void ToMPQ(string filename) { MpqArchiveVersion version = MpqArchiveVersion.Version2; if (this.Build <= (int)ExpansionFinalBuild.WotLK) { version = MpqArchiveVersion.Version2; } else if (this.Build <= (int)ExpansionFinalBuild.MoP) { version = MpqArchiveVersion.Version4; } else { MessageBox.Show("Only clients before WoD support MPQ archives."); return; } try { MpqArchive archive = null; if (File.Exists(filename)) { switch (ShowOverwriteDialog("You've selected an existing MPQ archive.\r\nWhich action would you like to take?", "Existing MPQ")) { case DialogResult.Yes: //Append archive = new MpqArchive(filename, FileAccess.Write); break; case DialogResult.No: //Overwrite archive = MpqArchive.CreateNew(filename, version); break; default: return; } } else { archive = MpqArchive.CreateNew(filename, version); } string tmpPath = Path.Combine(TEMP_FOLDER, TableStructure.Name); string fileName = Path.GetFileName(FilePath); string filePath = Path.Combine("DBFilesClient", fileName); new DBReader().Write(this, tmpPath); archive.AddFileFromDisk(tmpPath, filePath); int retval = archive.AddListFile(filePath); archive.Compact(filePath); archive.Flush(); archive.Dispose(); } //Save the file catch (Exception ex) { MessageBox.Show($"Error exporting to MPQ archive {ex.Message}"); } }
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(); } }
#pragma warning disable IDE0060 // Remove unused parameter private MpqArchive(string filePath, MpqArchiveVersion version, MpqFileStreamAttributes listfileAttributes, MpqFileStreamAttributes attributesFileAttributes, int maxFileCount) : this() #pragma warning restore IDE0060 // Remove unused parameter { if (maxFileCount < 0) { throw new ArgumentException(null, nameof(maxFileCount)); } var flags = SFileOpenArchiveFlags.TypeIsFile | SFileOpenArchiveFlags.AccessReadWriteShare; flags |= (SFileOpenArchiveFlags)version; if (!NativeMethods.SFileCreateArchive(filePath, (uint)flags, int.MaxValue, out _handle)) { throw new Win32Exception(); } }
public static MpqArchive CreateNew(string mpqPath, MpqArchiveVersion version, MpqFileStreamAttributes listfileAttributes, MpqFileStreamAttributes attributesFileAttributes, int maxFileCount) { return new MpqArchive(mpqPath, version, listfileAttributes, attributesFileAttributes, maxFileCount); }
public static MpqArchive CreateNew(string mpqPath, MpqArchiveVersion version) { return CreateNew(mpqPath, version, MpqFileStreamAttributes.None, MpqFileStreamAttributes.None, int.MaxValue); }
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(); }
public static MpqArchive CreateNew(string mpqPath, MpqArchiveVersion version, MpqFileStreamAttributes listfileAttributes, MpqFileStreamAttributes attributesFileAttributes, int maxFileCount) { return(new MpqArchive(mpqPath, version, listfileAttributes, attributesFileAttributes, maxFileCount)); }
public static MpqArchive CreateNew(string mpqPath, MpqArchiveVersion version) { return(CreateNew(mpqPath, version, MpqFileStreamAttributes.None, MpqFileStreamAttributes.None, int.MaxValue)); }