示例#1
0
    public void Load(string rootpath)
    {
        string dir = ProgressContainer.ProgressDirectory(rootpath);

        Directory.CreateDirectory(dir);
        string fullpath = ProgressContainer.FullPath(rootpath, m_Id);

        if (File.Exists(fullpath))
        {
            using (BinaryReader file = new BinaryReader(File.Open(fullpath, FileMode.Open)))
            {
                int version = file.ReadInt32();
                if (version >= 1)
                {
                    int booknum = file.ReadInt32();
                    for (int i = 0; i < booknum; i++)
                    {
                        string book = file.ReadString();
                        if (!m_books.Exists(x => x == book))
                        {
                            m_books.Add(book);
                        }
                    }
                }
                int count = file.ReadInt32();
                for (int i = 0; i < count; i++)
                {
                    Record record = new Record();
                    record.Load(file, version);
                    record.ProcessRecord(new Record.ProcessRecordEntry(CountOneEntry));
                    m_wordSet.Add(record.m_word, record);
                }
            }
        }

        foreach (string book in m_books)
        {
            BookDict dict = new BookDict(rootpath, book);
            dict.ReadBook(this);
            dict.SaveBook();
        }
        ReOrganize();
    }
示例#2
0
    public void Save(string rootpath)
    {
        string dir = ProgressContainer.ProgressDirectory(rootpath);

        Directory.CreateDirectory(dir);
        string fullpath = ProgressContainer.FullPath(rootpath, m_Id);

        using (BinaryWriter file = new BinaryWriter(File.Open(fullpath, FileMode.OpenOrCreate)))
        {
            file.Write(m_version);
            file.Write(m_books.Count);
            foreach (string book in m_books)
            {
                file.Write(book);
            }

            file.Write(m_wordSet.Count);
            foreach (KeyValuePair <string, Record> entry in m_wordSet)
            {
                Record record = entry.Value;
                record.Save(file);
            }
        }
    }