public static int Execute(List <string> args)
        {
            if (args.Count != 3)
            {
                Console.WriteLine("Usage: TLDAT TOFHDB ExtractFolder");
                return(-1);
            }

            String TLDAT         = args[0];
            String TOFHDB        = args[1];
            String ExtractFolder = args[2];

            if (!(ExtractFolder.EndsWith("/") || ExtractFolder.EndsWith("\\")))
            {
                ExtractFolder = ExtractFolder + '/';
            }

            Directory.CreateDirectory(ExtractFolder);

            TOFHDBheader header = new TOFHDBheader(TOFHDB);

            UInt64 biggestFile = header.BiggestFile();

            Byte[]     buffer = new byte[biggestFile];
            FileStream fs     = File.Open(TLDAT, FileMode.Open, FileAccess.Read);

            int counter = 1;

            foreach (TOFHDBfile e in header.FileArray)
            {
                fs.Position = (long)e.Offset;
                fs.Read(buffer, 0, (int)e.CompressedSize);
                String ExtensionFolder = ExtractFolder + e.Extension + '/';
                Directory.CreateDirectory(ExtensionFolder);
                String Path = ExtensionFolder + counter.ToString("D8") + '.' + e.Extension;

                FileStream os = File.OpenWrite(Path);
                os.Write(buffer, 0, (int)e.CompressedSize);
                os.Close();

                counter++;
            }

            fs.Close();

            return(0);
        }
Example #2
0
        public static int Execute( List<string> args )
        {
            if ( args.Count != 3 ) {
                Console.WriteLine( "Usage: TLDAT TOFHDB ExtractFolder" );
                return -1;
            }

            String TLDAT = args[0];
            String TOFHDB = args[1];
            String ExtractFolder = args[2];
            if ( !( ExtractFolder.EndsWith( "/" ) || ExtractFolder.EndsWith( "\\" ) ) ) {
                ExtractFolder = ExtractFolder + '/';
            }

            Directory.CreateDirectory( ExtractFolder );

            TOFHDBheader header = new TOFHDBheader( TOFHDB );

            UInt64 biggestFile = header.BiggestFile();
            Byte[] buffer = new byte[biggestFile];
            FileStream fs = File.Open( TLDAT, FileMode.Open, FileAccess.Read );

            int counter = 1;

            foreach ( TOFHDBfile e in header.FileArray ) {
                fs.Position = (long)e.Offset;
                fs.Read( buffer, 0, (int)e.CompressedSize );
                String ExtensionFolder = ExtractFolder + e.Extension + '/';
                Directory.CreateDirectory( ExtensionFolder );
                String Path = ExtensionFolder + counter.ToString( "D8" ) + '.' + e.Extension;

                FileStream os = File.OpenWrite( Path );
                os.Write( buffer, 0, (int)e.CompressedSize );
                os.Close();

                counter++;
            }

            fs.Close();

            return 0;
        }
Example #3
0
        public static int Execute( List<string> args )
        {
            if ( args.Count != 4 ) {
                Console.WriteLine( "Usage: OldTOFHDB Folder NewTLDAT NewTOFHDB" );
                return -1;
            }

            String OldTOFHDB = args[0];
            String ExtractFolder = args[1];
            String TLDAT = args[2];
            String TOFHDB = args[3];
            TOFHDBheader header = new TOFHDBheader( OldTOFHDB );

            // collect files
            SortedDictionary<uint, string> filenameMap = new SortedDictionary<uint, string>();
            foreach ( string dir in Directory.EnumerateDirectories( ExtractFolder ) ) {
                foreach ( string file in Directory.EnumerateFiles( dir ) ) {
                    string filenumstr = Path.GetFileNameWithoutExtension( file );
                    uint num = Util.ParseDecOrHex( filenumstr );
                    filenameMap.Add( num, file );
                }
            }

            if ( filenameMap.Count != header.FileArray.Count ) {
                Console.WriteLine( "File count mismatch!" );
                return 1;
            }
            if ( filenameMap.First().Key != 1 || filenameMap.Last().Key != header.FileArray.Count ) {
                Console.WriteLine( "Filenames are wrong!" );
                return 2;
            }

            // write files and populate header
            using ( FileStream fsData = File.Open( TLDAT, FileMode.Create, FileAccess.ReadWrite ) ) {
                foreach ( var f in filenameMap ) {
                    using ( FileStream fs = new FileStream( f.Value, FileMode.Open ) ) {
                        header.FileArray[(int)( f.Key - 1 )].Filesize = (ulong)fs.Length;
                        header.FileArray[(int)( f.Key - 1 )].CompressedSize = (ulong)fs.Length;
                        header.FileArray[(int)( f.Key - 1 )].Offset = (ulong)fsData.Position;

                        // check if TLZC compressed and write uncompressed size if so
                        if ( fs.PeekUInt32() == 0x435A4C54 ) {
                            fs.DiscardBytes( 12 );
                            header.FileArray[(int)( f.Key - 1 )].Filesize = fs.ReadUInt32();
                            fs.Position = 0;
                        }

                        fs.CopyTo( fsData );
                        fs.Close();
                    }
                }
                fsData.Close();
            }

            // write header
            using ( FileStream fs = new FileStream( TOFHDB, FileMode.Create, FileAccess.ReadWrite ) ) {
                header.Write( fs );
                fs.Close();
            }

            return 0;
        }