private void BtnImportOnClick(object sender, RoutedEventArgs e)
        {
            var btn      = sender as Button;
            var bookInfo = btn.DataContext as BookInfo;

            ConfigSevice.SaveBook(ref bookInfo);
            btn.IsEnabled = false;
        }
Esempio n. 2
0
        private void SaveConfig()
        {
            var isMaximized = WindowState == WindowState.Maximized;

            ConfigSevice.SetConfig(ConfigKey.WindowMaximized, isMaximized ? "1":"0");
            if (!isMaximized)
            {
                ConfigSevice.SetConfig(ConfigKey.WindowSize, string.Format("{0},{1}", ActualWidth.ToString("F"), ActualHeight.ToString("F")));
            }
            ConfigSevice.SetConfig(ConfigKey.WindowOpacity, Opacity.ToString("F"));
            ConfigSevice.SetConfig(ConfigKey.Background, (BdBackground.Background as SolidColorBrush).Color.ToString());
            ConfigSevice.SetConfig(ConfigKey.FontSize, sFontSize.Value.ToString("F"));
            ConfigSevice.SetConfig(ConfigKey.FontBrightness, sBrightness.Value.ToString("F"));
        }
Esempio n. 3
0
 private void SaveCurrentBook()
 {
     if (_bookInfo == null)
     {
         return;
     }
     _bookInfo.ChapterIndex  = _chapters.IndexOf(_currentChapter);
     _bookInfo.ChapterOffset = TbContent.VerticalOffset;
     if (_currentChapter != null)
     {
         var rgx = new Regex(_txtRegex);
         _bookInfo.ChapterName = rgx.Match(_currentChapter.Content).Value;
     }
     ConfigSevice.SaveCurrentBook(_bookInfo);
 }
Esempio n. 4
0
 private void BtnDel(object sender, RoutedEventArgs e)
 {
     LsCatalog.ItemsSource = null;
     TbContent.Text        = "";
     TbBookName.Text       = "";
     TbChapter.Text        = "";
     _file = "";
     _chapters.Clear();
     _currentChapter = null;
     if (_bookInfo != null && !string.IsNullOrEmpty(_bookInfo.BookId))
     {
         ConfigSevice.DelBook(_bookInfo.BookId);
     }
     _bookInfo = null;
 }
Esempio n. 5
0
        private void LoadBookShelft()
        {
            var list = ConfigSevice.GetAllBooks();

            if (list != null && list.Count > 0 && _bookInfo != null && !string.IsNullOrEmpty(_bookInfo.BookId))
            {
                var book = list.First(o => o.BookId == _bookInfo.BookId);
                if (_currentChapter != null)
                {
                    var rgx = new Regex(_txtRegex);
                    book.ChapterName = rgx.Match(_currentChapter.Content).Value;
                }
                list.Remove(book);
                list.Insert(0, book);
            }
            ListCtrlBookShelf.ItemsSource = list;
        }
Esempio n. 6
0
        private void LoadConfig()
        {
            var isMaximized = ConfigSevice.GetConfig(ConfigKey.WindowMaximized, "0") == "1";

            if (!isMaximized)
            {
                var size = ConfigSevice.GetConfig(ConfigKey.WindowSize);
                if (!string.IsNullOrEmpty(size))
                {
                    var sizeArr = size.Split(',');
                    if (sizeArr.Length == 2)
                    {
                        Width  = double.Parse(sizeArr[0]);
                        Height = double.Parse(sizeArr[1]);
                    }
                }
            }
            else
            {
                WindowState = WindowState.Maximized;
            }
            var opacity = ConfigSevice.GetConfig(ConfigKey.WindowOpacity, "0.8");

            sOpacity.Value = double.Parse(opacity);
            var background = ConfigSevice.GetConfig(ConfigKey.Background, "#AAA");

            BdBackground.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(background));
            foreach (RadioButton child in SpSetting.Children.Cast <object>().Where(child => child is RadioButton))
            {
                var str = (child.Background as SolidColorBrush).Color.ToString();
                if (str == background)
                {
                    child.IsChecked = true;
                }
            }
            var fontsize = ConfigSevice.GetConfig(ConfigKey.FontSize, "14");

            sFontSize.Value = double.Parse(fontsize);
            var brightness = ConfigSevice.GetConfig(ConfigKey.FontBrightness, "0");

            sBrightness.Value = double.Parse(brightness);
        }
Esempio n. 7
0
 private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
 {
     if (ConfigSevice.IsShowFloatingWin)
     {
         _floatingWin = new FloatingWin {
             Owner = this
         };
         _floatingWin.Left = SystemParameters.VirtualScreenWidth - _floatingWin.Width;
         _floatingWin.Top  = 0;
         _floatingWin.Show();
     }
     //var web = new WebBook("http://www.biquge.tw/59_59883/");
     //return;
     LoadConfig();
     _txtRegex = ConfigSevice.DefaultTxtRegex1;
     if (!ConfigSevice.GetCurrentBookInfo(out _bookInfo))
     {
         return;
     }
     _file = _bookInfo.FilePath;
     new Thread(GetChapters).Start();
 }
Esempio n. 8
0
        private void BookOnDel(object sender, MouseButtonEventArgs e)
        {
            var book = (sender as Border).DataContext as BookInfo;

            if (book == null || string.IsNullOrEmpty(book.BookId))
            {
                return;
            }
            ConfigSevice.DelBook(book.BookId);
            if (_bookInfo != null && book.BookId == _bookInfo.BookId)
            {
                _bookInfo             = null;
                LsCatalog.ItemsSource = null;
                TbContent.Text        = "";
                TbBookName.Text       = "";
                TbChapter.Text        = "";
                _file = "";
                _chapters.Clear();
                _currentChapter = null;
            }
            LoadBookShelft();
            e.Handled = true;
        }
Esempio n. 9
0
        private void GetChapters()
        {
            _chapters.Clear();
            if (!File.Exists(_file))
            {
                _autoLoad = false;
                return;
            }
            var name = FileHelper.GetFileNameNoneExt(_file);

            if (!_file.EndsWith(ConfigSevice.BookExt))
            {
                var tmpFile = ConfigSevice.BookDir + name + ConfigSevice.BookExt;
                FileHelper.FileToUTF8(_file, tmpFile);
                _file = tmpFile;
            }
            var rgx = new Regex(_txtRegex);

            using (StreamReader sr = File.OpenText(_file))
            {
                string s;
                int    lineNum = 1;
                while ((s = sr.ReadLine()) != null)
                {
                    if (rgx.IsMatch(s))
                    {
                        var count = _chapters.Count;
                        if (count <= 0 || (lineNum - _chapters[count - 1].LineNum) > 5)
                        {
                            if (count <= 0 && lineNum > 5)
                            {
                                _chapters.Add(new ChaptersInfo
                                {
                                    Content = "序",
                                    LineNum = 0
                                });
                            }
                            _chapters.Add(new ChaptersInfo
                            {
                                Content = s,
                                LineNum = lineNum
                            });
                        }
                    }
                    lineNum++;
                }
            }
            if (_chapters.Count <= 0 && !_regexChanged)
            {
                ReloadBook();
                return;
            }
            Dispatcher.Invoke(() =>
            {
                LsCatalog.ItemsSource = _chapters;
                if (_chapters.Count > 0)
                {
                    if (_autoLoad)
                    {
                        LsCatalog.SelectedIndex = _bookInfo.ChapterIndex < 0 ? 0 : _bookInfo.ChapterIndex;
                    }
                    else
                    {
                        _bookInfo = new BookInfo
                        {
                            BookName = name,
                            FilePath = _file
                        };
                        ConfigSevice.SaveBook(ref _bookInfo);
                        LsCatalog.SelectedIndex = 0;
                    }
                    TbBookName.Text = string.Format("《{0}》", _bookInfo.BookName);
                }
            });
        }