Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MpqFile"/> class.
        /// </summary>
        /// <param name="archive">The MPQ archive this file is in.</param>
        /// <param name="fileHandle">The file handle.</param>
        public MpqFile(MpqArchive archive, IntPtr fileHandle)
        {
            if (archive == null)
                throw new ArgumentNullException("archive");
            if (fileHandle == IntPtr.Zero)
                throw new ArgumentNullException("fileHandle");

            this.archive = archive;
            this.fileHandle = fileHandle;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MpqFile"/> class.
        /// </summary>
        /// <param name="archive">The MPQ archive this file is in.</param>
        /// <param name="fileHandle">The file handle.</param>
        public MpqFile(MpqArchive archive, IntPtr fileHandle)
        {
            if (archive == null)
            {
                throw new ArgumentNullException("archive");
            }
            if (fileHandle == IntPtr.Zero)
            {
                throw new ArgumentNullException("fileHandle");
            }

            this.archive    = archive;
            this.fileHandle = fileHandle;
        }
Exemplo n.º 3
0
        public void ProcessMPQ(List<string> lstAllMPQFiles)
        {
            // Create a folder to dump all this into
            Directory.CreateDirectory(DBCOutputDir);

            // Go through all the files, getting all DBCs
            foreach (var mpqFileName in lstAllMPQFiles)
            {
                //Directory.CreateDirectory(Path.Combine(DBCOutputDir, Path.GetFileNameWithoutExtension(mpqFileName)));

                using (var oArchive = new MpqArchive(mpqFileName))
                {
                    var dbcFiles = oArchive.FindAllFiles("*.dbc");
                    //var dbcsFiles = from a in oArchive.Files
                    //                where a.Name.EndsWith(".dbc")
                    //                select a.Name;

                    foreach (var strFileName in dbcFiles)
                    {
                        var strLocalFilePath = string.Format(@"{0}\{1}", DBCOutputDir, Path.GetFileName(strFileName));
                        //var strLocalFilePath = Path.Combine(DBCOutputDir, Path.GetFileNameWithoutExtension(mpqFileName));
                        //strLocalFilePath = Path.Combine(strLocalFilePath, Path.GetFileName(strFileName));

                        if (File.Exists(strLocalFilePath)) continue;

                        using (Stream stmOutput = new FileStream(strLocalFilePath, FileMode.Create))
                        {
                            using (Stream stmInput = oArchive.OpenFile(strFileName).GetStream())
                            {
                                // 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);
                                }
                            }

                            Console.WriteLine("Done");
                        }
                    }
                }
            }
        }