Beispiel #1
0
        private byte[] WriteHiz(HizArchive hizArchive)
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            writer.Write(hizArchive.header);
            writer.Write((byte)0);// header
            writer.Write(hizArchive.file_count);
            writer.Write(hizArchive.max_compress_size);

            for (int i = 0; i < hizArchive.file_count; i++)
            {
                HizFile hizFile = hizArchive.hizFiles[i];
                Console.WriteLine("Packing {0}", hizFile.name);
                writer.Write(decoder.DecodeData(BitConverter.GetBytes((short)hizFile.type)));
                writer.Write(decoder.DecodeData(BitConverter.GetBytes(hizFile.compress_size)));
                writer.Write(decoder.DecodeData(BitConverter.GetBytes(hizFile.decompress_size)));
                writer.Write(decoder.DecodeData(BitConverter.GetBytes((short)hizFile.name.Length)));
                writer.Write(decoder.DecodeData(Encoding.UTF8.GetBytes(hizFile.name)));
                writer.Write(hizFile.data);
            }
            Console.WriteLine("\nPacked {0} files.", hizArchive.file_count);
            writer.Close();
            return(stream.ToArray());
        }
Beispiel #2
0
 private HizFile[] ReadHizFilesFromDir(string dir)
 {
     string[]  paths    = Tools.ReadAllPaths(dir);
     HizFile[] hizFiles = new HizFile[paths.Length];
     for (int i = 0; i < paths.Length; i++)
     {
         HizFile hizFile = new HizFile();
         string  path    = paths[i];
         hizFile.name = path.Replace(dir + Path.DirectorySeparatorChar, string.Empty);
         if (File.GetAttributes(path).HasFlag(FileAttributes.Directory))
         {
             hizFile.type            = 0;
             hizFile.compress_size   = 0;
             hizFile.decompress_size = 0;
             hizFile.data            = new byte[0];
         }
         else
         {
             FileInfo fileInfo = new FileInfo(path);
             hizFile.type            = 0;
             hizFile.compress_size   = (int)fileInfo.Length;
             hizFile.decompress_size = (int)fileInfo.Length;
             hizFile.data            = File.ReadAllBytes(path);
         }
         hizFiles[i] = hizFile;
     }
     return(hizFiles);
 }
Beispiel #3
0
        private void ReadHizArchive(byte[] hiz_buffer)
        {
            BinaryReader reader = new BinaryReader(new MemoryStream(hiz_buffer));

            HizArchive = new HizArchive();
            if (!ReadHizHeader(reader))
            {
                return;
            }
            Console.WriteLine("File count: {0}\nChecksum: 0x{1}\nMax compress size: {2}\n",
                              HizArchive.file_count, checksum.ToString("X"), HizArchive.max_compress_size);

            HizArchive.hizFiles = new HizFile[HizArchive.file_count];
            for (int i = 0; i < HizArchive.file_count; i++)
            {
                HizFile hizFile = new HizFile();
                hizFile.type            = decoder.DecodeInt16(reader);
                hizFile.compress_size   = decoder.DecodeInt32(reader);
                hizFile.decompress_size = decoder.DecodeInt32(reader);
                int    name_len = decoder.DecodeInt16(reader);
                byte[] name     = decoder.DecodeData(reader.ReadBytes(name_len));
                hizFile.name = Encoding.UTF8.GetString(name);
                if (hizFile.isCompressed())
                {
                    hizFile.data = Unzip.GetData(reader.ReadBytes(hizFile.compress_size), true);
                }
                else
                {
                    hizFile.data = reader.ReadBytes(hizFile.decompress_size);
                }
                HizArchive.hizFiles[i] = hizFile;
            }
        }
Beispiel #4
0
 public static void UnpackAll(HizFile[] hiz_files, string dir)
 {
     Directory.CreateDirectory(dir);
     for (int i = 0; i < hiz_files.Length; i++)
     {
         HizFile hizFile = hiz_files[i];
         if (hizFile.data.Length == 0) //dir
         {
             Directory.CreateDirectory(dir + "/" + hizFile.name);
         }
         else
         {
             Console.WriteLine("{0} {1}KB", hizFile.name, hizFile.data.Length / 1024);
             File.WriteAllBytes(dir + "/" + hizFile.name, hizFile.data);
         }
     }
     Console.WriteLine("Done.");
 }