Пример #1
0
 // TAHファイルをstreamに書き込む.成功ならtrue,失敗ならfalseを返す.
 public bool RawWrite(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)
                 {
                     // 実際にデータを読み込む.
                     TAHRawData rawdata = RawData(delegateFileList[index++]);
                     // ヘッダーを更新する.
                     content.Data             = rawdata.data;
                     content.Entry.Length     = (int)rawdata.length;
                     content.Entry.DataOffset = (uint)stream.Position;
                     UInt32 length = (UInt32)content.Entry.Length;
                     binarywriter.Write(length);
                     binarywriter.Write(rawdata.data);
                     // 参照を解除する.
                     content.Data = null;
                     rawdata      = null;
                     Console.WriteLine(content.Entry.DataOffset.ToString() + ":" + content.Entry.FileName + "(" + content.Entry.Length.ToString() + ")");
                 }
                 // エントリを書き直す.
                 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);
 }
Пример #2
0
        private static void CreateTahFiles(string tahname, uint version)
        {
            string basefilename = Path.GetFileNameWithoutExtension(tahname);

            int count = 0;

            foreach (List <string> tahfilelist in tahfilelists)
            {
                if (tahfilelist.Count > 0)
                {
                    string destname;
                    if (count == 0)
                    {
                        destname = tahname;
                    }
                    else
                    {
                        tahname = Path.Combine(Path.GetDirectoryName(tahname), basefilename + "-" + count.ToString() + ".tah");
                    }
                    count++;
                    TAHWriter writer = new TAHWriter();
                    writer.Version = version;
                    foreach (string file in tahfilelist)
                    {
                        writer.Add(file);
                    }
                    Console.WriteLine("tah file " + tahname);
                    using (FileStream fs = File.OpenWrite(tahname))
                    {
                        int filecount = 1, filemax = tahfilelist.Count;
                        // データ取得delegate
                        writer.RawData += delegate(string filename)
                        {
                            TAHRawData   rawdata  = new TAHRawData();
                            TAHEntryInfo fileinfo = GetEntry(filename);
                            TAHFile      tahfile  = fileinfo.file;
                            uint         length;
                            rawdata.data   = TAHUtil.ReadRawEntryData(tahfile.Reader, fileinfo.entry, out length);
                            rawdata.length = length;
                            //Console.Write(tahname + " " + filecount++.ToString() + "/" + filemax.ToString() + "\r");
                            return(rawdata);
                        };
                        writer.RawWrite(fs);
                        Console.Write("\n");
                    }
                }
            }
        }