/// <summary> /// Extracts files from the archive matching the pattern (if any) /// </summary> void ExtractArchive() { using(MpqArchive archive = new MpqArchive(archiveFile)) { // destination directory if(destDir == null || destDir == "") destDir = Directory.GetCurrentDirectory(); // default to current dir of not specified // setup external listfile if specified if(listFile != null && listFile != "") archive.ExternalListFile = listFile; // buffers byte[] buf = new byte[0x40000]; if(!quietOutput) Console.WriteLine("Extracting to {0}", destDir); for(int i = 0; i < archive.Files.Length; i++) { MpqArchive.FileInfo fi = archive.Files[i]; // WoW contains a lot of files with Flags & FileHasMetadata //if((fi.Flags & MpqFileFlags.FileHasMetadata) != 0) // continue; // WoW contains a lot of zero length files with Flags & Unknown_02000000 //if((fi.Flags & MpqFileFlags.Unknown_02000000) != 0) // continue; // match pattern if(regex != null && !regex.Match(fi.Name).Success) continue; if(!quietOutput) Console.Write(fi.Name + " .. "); // create destination directory string srcFile = fi.Name; if(stripPath) srcFile = Path.GetFileName(srcFile); string destFile = Path.Combine(destDir, srcFile); string absDestDir = Path.GetDirectoryName(destFile); CreateDirectory(absDestDir); // copy to destination file using(Stream stmIn = archive.OpenFile(fi.Name)) { using(Stream stmOut = new FileStream(destFile, FileMode.Create)) { while(true) { int cb = stmIn.Read(buf, 0, buf.Length); if(cb == 0) break; stmOut.Write(buf, 0, cb); } stmOut.Close(); } } if(!quietOutput) Console.WriteLine("Done."); } } }
public static void ProcessMPQ(List<string> lstAllMPQFiles) { // Create a folder to dump all this into Directory.CreateDirectory(DBCOutputDir); // Go through all the files, getting all DBCs for (int i = 0; i < lstAllMPQFiles.Count; i++) { using (var oArchive = new MpqArchive(lstAllMPQFiles[i])) { var dbcsFiles = from a in oArchive.Files where a.Name.EndsWith(".dbc") select a.Name; foreach (var strFileName in dbcsFiles) { var strLocalFilePath = string.Format(@"{0}\{1}", DBCOutputDir, Path.GetFileName(strFileName)); // Does it already exist? If it does then it'll be one from a previous package, so let's leave it if (!File.Exists(strLocalFilePath)) { using (Stream stmOutput = new FileStream(strLocalFilePath, FileMode.Create)) { using (Stream stmInput = oArchive.OpenFile(strFileName)) { // Writing... Console.Write(string.Format("Writing File {0}....", Path.GetFileName(strFileName))); // Create an 8kb buffer var byFileContents = new byte[8192]; // Loop until we're out of data while (true) { // Read from the MPQ int intBytesRead = stmInput.Read(byFileContents, 0, byFileContents.Length); // Was there anything to read? if (intBytesRead == 0) break; // Write to the file stmOutput.Write(byFileContents, 0, intBytesRead); } } // Close the File stmOutput.Close(); Console.WriteLine("Done"); } } } } } }