示例#1
0
 /// <summary>
 /// Assigns the filenames to each TAD entry.
 /// </summary>
 /// <param name="raymonf">True for using raymonf's wulinshu database else the cached database is used which is faster.</param>
 public void AssignFileNames(bool raymonf = false)
 {
     if (raymonf)
     {
         foreach (TADEntry entry in Entries)
         {
             entry.FileName = Wulinshu.GetFilenameFromHash(entry.FirstHash);
         }
     }
     else
     {
         foreach (TADEntry entry in Entries)
         {
             entry.FileName = FilenameDatabase.GetFilename(entry.FirstHash, entry.SecondHash);
         }
     }
 }
示例#2
0
        /// <summary>
        /// Unpacks all the files.
        /// </summary>
        /// <param name="verbose">True for outputing every filename.</param>
        /// <param name="raymonf">True for using raymonf's wulinshu database else the cached database is used which is faster.</param>
        /// <param name="folder">The output folder. When empty it will be extracted in a folder next to the TAD file.</param>
        public void Unpack(bool verbose = false, bool raymonf = false, string folder = "")
        {
            m_abort = false;
            if (String.IsNullOrEmpty(folder))
            {
                folder = Path.GetDirectoryName(TAD.FilePath) + "\\_" + TAD.FileName + "_";
            }
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            if (DescriptionChanged != null)
            {
                DescriptionChanged(this, new DescriptionChangedArgs("Unpacking tac..."));
            }

            int counter = 0;

            foreach (TADEntry entry in TAD.Entries)
            {
                if (m_abort)
                {
                    break;
                }
                if (ProgressChanged != null)
                {
                    ProgressChanged(this, new ProgressChangedArgs(counter, TAD.Entries.Count));
                }

                if (raymonf)
                {
                    entry.FileName = Wulinshu.GetFilenameFromHash(entry.FirstHash);
                }
                else
                {
                    entry.FileName = FilenameDatabase.GetFilename(entry.FirstHash, entry.SecondHash);
                }

                if (verbose)
                {
                    Console.WriteLine("[TAC/TAD] Offset: {1}, Size: {2} -> Filepath: {0}", entry.FileName, entry.FileOffset, entry.FileSize);
                }

                m_tacStream.Seek(entry.FileOffset, SeekOrigin.Begin);
                byte[] fileBuffer = new byte[entry.FileSize];
                m_tacStream.Read(fileBuffer, 0, fileBuffer.Length);

                entry.FilePath = "";
                if (String.IsNullOrEmpty(entry.FileName))
                {
                    entry.FilePath = String.Format("{0}\\{1}", folder, counter.ToString());
                }
                else
                {
                    entry.FilePath = entry.FileName.Replace('/', '\\');
                    entry.FilePath = folder + "\\" + entry.FilePath;

                    string dir = Path.GetDirectoryName(entry.FilePath);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                }
                using (FileStream entryStream = File.Create(entry.FilePath))
                {
                    entryStream.Write(fileBuffer, 0, fileBuffer.Length);
                }
                counter++;
            }
            if (ProgressChanged != null)
            {
                Finished(this, new FinishedArgs(true));
            }
        }