void BuildArchive() { File.Delete(ArchivePath); var otherFiles = Directory.GetFiles(UmswePath); var handle = IntPtr.Zero; SFileCreateArchive(ArchivePath, 0, (uint)(DataFiles.Length + otherFiles.Length), out handle); SFileCloseArchive(handle); using (var mpq = new MpqArchive(ArchivePath, FileAccess.ReadWrite)) { mpq.AddListFile(""); for (int i = 0; i < DataFiles.Length; i++) { var file = DataFiles[i]; mpq.AddFileFromDisk($"{TempFolder}\\{file}", $"UI\\{file}"); } for (int i = 0; i < otherFiles.Length; i++) { var file = otherFiles[i]; mpq.AddFileFromDisk(file, Path.GetFileName(file)); } mpq.Dispose(); } }
/// <summary> /// Some alpha MPQs are hotswappable and only contain a single file and it's checksum /// </summary> /// <param name="mpq"></param> /// <param name="archivename"></param> private bool TryReadAlpha(MpqArchive mpq, string archivename) { // strip the local path and extension to get the filename var file = Path.ChangeExtension(GetInternalPath(archivename), null).WoWNormalise(); if (FileList.ContainsKey(file)) { return(true); } // add the filename as the listfile var internalname = Path.GetFileName(file); mpq.AddListFile(internalname); // read file if known if (mpq.HasFile(internalname)) { using var fs = mpq.OpenFile(internalname); if (fs.CanRead && fs.Length > 0) { var map = BlockTableEncoder.GetEMapFromExtension(file, fs.Length); if (!EncodingCache.TryGetRecord(MD5Hash.Parse(fs.GetMD5Hash()), file, out var record)) { record = BlockTableEncoder.EncodeAndExport(fs, map, Options.TempDirectory, file); EncodingCache.AddOrUpdate(record); } record.EBlock.EncodingMap = map; FileList.TryAdd(file, record); return(true); } } return(false); }
/** * Runs the program */ private void Run(String[] args) { // Verify argument count if (!CheckArguments(args)) { return; } // Retrieve argument values and listfile, and check for existence String operationName = args[0]; String mpqName = args[1]; String listfileName = "listfile.txt"; if (!File.Exists(mpqName)) { Console.WriteLine("MPQ file does not exist: " + mpqName); return; } if (!File.Exists(listfileName)) { Console.WriteLine("Listfile does not exist: " + listfileName); return; } // Determine what operation the user wanted Boolean extract; if (operationName.Equals("ext") || operationName.Equals("exp") || operationName.Equals("export") || operationName.Equals("extract")) { extract = true; } else if (operationName.Equals("imp") || operationName.Equals("import")) { extract = false; } else { Console.WriteLine("Invalid operation: " + operationName); return; } // For every entered file, we either perform import/export using (MpqArchive archive = new MpqArchive(mpqName, FileAccess.ReadWrite)) { // Add listfile.txt as external listfile int retval = archive.AddListFile(listfileName); Console.WriteLine("Added listfile: " + retval + " (0 is ok)"); for (int i = 2; i < args.Length; i++) { if (extract) { Extract(args[i], archive); } else { Import(args[i], archive); } } Console.WriteLine("All desired operations completed. Flushing & closing."); // Close out resources archive.Compact(listfileName); archive.Flush(); archive.Dispose(); } }