예제 #1
0
        public static TAHDirectories Load(BinaryReader br, TAHFile file)
        {
            TAHDirectories dir = new TAHDirectories();

            dir.Read(br, file);
            return(dir);
        }
예제 #2
0
        public static TAHEntry Load(BinaryReader br, TAHFile file)
        {
            TAHEntry h = new TAHEntry();

            h.Read(br, file);
            return(h);
        }
예제 #3
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);
        }
예제 #4
0
        public static TAHEntrySet Load(BinaryReader br, TAHFile file)
        {
            TAHEntrySet es = new TAHEntrySet();

            es.Read(br, file);
            return(es);
        }
예제 #5
0
 // ファイルをオープンする
 private static void OpenRead()
 {
     foreach (string filename in filenames)
     {
         Program.SetRescent(filename);
         FileStream fs = File.OpenRead(filename);
         tahfiles[filename] = new TAHFile(fs);
         tahfiles[filename].LoadEntries();
     }
 }
예제 #6
0
        private static void CreateTahFiles(string tahname, uint version)
        {
            string basefilename = Path.GetFileNameWithoutExtension(tahname);

            int count = 0;

            foreach (List <string> tahfilelist in tahfilelists)
            {
                if (tahfilelist.Count > 0)
                {
                    string destname;
                    if (count == 0)
                    {
                        destname = tahname;
                    }
                    else
                    {
                        tahname = Path.Combine(Path.GetDirectoryName(tahname), basefilename + "-" + count.ToString() + ".tah");
                    }
                    count++;
                    TAHWriter writer = new TAHWriter();
                    writer.Version = version;
                    foreach (string file in tahfilelist)
                    {
                        writer.Add(file);
                    }
                    Console.WriteLine("tah file " + tahname);
                    using (FileStream fs = File.OpenWrite(tahname))
                    {
                        int filecount = 1, filemax = tahfilelist.Count;
                        // データ取得delegate
                        writer.RawData += delegate(string filename)
                        {
                            TAHRawData   rawdata  = new TAHRawData();
                            TAHEntryInfo fileinfo = GetEntry(filename);
                            TAHFile      tahfile  = fileinfo.file;
                            uint         length;
                            rawdata.data   = TAHUtil.ReadRawEntryData(tahfile.Reader, fileinfo.entry, out length);
                            rawdata.length = length;
                            //Console.Write(tahname + " " + filecount++.ToString() + "/" + filemax.ToString() + "\r");
                            return(rawdata);
                        };
                        writer.RawWrite(fs);
                        Console.Write("\n");
                    }
                }
            }
        }
예제 #7
0
        // ハッシュテーブルを構築する
        private static void MakeHashTable()
        {
            foreach (string filename in filenames)
            {
                TAHFile tahfile = tahfiles[filename];
                foreach (TAHEntry entry in tahfile.EntrySet.Entries)
                {
                    if (hashentry.ContainsKey(entry.Hash))
                    {
                        string newfilename = GetFileName(entry);

                        if (hashentry[entry.Hash].entry.FileName != null &&
                            entry.FileName != null &&
                            filemaps[entry.Hash].ToLower() != newfilename.ToLower())
                        {
                            Console.WriteLine("Hash collision : " + filemaps[entry.Hash] + "->" + newfilename + " at " + filename);
                        }
                        // より新しいバージョンか?
                        if (hashentry[entry.Hash].file.Header.Version < tahfile.Header.Version)
                        {
                            hashentry[entry.Hash].file  = tahfile;
                            hashentry[entry.Hash].entry = entry;
                            filemaps[entry.Hash]        = newfilename;
                        }
                    }
                    else
                    {
                        hashentry[entry.Hash]       = new TAHEntryInfo();
                        hashentry[entry.Hash].file  = tahfile;
                        hashentry[entry.Hash].entry = entry;
                        filemaps[entry.Hash]        = GetFileName(entry);
                        hashtable.Add(entry.Hash);
                    }
                }
            }
        }
예제 #8
0
        public void Read(BinaryReader br, TAHFile file)
        {
            // ディレクトリデータの読み込み
            Files = new List <string>(file.Header.NumEntries);
            int output_length = br.ReadInt32();
            int input_length  = (int)(file.EntrySet[0].DataOffset - br.BaseStream.Position); //- 16 - 8 * file.Header.NumEntries;

            byte[] input  = br.ReadBytes(input_length);
            byte[] output = new byte[output_length];

            if (output.Length == 0)
            {
                return;
            }

            // add konoa:tahdecryptorのバグ回避.
            if (input.Length == 0)
            {
                return;
            }

            TAHUtil.Decrypt(input, output);
            //TAHdecrypt.Decrypter.decrypt(ref input, (uint)input.Length, ref output, (uint)output.Length);

            MemoryStream ms  = new MemoryStream(output);
            BinaryReader br2 = new BinaryReader(ms);

            try
            {
                string dir = "";

                while (ms.Position < ms.Length)
                {
                    string name = TAHUtil.ReadString(br2);

                    if (name.Length == 0)
                    {
                    }
                    else
                    if (name.EndsWith("/"))
                    {
                        dir = name;
                        //DbgPrint("Directory:            " + dir);
                    }
                    else
                    {
                        name = dir + name;
                        uint     hash = TAHUtil.CalcHash(name);
                        TAHEntry ent;

                        //DbgPrint(hash.ToString("X").PadLeft(8, '0'));

                        if (file.EntrySet.TryGetValue(hash, out ent))
                        {
                            ent.FileName = name;
                            //DbgPrint(": Found:     " + file);
                        }
                        else
                        {
                            //DbgPrint(": Not Found: " + file);
                            System.Diagnostics.Debug.Assert(false);
                        }

                        //EntryMap[hash].FileName = FileName;
                    }

                    Files.Add(name);
                }
            }
            catch (EndOfStreamException)
            {
            }
        }
예제 #9
0
 public void Read(BinaryReader br, TAHFile file)
 {
     Hash       = br.ReadUInt32();
     FileName   = FindExternalFileName(Hash);
     DataOffset = br.ReadUInt32();
 }