public static void ReadExternalFileList() { external_files = new ext_file_list(); if (System.IO.File.Exists("names.txt")) { System.IO.StreamReader reader = new System.IO.StreamReader(System.IO.File.OpenRead("names.txt")); List <string> known_files = new List <string>(); string line; while ((line = reader.ReadLine()) != null) { known_files.Add(line); } //map a list of hash keys to the file... external_files.files = known_files.ToArray(); if (external_files.files != null) { external_files.hashkeys = new UInt32[external_files.files.Length]; for (int i = 0; i < external_files.files.Length; i++) { external_files.hashkeys[i] = TAHUtil.CalcHash(external_files.files[i]); //Console.WriteLine(external_files.hashkeys[i].ToString("X8") + "\t" + external_files.files[i]); } } //sorting for faster look up... Array.Sort(external_files.hashkeys, external_files.files); } }
// 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); }
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) { } }