private async void MakeCommandBarVisibleForAWhile() { int visibleTime = (int)((double)SettingStorage.GetValue("CommandBarShowTimespan") * 1000.0); if (visibleTime <= 0) { return; } CommandBar1.Visibility = Visibility.Visible; //CommandBar1.Foreground = new SolidColorBrush(Application.Current.RequestedTheme == ApplicationTheme.Dark ? RequestedThemeProperty.: Colors.Black);//ad-hoc fix me CommandBar1.Foreground = (Brush)Application.Current.Resources.ThemeDictionaries["AppBarItemForegroundThemeBrush"]; MakeCommandBarVisibleForAWhile_DelayCount++; await Task.Delay(visibleTime); MakeCommandBarVisibleForAWhile_DelayCount--; if (MakeCommandBarVisibleForAWhile_DelayCount == 0) { if (CommandBar1.FocusState != FocusState.Unfocused || CommandBar1.IsOpen) { MakeCommandBarVisibleForAWhile(); } else { CommandBar1.Foreground = new SolidColorBrush(Colors.Transparent); } } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { UIHelper.SetTitleByResource(this, "BookViewer"); if (e?.Parameter is null) { } else if (e.Parameter is Windows.ApplicationModel.Activation.IActivatedEventArgs) { var args = (Windows.ApplicationModel.Activation.IActivatedEventArgs)e.Parameter; if (args.Kind == Windows.ApplicationModel.Activation.ActivationKind.File) { foreach (var item in ((Windows.ApplicationModel.Activation.FileActivatedEventArgs)args).Files) { if (item is Windows.Storage.IStorageFile) { Open((Windows.Storage.IStorageFile)item); break; } } } } else if (e.Parameter is Books.IBookFixed) { Open((Books.IBookFixed)e.Parameter); } else if (e.Parameter is Windows.Storage.IStorageFile) { Open((Windows.Storage.IStorageFile)e.Parameter); } else if (e.Parameter is BookAndParentNavigationParamater) { var param = (BookAndParentNavigationParamater)e.Parameter; Open(param.BookViewerModel); //SetBookshelfModel(param.BookshelfModel); if (Binding != null) { Binding.Title = param.Title; } } else if (e.Parameter is Stream stream) { throw new NotImplementedException(); } var currentView = Windows.UI.Core.SystemNavigationManager.GetForCurrentView(); //currentView.AppViewBackButtonVisibility = Frame?.CanGoBack == true ? Windows.UI.Core.AppViewBackButtonVisibility.Visible : Windows.UI.Core.AppViewBackButtonVisibility.Collapsed; currentView.BackRequested += CurrentView_BackRequested; //このディレイがないとタブコントロールが表示されてしまう。親がロードされれば問題ないはずなのでディレイ。 //TrySetFullScreenMode()内のコメントアウト参照。そっちでの細かな経緯は忘れた。 //Without this Delay, Tab control is not hidden. See TrySetFullScreenMode(). await Task.Delay(500); if ((bool)SettingStorage.GetValue("DefaultFullScreen")) { TrySetFullScreenMode(true); } }
public async Task LoadAsync(Stream stream) { await Task.Run(() => { System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); try { Content = new ZipArchive(stream, ZipArchiveMode.Read, false, Encoding.GetEncoding(932)); OnLoaded(new EventArgs()); } catch { } } ); if (Content == null) { return; } var entries = new List <ZipArchiveEntry>(); string[] supportedFile = BookManager.AvailableExtensionsImage; var cm = Content.Mode; var files = Content.Entries; foreach (var file in files) { var s = Path.GetExtension(file.Name).ToLower(); var b = supportedFile.Contains(Path.GetExtension(file.Name).ToLower()); if (supportedFile.Contains(Path.GetExtension(file.Name).ToLower())) { entries.Add(file); } } IOrderedEnumerable <ZipArchiveEntry> tempOrder; if ((bool)SettingStorage.GetValue("SortNaturalOrder")) { tempOrder = entries.OrderBy((a) => new NaturalSort.NaturalList(a.FullName)); //entries.Sort((a, b) => NaturalSort.NaturalCompare(a.FullName, b.FullName)); } else { tempOrder = entries.OrderBy((a) => a.FullName); //entries.Sort((a, b) => a.FullName.CompareTo(b.FullName)); } if ((bool)SettingStorage.GetValue("SortCoverComesFirst")) { tempOrder = tempOrder.ThenBy((a) => a.FullName.ToLower().Contains("cover")); //entries.Sort((a, b) => b.FullName.ToLower().Contains("cover").CompareTo(a.FullName.ToLower().Contains("cover"))); } entries = tempOrder.ToList(); AvailableEntries = entries.ToArray(); }
public async void Initialize(Books.IBookFixed value, Control target = null) { this.Loading = true; if (BookInfo != null) { SaveInfo(); } this.Title = ""; var pages = new ObservableCollection <PageViewModel>(); var option = OptionCache = target == null ? OptionCache : new Books.PageOptionsControl(target); for (uint i = 0; i < value.PageCount; i++) { uint page = i; pages.Add(new PageViewModel(new Books.VirtualPage(() => { var p = value.GetPage(page); p.Option = option; return(p); }))); } this._Reversed = false; this._PageSelected = 0; ID = value.ID; this.Pages = pages; BookInfo = await BookInfoStorage.GetBookInfoByIDOrCreateAsync(value.ID); var tempPageSelected = (bool)SettingStorage.GetValue("SaveLastReadPage") ? (int)(BookInfo?.GetLastReadPage()?.Page ?? 1):1; this.PageSelected = tempPageSelected == this.PagesCount ? 1 : tempPageSelected; this.Reversed = BookInfo?.PageReversed ?? false; OnPropertyChanged(nameof(Reversed)); this.AsBookShelfBook = null; this.Bookmarks = new ObservableCollection <BookmarkViewModel>(); { var rl = new Windows.ApplicationModel.Resources.ResourceLoader(); var bm = new BookmarkViewModel() { Page = 1, AutoGenerated = true, Title = rl.GetString("BookmarkTop/Title") }; this.Bookmarks.Add(bm); } foreach (var bm in BookInfo.Bookmarks) { this.Bookmarks.Add(new BookmarkViewModel(bm)); } { var rl = new Windows.ApplicationModel.Resources.ResourceLoader(); var bm = new BookmarkViewModel() { Page = this.PagesCount, AutoGenerated = true, Title = rl.GetString("BookmarkLast/Title") }; this.Bookmarks.Add(bm); } this.Loading = false; }
public BookFixed2Viewer() { this.InitializeComponent(); OriginalTitle = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().Title; Application.Current.Suspending += CurrentApplication_Suspending; if (!(bool)SettingStorage.GetValue("ShowRightmostAndLeftmost")) { this.AppBarButtonLeftmost.Visibility = Visibility.Collapsed; this.AppBarButtonRightmost.Visibility = Visibility.Collapsed; } var brSet = (double)SettingStorage.GetValue("BackgroundBrightness"); var br = (byte)((Application.Current.RequestedTheme == ApplicationTheme.Dark ? 1 - brSet : brSet) / 100.0 * 255.0); this.Background = new SolidColorBrush(new Color() { A = 255, B = br, G = br, R = br }); ((BookViewModel)this.DataContext).PropertyChanged += (s, e) => { if (e.PropertyName == nameof(BookViewModel.Title)) { SetTitle(Binding?.Title); } }; flipView.UseTouchAnimationsForAllNavigation = (bool)SettingStorage.GetValue("ScrollAnimation"); if (Binding != null) { Binding.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(BookViewModel.Loading)) { flipView.Focus(FocusState.Programmatic); } }; } //if (Windows.Foundation.Metadata.ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 5)) { flipView.FocusVisualPrimaryBrush = new SolidColorBrush(Colors.Transparent); flipView.FocusVisualSecondaryBrush = new SolidColorBrush(Colors.Transparent); AppBarButtonBookmark.AllowFocusOnInteraction = true; } }
protected override void OnNavigatedTo(NavigationEventArgs e) { UIHelper.SetTitleByResource(this, "BookViewer"); if (e?.Parameter is null) { } else if (e.Parameter is Windows.ApplicationModel.Activation.IActivatedEventArgs) { var args = (Windows.ApplicationModel.Activation.IActivatedEventArgs)e.Parameter; if (args.Kind == Windows.ApplicationModel.Activation.ActivationKind.File) { foreach (var item in ((Windows.ApplicationModel.Activation.FileActivatedEventArgs)args).Files) { if (item is Windows.Storage.IStorageFile) { Open((Windows.Storage.IStorageFile)item); break; } } } } else if (e.Parameter is Books.IBookFixed) { Open((Books.IBookFixed)e.Parameter); } else if (e.Parameter is Windows.Storage.IStorageFile) { Open((Windows.Storage.IStorageFile)e.Parameter); } else if (e.Parameter is BookAndParentNavigationParamater) { var param = (BookAndParentNavigationParamater)e.Parameter; Open(param.BookViewerModel); //SetBookshelfModel(param.BookshelfModel); if (Binding != null) { Binding.Title = param.Title; } } var currentView = Windows.UI.Core.SystemNavigationManager.GetForCurrentView(); currentView.AppViewBackButtonVisibility = Frame?.CanGoBack == true ? Windows.UI.Core.AppViewBackButtonVisibility.Visible : Windows.UI.Core.AppViewBackButtonVisibility.Collapsed; currentView.BackRequested += CurrentView_BackRequested; if ((bool)SettingStorage.GetValue("DefaultFullScreen")) { var v = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView(); v.TryEnterFullScreenMode(); } }
public static async Task <BookContainerViewModel[]> GetFromBookShelfStorage(IEnumerable <BookShelfStorage.BookContainer> storages, BookShelfViewModel Shelf) { var result = new List <BookContainerViewModel>(); foreach (var item in storages) { if (SettingStorage.GetValue("FolderNameToExclude") == null || !((System.Text.RegularExpressions.Regex)SettingStorage.GetValue("FolderNameToExclude")).IsMatch(item.Title)) { result.Add(await GetFromBookShelfStorage(item, Shelf)); } } return(result.ToArray()); }
public async System.Threading.Tasks.Task OpenTabWebPreferedBrowser(string uri) { if ((bool)SettingStorage.GetValue("DefaultBrowserExternal")) { if (Uri.TryCreate(uri, UriKind.Absolute, out var uri1)) { await Windows.System.Launcher.LaunchUriAsync(uri1); } } else { OpenTabWeb(uri); } }
public static async Task <BookViewModel> GetFromBookShelfStorage(BookShelfStorage.BookContainer.BookShelfBook storage, BookContainerViewModel parent) { var reg1 = SettingStorage.GetValue("BookNameTrim") as System.Text.RegularExpressions.Regex; if (!await storage.Access.IsAccessible()) { return(null); } var result = new BookViewModel(storage.ID, storage.Size, storage.Access, parent) { Title = reg1 == null ? storage.Title : reg1.Replace(storage.Title, "") }; await result.GetFromBookInfoStorageAsync(); return(result); }
private async void MakeStackPanelZoomVisibleForAWhile() { int visibleTime = (int)((double)SettingStorage.GetValue("ZoomButtonShowTimespan") * 1000.0); if (visibleTime <= 0) { return; } StackPanelZoom.Visibility = Visibility.Visible; MakeStackPanelZoomVisibleForAWhile_DelayCount++; await Task.Delay(visibleTime); MakeStackPanelZoomVisibleForAWhile_DelayCount--; if (MakeStackPanelZoomVisibleForAWhile_DelayCount == 0) { StackPanelZoom.Visibility = Visibility.Collapsed; } }
public BookFixed3ViewerControllerControl() { this.InitializeComponent(); this.LosingFocus += BookFixed3ViewerControllerControl_LosingFocus; if (!(bool)SettingStorage.GetValue("ShowRightmostAndLeftmost")) { this.ButtonLeftmost.Visibility = Visibility.Collapsed; this.ButtonRightmost.Visibility = Visibility.Collapsed; } this.Loaded += (s, e) => { try { this.Focus(FocusState.Programmatic); } catch { } }; }
public async Task LoadAsync(System.IO.Stream sr) { SharpCompress.Archives.IArchive archive; await Task.Run(() => { try { archive = SharpCompress.Archives.ArchiveFactory.Open(sr); var entries = new List <SharpCompress.Archives.IArchiveEntry>(); foreach (var entry in archive.Entries) { if (!entry.IsDirectory && !entry.IsEncrypted) { if (BookManager.AvailableExtensionsImage.Contains(System.IO.Path.GetExtension(entry.Key).ToLower())) { entries.Add(entry); } } } IOrderedEnumerable <SharpCompress.Archives.IArchiveEntry> tempOrder; if ((bool)SettingStorage.GetValue("SortNaturalOrder")) { tempOrder = entries.OrderBy((a) => new NaturalSort.NaturalList(a.Key)); } else { tempOrder = entries.OrderBy((a) => a.Key); } if ((bool)SettingStorage.GetValue("SortCoverComesFirst")) { tempOrder = tempOrder.ThenBy((a) => a.Key.ToLower().Contains("cover")); } entries = tempOrder.ToList(); Entries = entries.ToArray(); OnLoaded(); } catch { this.Entries = new SharpCompress.Archives.IArchiveEntry[0]; } }); }
private void Button_Click_GoToBrowser(object sender, RoutedEventArgs e) { UIHelper.SetTitleByResource(this, "Browser"); string homepage = "https://www.google.com/"; if (SettingStorage.GetValue("WebHomePage") is string h) { homepage = h; } void OpenBrowser(TabPage tabPage) { var item = (this.Parent as Frame)?.Parent as Microsoft.UI.Xaml.Controls.TabViewItem; UIHelper.FrameOperation.OpenBrowser(this.Frame, homepage, (a) => { tabPage.OpenTabWeb(a); }, (b) => { tabPage.OpenTabBook(b); }, (c) => { { if (item != null) { item.Header = c; } } }); } var tab = UIHelper.GetCurrentTabPage(this); if (tab != null) { OpenBrowser(tab); } else { //ToDo: This will not be used. But set correct Action. UIHelper.FrameOperation.OpenBrowser(this.Frame, homepage, (a) => { }, (b) => { }, (c) => { }); } }
private async Task GetFromBookInfoStorageAsync(string ID) { var bookInfo = await Storages.BookInfoStorage.GetBookInfoByIDAsync(ID); if (bookInfo != null) { switch (bookInfo.PageDirection) { case Books.Direction.L2R: Reversed = false; break; case Books.Direction.R2L: Reversed = true; break; case Books.Direction.Default: default: Reversed = (bool)SettingStorage.GetValue("DefaultPageReverse"); break; } ReadRate = (bookInfo.GetLastReadPage()?.Page ?? 0) / (double)BookSize; //Issue: asyncの関係でSetLastReadPage()の前に GetLastReadPage()が実行されることがあるようだ。 } else { Reversed = false; ReadRate = 0; } }
public BookFixed3Viewer() { this.InitializeComponent(); if (Binding != null) { Binding.ToggleFullScreenCommand = new DelegateCommand((a) => ToggleFullScreen()); } if (Binding != null) { Binding.GoToHomeCommand = new DelegateCommand((a) => { Binding?.SaveInfo(); Frame.Navigate(typeof(Bookshelf.NavigationPage), null); }); } Application.Current.Suspending += (s, e) => Binding?.SaveInfo(); OriginalTitle = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().Title; ((BookViewModel)this.DataContext).PropertyChanged += (s, e) => { if (e.PropertyName == nameof(BookViewModel.Title)) { SetTitle(Binding?.Title); } }; var brSet = (double)SettingStorage.GetValue("BackgroundBrightness"); var br = (byte)((Application.Current.RequestedTheme == ApplicationTheme.Dark ? 1 - brSet : brSet) / 100.0 * 255.0); var color = new Color() { A = 255, B = br, G = br, R = br }; this.Background = new AcrylicBrush() { BackgroundSource = AcrylicBackgroundSource.HostBackdrop, TintColor = color, FallbackColor = color, TintOpacity = 0.8 }; flipView.UseTouchAnimationsForAllNavigation = (bool)SettingStorage.GetValue("ScrollAnimation"); if (Binding != null) { Binding.PagePropertyChanged += async(s, e) => { if ((e.Item1 == flipView.SelectedItem || e.Item1?.NextPage?.NextPage == flipView.SelectedItem) && e.Item2.PropertyName == nameof(PageViewModel.SpreadDisplayedStatus)) { await Binding.UpdatePages(this.Dispatcher); } }; } flipView.SelectionChanged += async(s, e) => { if (e.AddedItems.Count > 0 && e.AddedItems[0] is PageViewModel vm) { await Binding?.UpdatePages(this.Dispatcher); } }; }
public BookFixed3Viewer() { this.InitializeComponent(); if (Binding != null) { Binding.ToggleFullScreenCommand = new Helper.DelegateCommand((a) => ToggleFullScreen()); } if (Binding != null) { Binding.GoToHomeCommand = new Helper.DelegateCommand((a) => { Binding?.SaveInfo(); this.Frame.Navigate(typeof(HomePage), null); }); } Application.Current.Suspending += (s, e) => Binding?.SaveInfo(); OriginalTitle = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().Title; ((BookViewModel)this.DataContext).PropertyChanged += (s, e) => { if (e.PropertyName == nameof(ViewModels.BookViewModel.Title)) { SetTitle(Binding?.Title); } }; var brSet = (double)SettingStorage.GetValue("BackgroundBrightness"); var br = (byte)((Application.Current.RequestedTheme == ApplicationTheme.Dark ? 1 - brSet : brSet) / 100.0 * 255.0); //this.Background = new SolidColorBrush(new Windows.UI.Color() { A = 255, B = br, G = br, R = br }); var color = new Windows.UI.Color() { A = 255, B = br, G = br, R = br }; this.Background = new AcrylicBrush() { BackgroundSource = AcrylicBackgroundSource.HostBackdrop, TintColor = color, FallbackColor = color, TintOpacity = 0.8 }; flipView.UseTouchAnimationsForAllNavigation = (bool)SettingStorage.GetValue("ScrollAnimation"); flipView.SelectionChanged += (s, e) => { if (e.AddedItems.Count > 0 && e.AddedItems[0] is ViewModels.PageViewModel vm) { int current = Binding?.Pages.IndexOf(vm) ?? -1; var prevPage = current >= 1 ? Binding.Pages[current - 1] : null; var prevPrevPage = current >= 2 ? Binding.Pages[current - 2] : null; switch (vm.SpreadDisplayedStatus) { case SpreadPagePanel.DisplayedStatusEnum.Spread: break; } } //ToDo:見開き対応。 // //1. 以前選択されていたページのイベントを取り消す。 //2. 全ページリストアする? //3. 選択中のページの見開き状態から次ページを表示するか切り替える。 //4. 選択中のページの見開き状態の変化イベントを登録する。 //5. 前のページの見開き状態が、 // a) 1ページなら何もしない。 // b) 半ページなら前に半ページ後半を挿入する。 // c) 2ページかつ2ページ前の見開き状態が2ページなら前ページを削除する。 // d) 2ページかつ2ページ前の見開き状態が1ページなら前ページを強制1ページ表示にする。 //6. 前ページの見開き状態の変化イベントを登録する。 //うわしんど。 }; }
public async Task LoadAsync(Stream sr) { SharpCompress.Archives.IArchive archive; await Task.Run(() => { try { archive = SharpCompress.Archives.ArchiveFactory.Open(sr); var entries = new List <SharpCompress.Archives.IArchiveEntry>(); foreach (var entry in archive.Entries) { if (!entry.IsDirectory && !entry.IsEncrypted) { if (BookManager.AvailableExtensionsImage.Contains(Path.GetExtension(entry.Key).ToLower())) { entries.Add(entry); } } } IOrderedEnumerable <SharpCompress.Archives.IArchiveEntry> tempOrder; if ((bool)SettingStorage.GetValue("SortNaturalOrder")) { tempOrder = entries.OrderBy((a) => new NaturalSort.NaturalList(a.Key)); } else { tempOrder = entries.OrderBy((a) => a.Key); } if ((bool)SettingStorage.GetValue("SortCoverComesFirst")) { tempOrder = tempOrder.ThenBy((a) => a.Key.ToLower().Contains("cover")); } entries = tempOrder.ToList(); { //toc関係 var toc = new List <TocItem>(); for (int i = 0; i < entries.Count; i++) { var dirs = Path.GetDirectoryName(entries[i].Key).Split(Path.DirectorySeparatorChar).ToList(); dirs.Add("."); var ctoc = toc; TocItem lastitem = null; for (int j = 0; j < dirs.Count(); j++) { dirs[j] = dirs[j] == "" ? "." : dirs[j]; if (ctoc.Count == 0 || ctoc.Last().Title != dirs[j]) { ctoc.Add(new TocItem() { Children = new TocItem[0], Title = dirs[j], Page = i }); } if (lastitem != null) { lastitem.Children = ctoc.ToArray(); } lastitem = ctoc.Last(); ctoc = lastitem.Children.ToList(); } } Toc = toc.ToArray(); } Entries = entries.ToArray(); OnLoaded(); } catch { Entries = new SharpCompress.Archives.IArchiveEntry[0]; } }); }
public void OpenTabWeb() { OpenTabWeb(SettingStorage.GetValue("WebHomePage") as string ?? "https://www.google.com/"); }
public static void OpenBrowser(Frame frame, string uri, Action <string> OpenTabWeb, Action <Windows.Storage.IStorageItem> OpenTabBook, Action <string> UpdateTitle) { frame?.Navigate(typeof(kurema.BrowserControl.Views.BrowserPage), uri); if (frame?.Content is kurema.BrowserControl.Views.BrowserPage content) { content.Control.Control.NewWindowRequested += (s, e) => { OpenTabWeb?.Invoke(e.Uri.ToString()); e.Handled = true; }; content.Control.Control.UnviewableContentIdentified += async(s, e) => { string extension = ""; foreach (var ext in BookManager.AvailableExtensionsArchive) { if (Path.GetExtension(e.Uri.ToString()).ToLower() == ext) { extension = ext; goto success; } } success :; try { var namebody = Path.GetFileNameWithoutExtension(e.Uri.ToString()); namebody = namebody.Length > 32 ? namebody.Substring(0, 32) : namebody; var item = await Windows.Storage.ApplicationData.Current.TemporaryFolder.CreateFileAsync( Path.Combine("Download", namebody + extension) , Windows.Storage.CreationCollisionOption.GenerateUniqueName); var downloader = new BackgroundDownloader(); var download = downloader.CreateDownload(e.Uri, item); var vmb = content.Control.DataContext as kurema.BrowserControl.ViewModels.BrowserControlViewModel; var dlitem = new kurema.BrowserControl.ViewModels.DownloadItemViewModel(item.Name); vmb?.Downloads.Add(dlitem); await download.StartAsync().AsTask(new Progress <DownloadOperation>((t) => { try { //https://stackoverflow.com/questions/38939720/backgrounddownloader-progress-doesnt-update-in-uwp-c-sharp if (t.Progress.TotalBytesToReceive > 0) { double br = t.Progress.TotalBytesToReceive; dlitem.DownloadedRate = br / t.Progress.TotalBytesToReceive; } } catch { } })); dlitem.DownloadedRate = 1.0; dlitem.OpenCommand = new DelegateCommand((a) => OpenTabBook?.Invoke(item)); OpenTabBook?.Invoke(item); BookViewerApp.App.Current.Suspending += async(s2, e2) => { try { await item.DeleteAsync(); } catch { } }; } catch { } return; }; } if ((frame.Content as kurema.BrowserControl.Views.BrowserPage)?.Control.DataContext is kurema.BrowserControl.ViewModels.BrowserControlViewModel vm && vm != null) { if (SettingStorage.GetValue("WebHomePage") is string homepage) { vm.HomePage = homepage; } vm.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(kurema.BrowserControl.ViewModels.BrowserControlViewModel.Title)) { UpdateTitle(vm.Title); } }; } }
public async Task LoadAsync(Stream stream) { await Task.Run(() => { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); try { Content = new ZipArchive(stream, ZipArchiveMode.Read, false, System.Globalization.CultureInfo.CurrentCulture.TwoLetterISOLanguageName == "ja" ? Encoding.GetEncoding(932) : Encoding.UTF8); OnLoaded(new EventArgs()); } catch { } } ); if (Content == null) { return; } var entries = new List <ZipArchiveEntry>(); string[] supportedFile = BookManager.AvailableExtensionsImage; var cm = Content.Mode; var files = Content.Entries; foreach (var file in files) { var s = Path.GetExtension(file.Name).ToLower(); var b = supportedFile.Contains(Path.GetExtension(file.Name).ToLower()); if (supportedFile.Contains(Path.GetExtension(file.Name).ToLower())) { entries.Add(file); } } IOrderedEnumerable <ZipArchiveEntry> tempOrder; if ((bool)SettingStorage.GetValue("SortNaturalOrder")) { tempOrder = entries.OrderBy((a) => new NaturalSort.NaturalList(a.FullName)); //entries.Sort((a, b) => NaturalSort.NaturalCompare(a.FullName, b.FullName)); } else { tempOrder = entries.OrderBy((a) => a.FullName); //entries.Sort((a, b) => a.FullName.CompareTo(b.FullName)); } if ((bool)SettingStorage.GetValue("SortCoverComesFirst")) { tempOrder = tempOrder.ThenBy((a) => a.FullName.ToLower().Contains("cover")); //entries.Sort((a, b) => b.FullName.ToLower().Contains("cover").CompareTo(a.FullName.ToLower().Contains("cover"))); } entries = tempOrder.ToList(); { //toc関係 var toc = new List <TocItem>(); for (int i = 0; i < entries.Count; i++) { var dirs = Path.GetDirectoryName(entries[i].FullName).Split(Path.DirectorySeparatorChar).ToList(); dirs.Add("."); var ctoc = toc; TocItem lastitem = null; for (int j = 0; j < dirs.Count(); j++) { dirs[j] = dirs[j] == "" ? "." : dirs[j]; if (ctoc.Count == 0 || ctoc.Last().Title != dirs[j]) { ctoc.Add(new TocItem() { Children = new TocItem[0], Title = dirs[j], Page = i }); } if (lastitem != null) { lastitem.Children = ctoc.ToArray(); } lastitem = ctoc.Last(); ctoc = lastitem.Children.ToList(); } } Toc = toc.ToArray(); } AvailableEntries = entries.ToArray(); }
public BookShelfControl() { this.InitializeComponent(); SetBookShelfItemSize((double)SettingStorage.GetValue("TileWidth"), (double)SettingStorage.GetValue("TileHeight")); }
public static async void OpenEpub(Frame frame, Windows.Storage.IStorageFile file, FrameworkElement sender) { if (file is null) { return; } if (sender is null) { return; } SetTitleByResource(sender, "Epub"); var tabPage = GetCurrentTabPage(sender); var epubType = SettingStorage.GetValue("EpubViewerType") as SettingStorage.SettingEnums.EpubViewerType?; EpubResolverBase resolver = epubType switch { //SettingStorage.SettingEnums.EpubViewerType.Bibi => EpubResolverFile.GetResolverBibi(file), SettingStorage.SettingEnums.EpubViewerType.Bibi => await EpubResolverBase.GetResolverBibiZip(file), SettingStorage.SettingEnums.EpubViewerType.EpubJsReader => EpubResolverBase.GetResolverBasicFile(file), _ => await EpubResolverBase.GetResolverBibiZip(file), }; frame.Navigate(typeof(kurema.BrowserControl.Views.BrowserControl), null); if (frame.Content is kurema.BrowserControl.Views.BrowserControl content) { OpenBrowser_BookmarkSetViewModel(content?.DataContext as kurema.BrowserControl.ViewModels.BrowserControlViewModel); Uri uri = content.Control.BuildLocalStreamUri("epub", resolver.PathHome); content.Control.NavigateToLocalStreamUri(uri, resolver); if (tabPage is not null) { content.Control.NewWindowRequested += async(s, e) => { await tabPage.OpenTabWebPreferedBrowser(e.Uri.ToString()); e.Handled = true; }; } if (content.DataContext is kurema.BrowserControl.ViewModels.BrowserControlViewModel vm) { vm.ControllerCollapsed = true; } { { //普通ブラウザでもダークモード対応するのも選択肢。でもbackgroundとか修正しないといけないし、とりあえずなし。 var defaultDark = (bool)SettingStorage.GetValue("EpubViewerDarkMode") && Application.Current.RequestedTheme == ApplicationTheme.Dark; var checkbox = new CheckBox() { Content = ResourceManager.Loader.GetString("Browser/Addon/DarkMode"), IsChecked = defaultDark, HorizontalAlignment = HorizontalAlignment.Stretch }; async Task applyDarkMode() { if (checkbox.IsChecked ?? false) { //if (epubType == SettingStorage.SettingEnums.EpubViewerType.Bibi) await content.Control.InvokeScriptAsync("eval", new[] { @"if(document.body.style.background===""""){document.body.style.background='white';}" }); await content.Control.InvokeScriptAsync("eval", new[] { @"document.body.style.filter='invert(100%) hue-rotate(180deg)';" }); } else { //if (epubType == SettingStorage.SettingEnums.EpubViewerType.Bibi) await content.Control.InvokeScriptAsync("eval", new[] { @"if(document.body.style.background===""white""){document.body.style.background='';}" }); await content.Control.InvokeScriptAsync("eval", new[] { @"document.body.style.filter='none';" }); } } checkbox.Checked += async(s, e) => { await applyDarkMode(); }; checkbox.Unchecked += async(s, e) => { await applyDarkMode(); }; content.Control.NavigationCompleted += async(s, e) => { await applyDarkMode(); }; content.AddOnSpace.Add(checkbox); } { var checkbox = new CheckBox() { Content = ResourceManager.Loader.GetString("Setting_EpubViewerDarkMode/Title"), IsChecked = (bool)SettingStorage.GetValue("EpubViewerDarkMode"), HorizontalAlignment = HorizontalAlignment.Stretch, }; ToolTipService.SetToolTip(checkbox, ResourceManager.Loader.GetString("Setting_EpubViewerDarkMode/Description")); checkbox.Checked += (s, e) => SettingStorage.SetValue("EpubViewerDarkMode", true); checkbox.Unchecked += (s, e) => SettingStorage.SetValue("EpubViewerDarkMode", false); content.AddOnSpace.Add(checkbox); } } //content.Control.ScriptNotify += (s, e) => //{ // //window.external.notify(document.body.style.background); // var v = e.Value; //}; } HistoryManager.AddEntry(file); //await HistoryStorage.AddHistory(file, null); }