Пример #1
0
        public void SaveTo()
        {
            DirectoryInfo di = new DirectoryInfo(SharedData.SavedNovelListDirPath);

            if (!di.Exists)
            {
                di.Create();
            }

            foreach (NovelInfo novelInfo in saveNovels)
            {
                var novelDic = novelInfo.GetValues();
                using (FileStream fs = new FileStream(di.FullName + @"\" + novelInfo.NCode, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
                {
                    var writer = new KimamaLib.XMLWrapper.Writer();
                    writer.SetRoot("novels");
                    foreach (KeyValuePair <string, string> pair in novelDic)
                    {
                        var attribute = new KimamaLib.XMLWrapper.AttributeInfo()
                        {
                            Name  = "name",
                            Value = pair.Key
                        };
                        writer.AddElement("item", attribute, pair.Value);
                    }

                    writer.Write(fs);
                }
            }
        }
        public void DownloadNovel(NovelInfo novelInfo)
        {
            DirectoryInfo di = new DirectoryInfo(SharedData.SavelNovelDirPath);

            if (!di.Exists)
            {
                di.Create();
            }
            FileInfo fi = new FileInfo(di.FullName + @"\" + novelInfo.NCode);

            string ncode = novelInfo.NCode;

            bool nType = false;

            if (novelInfo.NType == NovelType.Serialization)
            {
                nType = true;
            }
            var novelDownloader = new SyousetukaGetterLib.NovelDownloader(ncode, novelInfo.GeneralAllNo, nType);

            novelDownloader.DownloadNovel();
            List <string> titleList;

            if (nType)
            {
                titleList = novelDownloader.Title[ncode];
            }
            else
            {
                titleList = new List <string>();
                titleList.Add("");
            }
            var textList = novelDownloader.NovelText[ncode];

            novelInfo.Titles = titleList;
            novelInfo.Texts  = textList;

            int count = titleList.Count < textList.Count ? titleList.Count : textList.Count;

            using (FileStream fs = new FileStream(fi.FullName, FileMode.Create, FileAccess.Write, FileShare.Read))
            {
                var xmlWriter = new KimamaLib.XMLWrapper.Writer();
                xmlWriter.SetRoot("novels");

                var attribute = new KimamaLib.XMLWrapper.AttributeInfo()
                {
                    Name  = "count",
                    Value = count.ToString()
                };

                xmlWriter.AddElement("item", attribute);
                for (int i = 0; i < count; ++i)
                {
                    var attributes = new KimamaLib.XMLWrapper.AttributeInfo[2]
                    {
                        new KimamaLib.XMLWrapper.AttributeInfo()
                        {
                            Name = "page", Value = (i + 1).ToString()
                        },
                        new KimamaLib.XMLWrapper.AttributeInfo()
                        {
                            Name = "subtitle", Value = titleList[i]
                        },
                    };
                    var text = textList[i].Replace("<ruby>", string.Empty);
                    text = text.Replace("</ruby>", string.Empty);
                    text = text.Replace("<rb>", string.Empty);
                    text = text.Replace("</rb>", string.Empty);
                    text = text.Replace("<rp>", string.Empty);
                    text = text.Replace("</rp>", string.Empty);
                    text = text.Replace("<rt>", string.Empty);
                    text = text.Replace("</rt>", string.Empty);
                    xmlWriter.AddElement("novel", attributes, text);
                }
                xmlWriter.Write(fs);
            }
        }