示例#1
0
    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);
        }
    }
示例#3
0
 private void Reset_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
 {
     //reset settings
     SettingStorage.Reset();
     //update view
     UpdateView();
 }
示例#4
0
        public MainWindow()
        {
            InitializeComponent();
            SettingStorage.Initialize();

            Exit.Click += (e, o) => Close();

            Title = $"WDBXEditor2  -  {Constants.Version}";
        }
示例#5
0
        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();
        }
示例#6
0
        private void LocaleSelected(object sender, SelectionChangedEventArgs e)
        {
            LocaleSelectInfo localSelectData = (LocaleSelectList.SelectedItem as LocaleSelectInfo);

            if (localSelectData.Locale != SelectedLocale)
            {
                SelectedLocale = localSelectData.Locale;
                SettingStorage.Store("LastLocaleSelectedIndex", LocaleSelectList.SelectedIndex.ToString());
            }
        }
示例#7
0
 public override void SaveSettings(Panel s)
 {
     SettingStorage.Save(s);
     foreach (var settings in Panel.GetAllSettings())
     {
         if (settings.GetType() == s.GetType() && settings != s)
         {
             SettingStorage.Load(settings.GetType(), settings);
         }
     }
 }
示例#8
0
        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;
        }
示例#9
0
 static void Main(string[] args)
 {
     {
         SettingStorage settingStorage = new SettingStorage("test.ini", Format.INI);
         settingStorage["n1"]["k1"] = 1;
         settingStorage.Save();
         Console.WriteLine(settingStorage["n1"]["k1"].AsInt(0));
         Console.WriteLine(settingStorage["n1"]["k2"].AsInt(0));
         Console.WriteLine(settingStorage["n1"]["k2"].AsInt());
         Console.ReadKey();
     }
 }
示例#10
0
    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;
        }
    }
示例#11
0
    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();
        }
    }
示例#12
0
        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());
        }
示例#13
0
 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);
     }
 }
示例#14
0
        public GeneralForm()
        {
            select_visitor = new ExhibitionVisitor();
            InitializeComponent();
            List <PharmaVisitor> dgv_collection = null;

            initialDataGread(dgv_collection);
            ss        = new SettingStorage();
            templForm = new TemplateForm(ss);
            var count = context.ExhibitionVisitors.Where(v => v.Status != "registered").Select(s => s).Count() - 1;

            lb_count.Text = count.ToString();
            lbl_payment_status.Visible = false;
        }
示例#15
0
        public DefinitionSelect()
        {
            InitializeComponent();
            DefinitionSelectList.Focus();
            DefinitionSelectList.ItemsSource = definitionSelectData;
            LocaleSelectList.ItemsSource     = localeSelectData;

            string lastLocaleSelectedIndexSetting = SettingStorage.Get("LastLocaleSelectedIndex");

            if (lastLocaleSelectedIndexSetting != null)
            {
                int lastLocaleSelectedIndex = int.Parse(lastLocaleSelectedIndexSetting);
                LocaleSelectList.SelectedIndex = lastLocaleSelectedIndex;
            }
        }
示例#16
0
        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);
        }
示例#17
0
    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;
        }
    }
示例#18
0
    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 { }
        };
    }
示例#19
0
        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]; }
            });
        }
示例#20
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;
            }
        }
示例#22
0
 public SettingViewModel(SettingStorage.SettingInstance instance)
 {
     target = instance;
 }
示例#23
0
        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. 前ページの見開き状態の変化イベントを登録する。

                //うわしんど。
            };
        }
示例#24
0
 public override void LoadSettings(Panel s)
 {
     SettingStorage.Load(s.GetType(), s);
 }
示例#25
0
 public ConfigStorage(string appPath)
 {
     _settings         = new SettingStorage(appPath + "\\" + ConfigDbFile, _lockConfDb);
     _settingsAction   = new ActionsStorage(appPath + "\\" + ConfigDbFile, _lockConfDb);
     _settingsSchedule = new ScheduleStorage(appPath + "\\" + ConfigDbFile, _lockConfDb);
 }
示例#26
0
        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]; }
            });
        }
示例#27
0
 public void OpenTabWeb()
 {
     OpenTabWeb(SettingStorage.GetValue("WebHomePage") as string ?? "https://www.google.com/");
 }
    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);
            }
        };
    }
示例#29
0
        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 SettingBag1Loader(SettingStorage settingStorage)
 {
     _settingStorage = settingStorage;
 }
        public BookShelfControl()
        {
            this.InitializeComponent();

            SetBookShelfItemSize((double)SettingStorage.GetValue("TileWidth"), (double)SettingStorage.GetValue("TileHeight"));
        }
示例#32
0
            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);
                        }
                    };
                }
            }