private static bool GetBookInfo(string id, out BookInfo info) { info = null; var filePath = IniUtils.Read(ConfigFile, id, FILEPATHITEMNAME).Trim(); if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath)) { IniUtils.Write(ConfigFile, id, "", ""); return(false); } int index; double offset; int.TryParse(IniUtils.Read(ConfigFile, id, CHAPTERINDEXITEMNAME, "0").Trim(), out index); double.TryParse(IniUtils.Read(ConfigFile, id, CHAPTEROFFSETITEMNAME, "0").Trim(), out offset); var name = IniUtils.Read(ConfigFile, id, BOOKNAMEITEMNAME).Trim(); var itemName = IniUtils.Read(ConfigFile, id, CHAPTERNAMEITEMNAME).Trim(); info = new BookInfo() { BookId = id, BookName = name, ChapterName = itemName, FilePath = filePath, ChapterIndex = index, ChapterOffset = offset }; return(true); }
private static void SaveBookData(BookInfo info) { //文件地址 IniUtils.Write(ConfigFile, info.BookId, FILEPATHITEMNAME, info.FilePath); IniUtils.Write(ConfigFile, info.BookId, CHAPTERINDEXITEMNAME, info.ChapterIndex.ToString()); IniUtils.Write(ConfigFile, info.BookId, CHAPTEROFFSETITEMNAME, info.ChapterOffset.ToString()); IniUtils.Write(ConfigFile, info.BookId, BOOKNAMEITEMNAME, info.BookName); IniUtils.Write(ConfigFile, info.BookId, CHAPTERNAMEITEMNAME, info.ChapterName); }
public static void SetConfig(ConfigKey key, string value) { if (!File.Exists(ConfigFile)) { using (var fs = File.Create(ConfigFile)) { fs.Close(); } } IniUtils.Write(ConfigFile, CONFIGKEY, key.ToString(), value); }
public static void SaveCurrentBook(BookInfo info) { if (!File.Exists(ConfigFile)) { using (var fs = File.Create(ConfigFile)) { fs.Close(); } } if (!string.IsNullOrEmpty(info.FilePath)) { IniUtils.Write(ConfigFile, CURRENTKEY, BOOKIDITEMNAME, info.BookId); SaveBookData(info); return; } IniUtils.Write(ConfigFile, CURRENTKEY, BOOKIDITEMNAME, ""); }