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

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

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

            es.Read(br, file);
            return(es);
        }
Exemple #5
0
        public void Read(BinaryReader br, TAHFile file)
        {
            Hash       = br.ReadUInt32();
            FileName   = FindExternalFileName(Hash);
            DataOffset = br.ReadUInt32();
#if false
            Owner = file;
#endif
        }
Exemple #6
0
 // 確実に開放する.
 public void Dispose()
 {
     if (ims != null)
     {
         ims.Dispose();
         ims = null;
     }
     if (tah != null)
     {
         tah.Dispose();
         tah = null;
     }
     if (ms != null)
     {
         ms.Dispose();
         ms = null;
     }
     if (archive != null)
     {
         archive.Dispose();
         archive = null;
     }
 }
Exemple #7
0
        public static void ArcsDumpTAHEntries(Stream source, ArcsDatabase db, string tahname)
        {
            try
            {
                TDCGExplorer.SetToolTips("Processing " + Path.GetFileName(tahname));
                using (TAHFile tah = new TAHFile(source))
                {
                    try
                    {
                        tah.LoadEntries();
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("Error: " + ex);
                        return;
                    }

                    DateTime datetime = File.GetLastWriteTime(tahname);

                    ArcsTahEntry entry = new ArcsTahEntry();
                    entry.path      = tahname.Substring(arcspath.Length + 1);
                    entry.shortname = Path.GetFileName(tahname).ToLower();
                    entry.version   = (int)tah.Header.Version;
                    entry.id        = 0;
                    entry.exist     = 1;
                    entry.datetime  = datetime;

                    entry.id = db.SetTahEntry(entry);
                    ArcsDumpTahFilesEntries(db, entry, tah);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error: " + ex);
                return;
            }
        }
Exemple #8
0
        public static void DumpArcEntries(ArcsDatabase db, string source_file, IArchive arc, int id)
        {
            try
            {
                TDCGExplorer.LastAccessFile = source_file;
                arc.Open(source_file);

                foreach (IArchiveEntry entry in arc)
                {
                    // ディレクトリのみの場合はスキップする.
                    if (entry.IsDirectory == true)
                    {
                        continue;
                    }

                    // TAHファイルなら詳細をダンプする.
                    if (Path.GetExtension(entry.FileName) == ".tah")
                    {
                        using (MemoryStream ms = new MemoryStream((int)entry.Size))
                        {
                            arc.Extract(entry, ms);
                            ms.Seek(0, SeekOrigin.Begin);

                            using (TAHFile tah = new TAHFile(ms))
                            {
                                try
                                {
                                    tah.LoadEntries();
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine("Error: " + ex);
                                    continue;
                                }

                                ArcsZipTahEntry ziptahentry = new ArcsZipTahEntry();
                                ziptahentry.id        = 0;
                                ziptahentry.path      = entry.FileName;
                                ziptahentry.shortname = Path.GetFileName(entry.FileName).ToLower();
                                ziptahentry.version   = (int)tah.Header.Version;
                                ziptahentry.zipid     = id;
                                int tahid = db.SetZipTahEntry(ziptahentry);

                                int tahentry = 0;
                                foreach (TAHEntry ent in tah.EntrySet.Entries)
                                {
                                    if (ent.FileName == null)
                                    {
                                        TDCGExplorer.SetToolTips("Dump " + ent.Hash.ToString("x8") + " file");
                                    }
                                    else
                                    {
                                        TDCGExplorer.SetToolTips("Dump " + Path.GetFileName(ent.FileName) + " file");
                                    }
                                    ArcsTahFilesEntry fileentry = new ArcsTahFilesEntry();
                                    fileentry.id       = 0;
                                    fileentry.tahid    = tahid;
                                    fileentry.tahentry = tahentry++;
                                    fileentry.path     = ent.FileName;
                                    if (fileentry.path == null)
                                    {
                                        fileentry.path = "";
                                    }
                                    //fileentry.md5sum = "";
                                    fileentry.hash   = (int)ent.Hash;
                                    fileentry.length = (int)ent.Length;
                                    db.SetZipTahFilesPath(fileentry);
                                }
                            }
                        }
                    }
                    else
                    {
                        // tahファイル以外はファイル名のみ情報を格納する.
                        ArcsZipTahEntry ziptahentry = new ArcsZipTahEntry();
                        ziptahentry.id      = 0;
                        ziptahentry.path    = entry.FileName;
                        ziptahentry.version = 0;
                        ziptahentry.zipid   = id;
                        int tahid = db.SetZipTahEntry(ziptahentry);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error: " + ex);
                return;
            }
        }
Exemple #9
0
        public static void ArcsDumpTahFilesEntries(ArcsDatabase db, ArcsTahEntry entry, TAHFile tah)
        {
            string source   = Path.Combine(TDCGExplorer.SystemDB.arcs_path, entry.path);
            int    tahentry = 0;

            foreach (TAHEntry ent in tah.EntrySet.Entries)
            {
                if (ent.FileName == null)
                {
                    TDCGExplorer.SetToolTips("Dump " + ent.Hash.ToString("x8") + " file");
                }
                else
                {
                    TDCGExplorer.SetToolTips("Dump " + ent.FileName + " file");
                }
                ArcsTahFilesEntry fileentry = new ArcsTahFilesEntry();
                fileentry.id       = 0;
                fileentry.tahid    = entry.id;
                fileentry.tahentry = tahentry++;
                fileentry.path     = ent.FileName;
                if (entry.path == null)
                {
                    entry.path = "";
                }
                fileentry.hash   = (int)ent.Hash;
                fileentry.length = (int)ent.Length;
                db.SetTahFilesPath(fileentry);
            }
        }
Exemple #10
0
        public GenericTAHStream(GenericTahInfo info, ArcsTahFilesEntry tsoInfo)
        {
            // zipファイルの中か?
            if (info.zipid != -1)
            {
                ArcsZipArcEntry zip     = TDCGExplorer.ArcsDB.GetZip(info.zipid);
                string          zippath = Path.Combine(TDCGExplorer.SystemDB.zips_path, zip.path);
                switch (Path.GetExtension(zip.path).ToLower())
                {
                case ".zip":
                    archive = new ZipArchive();
                    break;

                case ".lzh":
                    archive = new LzhArchive();
                    break;

                case ".rar":
                    archive = new RarArchive();
                    break;

                default:
                    archive = new DirectAccessArchive();
                    break;
                }
                TDCGExplorer.LastAccessFile = zippath;
                archive.Open(zippath);
                if (archive == null)
                {
                    throw new Exception(TextResource.ArchiveIsNull);
                }

                //
                foreach (IArchiveEntry entry in archive)
                {
                    // ディレクトリのみの場合はスキップする.
                    if (entry.IsDirectory == true)
                    {
                        continue;
                    }
                    // マッチするファイルを見つけた.
                    if (entry.FileName == info.path)
                    {
                        ms = new MemoryStream((int)entry.Size);

                        archive.Extract(entry, ms);
                        ms.Seek(0, SeekOrigin.Begin);
                        tah = new TAHFile(ms);
                        tah.LoadEntries();
                        if (tsoInfo == null)
                        {
                            return;
                        }
                        int tahentry = 0;
                        foreach (TAHEntry ent in tah.EntrySet.Entries)
                        {
                            // 該当ファイルを見つけた.
                            if (tahentry == tsoInfo.tahentry)
                            {
                                byte[] data = TAHUtil.ReadEntryData(tah.Reader, ent);
                                //
                                Cursor.Current = Cursors.WaitCursor;
                                ims            = new MemoryStream(data);
                                return;
                            }
                            tahentry++;
                        }
                    }
                }
            }
            else
            {
                string source = Path.Combine(TDCGExplorer.SystemDB.arcs_path, info.path);
                tah = new TAHFile(source);
                tah.LoadEntries();
                if (tsoInfo == null)
                {
                    return;
                }
                int tahentry = 0;
                foreach (TAHEntry ent in tah.EntrySet.Entries)
                {
                    // 該当ファイルを見つけた.
                    if (tahentry == tsoInfo.tahentry)
                    {
                        byte[] data = TAHUtil.ReadEntryData(tah.Reader, ent);
                        //
                        ims = new MemoryStream(data);
                        return;
                    }
                    tahentry++;
                }
            }
            throw new Exception("TAH内のファイルが見つかりません");
        }
Exemple #11
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)
            {
            }
        }