Exemple #1
0
        public void Write(string filePath, ThreadHeader header,
                          ResSetCollection resCollection)
        {
            Stream stream = StreamCreator.CreateWriter(filePath, useGzip, true);

            header.UseGzip = useGzip;

            try {
                ThreadFormatter formatter = new X2chThreadFormatter();
                string          textData  = formatter.Format(resCollection);
                byte[]          byteData  = TwinDll.DefaultEncoding.GetBytes(textData);

                stream.Write(byteData, 0, byteData.Length);
            }
            finally {
                if (stream != null)
                {
                    stream.Close();
                }
            }

            // インデックスファイルを作成
            string indexPath = GetIndexPath(filePath);

            ThreadIndexer.Write(indexPath, header);
        }
        /// <summary>
        /// スレッドをdat形式で保存
        /// </summary>
        /// <param name="cache">キャッシュ情報</param>
        /// <param name="header">保存するスレッド</param>
        /// <param name="filePath">保存先ファイルパス</param>
        public static void SaveDat(Cache cache, ThreadHeader header, string filePath)
        {
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }

            if (header == null)
            {
                throw new ArgumentNullException("header");
            }

            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            // datの存在するパスを取得
            string fromPath = cache.GetDatPath(header);

            ThreadStorage reader = null;
            StreamWriter  writer = null;

            ResSetCollection    items     = new ResSetCollection();
            X2chThreadFormatter formatter = new X2chThreadFormatter();

            try {
                // 読み込みストリームを開く
                reader = new LocalThreadStorage(cache, header, StorageMode.Read);
                // 書き込みストリームを開く
                writer = new StreamWriter(filePath, false, Encoding.GetEncoding("Shift_Jis"));

                // すべて読み込む
                while (reader.Read(items) != 0)
                {
                    ;
                }
                writer.Write(formatter.Format(items));
            }
            finally {
                if (reader != null)
                {
                    reader.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }