Exemple #1
0
        /// <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}");
            }
        }
Exemple #2
0
        /// <summary>
        /// Actually run the App.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Help();

                System.Environment.Exit(0);
            }

            string folder  = args[0];
            string mpqPath = args[1];

            if (!Directory.Exists(folder))
            {
                Logger.Danger("Could not find specified folder '" + folder + "'. Please ensure this exists!");

                System.Environment.Exit(0);
            }

            string[] files = Directory.GetFiles(folder, "*", SearchOption.AllDirectories);

            int total = files.Length;

            Logger.Info(String.Format("Writing ({0}) files from '{1}' to '{2}'...\n", total, folder, mpqPath));

            if (File.Exists(mpqPath))
            {
                File.Delete(mpqPath);
            }

            ProgressBar progress = new ProgressBar(60);

            int current = 1;

            using (MpqArchive mpq = MpqArchive.CreateNew(mpqPath, MpqArchiveVersion.Version2, MpqFileStreamAttributes.None, MpqFileStreamAttributes.CreateAttributesFile, files.Length))
            {
                foreach (string file in files)
                {
                    string innerPath = After(file, folder);
                    innerPath = innerPath.Substring(1); // Get rid of leading slash.

                    mpq.AddFileFromDiskWithCompression(file, innerPath, MpqCompressionTypeFlags.MPQ_COMPRESSION_ZLIB);

                    int percentage = (current / total) * 100;

                    progress.Update(percentage);

                    current++;
                }
            }

            Logger.Success("\n\nDone!\n");
        }
Exemple #3
0
        /// <summary>
        /// Moves the files from the chunked archive to a flat file one
        /// </summary>
        /// <param name="archivename"></param>
        /// <param name="block"></param>
        private void DoFileSwap(string archivename, string block)
        {
            Directory.CreateDirectory("Temp");

            string filename = Path.GetFileName(archivename);

            using (var mpq = MpqArchive.CreateNew(archivename, MpqArchiveVersion.Version3))
                using (var tmp = new MpqArchive(block, FileAccess.Read, OpenArchiveFlags.BLOCK4))
                {
                    if (TryGetFileList(tmp, false, out var lf))
                    {
                        _progressBar.Start();

                        string tempPath;
                        for (int i = 0; i < lf.Count; i++)
                        {
                            using (var fs = tmp.OpenFile(lf[i]))
                            {
                                // incremental patch files can't be written directly with StormLib SFileCreateFile?
                                if ((fs.TFileEntry.dwFlags & 0x100000u) != 0x100000u)
                                {
                                    mpq.AddFileFromStream(fs);
                                }
                                else
                                {
                                    tempPath = Path.Combine("Temp", lf[i]);
                                    Directory.CreateDirectory(Path.GetDirectoryName(tempPath));

                                    tmp.ExtractFile(lf[i], tempPath);
                                    mpq.AddFileFromDisk(tempPath, lf[i], fs.TFileEntry.dwFlags);
                                }
                            }

                            _progressBar.Update(filename, i / (float)lf.Count);

                            if (i % 10000 == 0)
                            {
                                mpq.Flush();
                            }
                        }
                    }
                }

            Console.WriteLine("Emptying Temp Folder...");
            DeleteDirectory("Temp");
            _progressBar.Stop();
        }
Exemple #4
0
        public void CreateMpqFromDbcFileList(string archiveName, List <string> exportList)
        {
            var archivePath = "Export\\" + archiveName;

            if (File.Exists(archivePath))
            {
                File.Delete(archivePath);
            }
            using (var archive = MpqArchive.CreateNew(archivePath, MpqArchiveVersion.Version1))
            {
                exportList.ForEach((dbcFile) =>
                {
                    var pathToAdd = "DBFilesClient\\" + dbcFile.Substring(dbcFile.IndexOf('\\') + 1);
                    archive.AddFileFromDiskWithCompression(dbcFile, pathToAdd, MpqCompressionTypeFlags.MPQ_COMPRESSION_ZLIB);
                });
            }
        }
        static void Main(string[] args)
        {
            //Try to load configuration file
            Config = new ApplicationConfigurationLoader().BuildConfigFile();

            //Now we want to search the entire output directory
            //for DBC files and stick them in the MPQ.

            string[] dbcFileNames = Directory.GetFiles(Config.DbcOutputPath);

            //Creates an MPQ with length of dbc files at the MPQ output directory.
            using (MpqArchive mpq = MpqArchive.CreateNew(Path.Combine(Config.MpqOutputPath, $"{Config.MpqOutputName}.MPQ"), MpqArchiveVersion.Version2, MpqFileStreamAttributes.None, MpqFileStreamAttributes.None, dbcFileNames.Length))
            {
                foreach (string dbc in dbcFileNames)
                {
                    mpq.AddFileFromDiskWithCompression(dbc, Path.Combine("DBClientFiles", Path.GetFileName(dbc)), MpqCompressionTypeFlags.MPQ_COMPRESSION_ZLIB);
                }
            }
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Console.WriteLine(DBCToolsExtensions.BuildToolsWelcomeMessage("CreateMPQ"));

            //Try to load configuration file
            Config = new ApplicationConfigurationLoader().BuildConfigFile();

            //Now we want to search the entire output directory
            //for DBC files and stick them in the MPQ.

            string[] dbcFileNames = Directory.GetFiles(Config.DbcOutputPath);

            if (!Directory.Exists(Config.MpqOutputPath))
            {
                Directory.CreateDirectory(Config.MpqOutputPath);
            }

            string fullFilePath = Path.Combine(Config.MpqOutputPath, $"{Config.MpqOutputName}.MPQ");

            //If the MPQ already exists, then delete it
            if (File.Exists(fullFilePath))
            {
                File.Delete(fullFilePath);
            }

            //Creates an MPQ with length of dbc files at the MPQ output directory.
            using (MpqArchive mpq = MpqArchive.CreateNew(fullFilePath, MpqArchiveVersion.Version2, MpqFileStreamAttributes.None, MpqFileStreamAttributes.CreateAttributesFile, dbcFileNames.Length))
            {
                foreach (string dbc in dbcFileNames)
                {
                    mpq.AddFileFromDiskWithCompression(dbc, Path.Combine("DBFilesClient", Path.GetFileName(dbc)), MpqCompressionTypeFlags.MPQ_COMPRESSION_ZLIB);
                }
            }

            Console.WriteLine("Finished. Press any key!");
        }