Example #1
0
 // TAHファイルをstreamに書き込む.成功ならtrue,失敗ならfalseを返す.
 public bool Write(Stream tostream)
 {
     try
     {
         int index = 0;
         // ファイル先頭に移動する.
         tostream.Seek(0, SeekOrigin.Begin);
         using (BufferedStream stream = new BufferedStream(tostream))
             using (BinaryWriter binarywriter = new BinaryWriter(stream))
             {
                 // ヘッダー情報を構築する.
                 BuildHeader();
                 // ヘッダーを書き込む.
                 header.Write(binarywriter);
                 long entryposition = stream.Position;
                 // offset値は0のままでエントリを一度書き込む.
                 foreach (TAHContent content in contents)
                 {
                     content.Entry.Write(binarywriter);
                 }
                 // ディレクトリを構築する
                 BuildDirectory();
                 // ディレクトリを書き込む.
                 directory.Write(binarywriter);
                 // データを書き込む
                 foreach (TAHContent content in contents)
                 {
                     // 実際にデータを読み込む.
                     Byte[] data = Data(delegateFileList[index++]);
                     // ヘッダーを更新する.
                     content.Data             = data;
                     content.Entry.Length     = data.Length;
                     content.Entry.DataOffset = (uint)stream.Position;
                     UInt32 length = (UInt32)content.Entry.Length;
                     binarywriter.Write(length);
                     Byte[] cryptdata = TAHUtil.Encrypt(content.Data);
                     binarywriter.Write(cryptdata);
                     // 参照を解除する.
                     content.Data = null;
                     data         = null;
                 }
                 // エントリを書き直す.
                 stream.Seek(entryposition, SeekOrigin.Begin);
                 foreach (TAHContent content in contents)
                 {
                     content.Entry.Write(binarywriter);
                 }
                 // バッファをフラッシュして完了.
                 binarywriter.Flush();
                 binarywriter.Close();
                 //stream.Flush();
             }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         return(false);
     }
     return(true);
 }
Example #2
0
        public void Write(BinaryWriter bw)
        {
            MemoryStream ms  = new MemoryStream();
            BinaryWriter bw2 = new BinaryWriter(ms);

            foreach (string i in Files)
            {
                if (i.EndsWith("/"))
                {
                    TAHUtil.WriteString(bw2, i);
                }
                else
                {
                    TAHUtil.WriteString(bw2, Path.GetFileName(i));
                }
            }

            bw2.Flush();
            byte[] encrypted = TAHUtil.Encrypt(ms.ToArray());

            bw.Write((uint)ms.Length);
            bw.Write(encrypted);
        }