Exemple #1
0
        public static TAHEntry Load(BinaryReader br, TAHFile file)
        {
            TAHEntry h = new TAHEntry();

            h.Read(br, file);
            return(h);
        }
Exemple #2
0
        public void Read(BinaryReader br, TAHFile file)
        {
            Entries  = new List <TAHEntry>(file.Header.NumEntries);
            EntryMap = new Dictionary <uint, TAHEntry>();

            for (int i = 0, n = file.Header.NumEntries; i < n; ++i)
            {
                TAHEntry e = TAHEntry.Load(br, file);

                if (i != 0)
                {
                    TailEntry.Length = (int)(e.DataOffset - TailEntry.DataOffset);
                }
                //Console.WriteLine(e.ToString());
                Entries.Add(e);
                if (EntryMap.ContainsKey(e.Hash))
                {
                    //Console.WriteLine("Error: delect hashkey collision. " + e.Hash.ToString("X8") + ": " + e.DataOffset.ToString());
                    Debug.WriteLine("Error: detect hashkey collision. " + e.Hash.ToString("X8") + ": " + e.DataOffset.ToString());
                }
                else
                {
                    EntryMap.Add(e.Hash, e);
                }
            }

            TailEntry.Length = (int)(br.BaseStream.Length - TailEntry.DataOffset);
        }
Exemple #3
0
        public static byte[] ReadEntryData(BinaryReader br, TAHEntry e)
        {
            br.BaseStream.Seek(e.DataOffset, SeekOrigin.Begin);
            byte[] output = new byte[br.ReadInt32()];
            byte[] input  = br.ReadBytes(e.Length - 4);

            TAHUtil.Decrypt(input, output);

            return(output);
        }
Exemple #4
0
        // ファイル名を取得する.
        private static string GetFileName(TAHEntry entry)
        {
            string filename;

            filename = entry.FileName;

            if (filename == null)
            {
                filename = "00000000" + "_" + entry.Hash.ToString("x8");
            }
            return(filename);
        }
Exemple #5
0
        // TAHにファイルを加える.
        public void Add(string filename)
        {
            // オリジナルのファイル名を保存しておく.
            delegateFileList.Add(filename);
            // TAHに格納可能なファイル名に変換する.
            string   regularfile = filename.Replace('\\', '/');
            TAHEntry tahentry    = new TAHEntry();

            tahentry.DataOffset = 0;
            tahentry.FileName   = regularfile;
            tahentry.Length     = 0;
            if (Path.GetDirectoryName(regularfile) == "")
            {
                // dddddddd_xxxxxxxx.eee形式をハッシュ値に戻す
                if (regularfile.Length >= 17)
                {
                    string hashcode = regularfile.Substring(9, 8);
                    try
                    {
                        // 16進数からハッシュ値に.
                        tahentry.Hash = UInt32.Parse(hashcode, System.Globalization.NumberStyles.HexNumber);
                        // 暫定ファイル名は削除.
                        tahentry.FileName = null;
                    }
                    catch (Exception)
                    {
                        // 判んない時は適当につける.
                        tahentry.Hash = TAHUtil.CalcHash(regularfile);
                    }
                }
                else
                {
                    // 判んない時は適当につける.
                    tahentry.Hash = TAHUtil.CalcHash(regularfile);
                }
            }
            else
            {
                tahentry.Hash = TAHUtil.CalcHash(regularfile);
            }
            TAHContent content = new TAHContent(tahentry, null);

            contents.Add(content);
        }
Exemple #6
0
 public TAHContent LoadContent(BinaryReader br, TAHEntry e)
 {
     return(new TAHContent(e, TAHUtil.ReadEntryData(br, e)));
 }
Exemple #7
0
 public TAHContent(TAHEntry e, byte[] data)
 {
     Entry = e;
     Data  = data;
 }
Exemple #8
0
 public bool TryGetValue(uint hash, out TAHEntry e)
 {
     return(EntryMap.TryGetValue(hash, out e));
 }
Exemple #9
0
 public static byte[] ReadRawEntryData(BinaryReader br, TAHEntry e, out uint len)
 {
     br.BaseStream.Seek(e.DataOffset, SeekOrigin.Begin);
     len = br.ReadUInt32();
     return(br.ReadBytes(e.Length - 4));
 }