private void ReadCache(ResSetCollection buff)
        {
            // 新規に開く場合のみキャッシュを読み込む
            if (modeOpen)
            {
                if (ThreadIndexer.Exists(Cache, headerInfo))
                {
                    ThreadIndexer.Read(Cache, headerInfo);

                    try
                    {
                        storage            = new LocalThreadStorage(Cache, headerInfo, StorageMode.Read);
                        storage.BufferSize = bufferSize;

                        // すべてのレスを読み込み表示
                        while (storage.Read(buff) != 0)
                        {
                            ;
                        }
                    }
                    finally
                    {
                        if (storage != null)
                        {
                            storage.Close();
                            storage = null;
                        }
                    }

                    buff.IsNew = false;
                }
            }
        }
        /// <summary>
        /// スレッドを開く
        /// </summary>
        /// <param name="header"></param>
        public virtual void Open(ThreadHeader header)
        {
            if (header == null)
            {
                throw new ArgumentNullException("header");
            }
            if (IsReading)
            {
                throw new InvalidOperationException("スレッドを読み込み中です");
            }

            Close();

            // 各フラグを設定
            IsOpen    = true;
            IsReading = true;

            modeOpen   = true;
            headerInfo = header;

            // インデックス情報を読み込む
            if (ThreadIndexer.Exists(Cache, header))
            {
                ThreadIndexer.Read(Cache, header);
            }

            string subj = (header.Subject != String.Empty) ? header.Subject : "[スレッド名不明]";

            OnStatusTextChanged(subj + "を開いています");

            ThreadRun();
        }
        /// <summary>
        /// インデックス一覧を読み込む
        /// </summary>
        public void Load()
        {
            items.Clear();

            if (File.Exists(fileName))
            {
                StreamReader sr = null;
                string       text;

                try {
                    sr = new StreamReader(fileName, TwinDll.DefaultEncoding);
                    while ((text = sr.ReadLine()) != null)
                    {
                        string       filePath = Path.Combine(Application.StartupPath, text);
                        ThreadHeader header   = ThreadIndexer.Read(filePath);

                        if (header != null)
                        {
                            items.Add(header);
                        }
                    }
                }
                finally {
                    if (sr != null)
                    {
                        sr.Close();
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// 生きているスレとdat落ちしているスレを分離
        /// </summary>
        /// <param name="oldBoard">ログが存在する板</param>
        /// <param name="newBoard">生きているスレの移転先</param>
        /// <param name="leaveItems">dat落ちしているスレが格納される</param>
        /// <param name="liveItems">生きているスレが格納される</param>
        private void Separate(BoardInfo oldBoard, BoardInfo newBoard,
                              out List <ThreadHeader> leaveItems, out List <ThreadHeader> liveItems)
        {
            leaveItems = new List <ThreadHeader>();
            liveItems  = new List <ThreadHeader>();

            if (cache.Exists(oldBoard))
            {
                List <ThreadHeader> oldItems   = GotThreadListIndexer.Read(cache, oldBoard);
                List <ThreadHeader> newItems   = new List <ThreadHeader>();
                ThreadListReader    listReader = null;

                if (oldItems.Count > 0)
                {
                    try {
                        listReader = TypeCreator.CreateThreadListReader(newBoard.Bbs);
                        listReader.Open(newBoard);

                        while (listReader.Read(newItems) != 0)
                        {
                            ;
                        }

                        // 移転先のスレ一覧に存在するログのみ移転 (dat落ちしているスレは移転しない)
                        foreach (ThreadHeader header in oldItems)
                        {
                            Predicate <ThreadHeader> p = new Predicate <ThreadHeader>(delegate(ThreadHeader h)
                            {
                                return(h.Key == header.Key);
                            });

                            if (newItems.Exists(p))
                            {
                                // 生きているスレの板情報を移転先板に書き換える
                                if (ThreadIndexer.Read(cache, header) != null)
                                {
                                    ThreadIndexer.Delete(cache, header);

                                    liveItems.Add(header);
                                    header.BoardInfo = newBoard;

                                    ThreadIndexer.Write(cache, header);
                                }
                            }
                            else
                            {
                                leaveItems.Add(header);
                            }
                        }
                    }
                    finally {
                        if (listReader != null)
                        {
                            listReader.Close();
                        }
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// oldBoardからnewBoardにログを移動
        /// </summary>
        /// <param name="oldItems"></param>
        /// <param name="newBoard"></param>
        private void CopyDatFiles(BoardInfo oldItems, BoardInfo newBoard)
        {
            string fromFolder = cache.GetFolderPath(oldItems);
            string toFolder   = cache.GetFolderPath(newBoard, true);

            string[] fileNames = Directory.GetFiles(fromFolder, "*.dat*");            // .dat .dat.gz を検索

            foreach (string fromPath in fileNames)
            {
                try {
                    string fromName = Path.GetFileName(fromPath);
                    string destPath = Path.Combine(toFolder, fromName);

                    File.Copy(fromPath, destPath, true);
                    File.Delete(fromPath);

                    int token = fromName.IndexOf('.');
                    if (token != -1)
                    {
                        string key           = fromName.Substring(0, token);
                        string fromIndexFile = Path.Combine(fromFolder, key + ".idx");
                        string toIndexFile   = Path.Combine(toFolder, key + ".idx");

                        ThreadHeader h = ThreadIndexer.Read(fromIndexFile);

                        if (h != null)
                        {
                            h.BoardInfo.Server = newBoard.Server;

                            ThreadIndexer.Write(toIndexFile, h);

                            File.Delete(fromIndexFile);
                        }
                    }
                }
                catch (IOException ex)
                {
                    TwinDll.Output(ex);
                }
            }
        }