async void ExecuteImportBackupCommand() { try { var picker = new FileOpenPicker(); picker.ViewMode = PickerViewMode.List; picker.FileTypeFilter.Add(".json"); var file = await picker.PickSingleFileAsync(); if (file != null) { try { var backup = await _backupManager.ReadBackupContainerAsync(file, default); Action <BackupContainer>[] BackupActions = new Action <BackupContainer>[] { _backupManager.RestoreLocalMylist, _backupManager.RestoreSubscription, _backupManager.RestorePin, _backupManager.RestoreRankingSettings, _backupManager.RestoreVideoFilteringSettings, _backupManager.RestorePlayerSettings, _backupManager.RestoreAppearanceSettings, _backupManager.RestoreNicoRepoSettings, _backupManager.RestoreCommentSettings, }; List <Exception> exceptions = new List <Exception>(); foreach (var backupAction in BackupActions) { try { backupAction(backup); } catch (Exception e) { exceptions.Add(e); } } WeakReferenceMessenger.Default.Send <SettingsRestoredMessage>(); _notificationService.ShowLiteInAppNotification_Success("BackupRestoreComplete".Translate()); NGVideoOwnerUserIds = _videoFilteringRepository.GetVideoOwnerIdFilteringEntries(); OnPropertyChanged(nameof(NGVideoOwnerUserIds)); VideoTitleFilteringItems.Clear(); foreach (var item in _videoFilteringRepository.GetVideoTitleFilteringEntries().Select(x => new VideoFilteringTitleViewModel(x, OnRemoveVideoTitleFilterEntry, _videoFilteringRepository, TestText))) { VideoTitleFilteringItems.Add(item); } if (exceptions.Any()) { throw new AggregateException(exceptions); } } catch { _notificationService.ShowLiteInAppNotification_Fail("BackupRestoreFailed".Translate()); throw; } } } catch (Exception e) { _logger.ZLogError(e, "Backup import failed"); } }
public SettingsPageViewModel( PageManager pageManager, NotificationService toastService, Services.DialogService dialogService, PlayerSettings playerSettings, VideoRankingSettings rankingSettings, NicoRepoSettings nicoRepoSettings, AppearanceSettings appearanceSettings, VideoCacheSettings cacheSettings, VideoCacheFolderManager videoCacheFolderManager, ApplicationLayoutManager applicationLayoutManager, VideoFilteringSettings videoFilteringRepository, BackupManager backupManager, ILoggerFactory loggerFactory ) { _notificationService = toastService; RankingSettings = rankingSettings; _HohoemaDialogService = dialogService; PlayerSettings = playerSettings; ActivityFeedSettings = nicoRepoSettings; AppearanceSettings = appearanceSettings; VideoCacheSettings = cacheSettings; _videoCacheFolderManager = videoCacheFolderManager; ApplicationLayoutManager = applicationLayoutManager; _videoFilteringRepository = videoFilteringRepository; _backupManager = backupManager; _logger = loggerFactory.CreateLogger <SettingsPageViewModel>(); // NG Video Owner User Id NGVideoOwnerUserIdEnable = _videoFilteringRepository.ToReactivePropertyAsSynchronized(x => x.NGVideoOwnerUserIdEnable) .AddTo(_CompositeDisposable); NGVideoOwnerUserIds = _videoFilteringRepository.GetVideoOwnerIdFilteringEntries(); OpenUserPageCommand = new RelayCommand <VideoOwnerIdFilteringEntry>(userIdInfo => { pageManager.OpenPageWithId(HohoemaPageType.UserInfo, userIdInfo.UserId); }); // NG Keyword on Video Title VideoTitleFilteringItems = new ObservableCollection <VideoFilteringTitleViewModel>(); NGVideoTitleKeywordEnable = _videoFilteringRepository.ToReactivePropertyAsSynchronized(x => x.NGVideoTitleKeywordEnable) .AddTo(_CompositeDisposable); TestText = _videoFilteringRepository.ToReactivePropertyAsSynchronized(x => x.NGVideoTitleTestText) .AddTo(_CompositeDisposable); /* * NGVideoTitleKeywordError = NGVideoTitleKeywords * .Select(x => * { * if (x == null) { return null; } * * var keywords = x.Split('\r'); * var invalidRegex = keywords.FirstOrDefault(keyword => * { * Regex regex = null; * try * { * regex = new Regex(keyword); * } * catch { } * return regex == null; * }); * * if (invalidRegex == null) * { * return null; * } * else * { * return $"Error in \"{invalidRegex}\""; * } * }) * .ToReadOnlyReactiveProperty() * .AddTo(_CompositeDisposable); */ // アピアランス StartupPageType = AppearanceSettings.ToReactivePropertyAsSynchronized(x => x.FirstAppearPageType) .AddTo(_CompositeDisposable); var currentTheme = App.GetTheme(); SelectedTheme = new ReactiveProperty <ElementTheme>(AppearanceSettings.ApplicationTheme, mode: ReactivePropertyMode.DistinctUntilChanged) .AddTo(_CompositeDisposable); SelectedTheme.Subscribe(theme => { AppearanceSettings.ApplicationTheme = theme; ApplicationTheme appTheme; if (theme == ElementTheme.Default) { appTheme = Views.Helpers.SystemThemeHelper.GetSystemTheme(); } else if (theme == ElementTheme.Dark) { appTheme = ApplicationTheme.Dark; } else { appTheme = ApplicationTheme.Light; } App.SetTheme(appTheme); var appView = ApplicationView.GetForCurrentView(); if (appTheme == ApplicationTheme.Light) { appView.TitleBar.ButtonForegroundColor = Colors.Black; appView.TitleBar.ButtonHoverBackgroundColor = Colors.DarkGray; appView.TitleBar.ButtonHoverForegroundColor = Colors.Black; appView.TitleBar.ButtonInactiveForegroundColor = Colors.Gray; } else { appView.TitleBar.ButtonForegroundColor = Colors.White; appView.TitleBar.ButtonHoverBackgroundColor = Colors.DimGray; appView.TitleBar.ButtonHoverForegroundColor = Colors.White; appView.TitleBar.ButtonInactiveForegroundColor = Colors.DarkGray; } }) .AddTo(_CompositeDisposable); IsDefaultFullScreen = new ReactiveProperty <bool>(ApplicationView.PreferredLaunchWindowingMode == ApplicationViewWindowingMode.FullScreen) .AddTo(_CompositeDisposable); IsDefaultFullScreen.Subscribe(x => { if (x) { ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen; } else { ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto; } }) .AddTo(_CompositeDisposable); AppearanceSettings.ObserveProperty(x => x.Locale, isPushCurrentValueAtFirst: false).Subscribe(locale => { I18NPortable.I18N.Current.Locale = locale; }) .AddTo(_CompositeDisposable); // キャッシュ DefaultCacheQuality = VideoCacheSettings.ToReactivePropertyAsSynchronized(x => x.DefaultCacheQuality) .AddTo(_CompositeDisposable); IsAllowDownloadOnMeteredNetwork = VideoCacheSettings.ToReactivePropertyAsSynchronized(x => x.IsAllowDownloadOnMeteredNetwork) .AddTo(_CompositeDisposable); MaxVideoCacheStorageSize = VideoCacheSettings.ToReactivePropertyAsSynchronized(x => x.MaxVideoCacheStorageSize) .AddTo(_CompositeDisposable); OpenCurrentCacheFolderCommand = new RelayCommand(async() => { var folder = _videoCacheFolderManager.VideoCacheFolder; if (folder != null) { await Windows.System.Launcher.LaunchFolderAsync(folder); } }); // シェア IsLoginTwitter = new ReactiveProperty <bool>(/*TwitterHelper.IsLoggedIn*/ false) .AddTo(_CompositeDisposable); TwitterAccountScreenName = new ReactiveProperty <string>(/*TwitterHelper.TwitterUser?.ScreenName ?? ""*/) .AddTo(_CompositeDisposable); StringBuilder sb = new StringBuilder(); sb.Append(SystemInformation.Instance.ApplicationName) .Append(" v").Append(SystemInformation.Instance.ApplicationVersion.ToFormattedString()) .AppendLine(); sb.Append(SystemInformation.Instance.OperatingSystem).Append(" ").Append(SystemInformation.Instance.OperatingSystemArchitecture) .Append("(").Append(SystemInformation.Instance.OperatingSystemVersion).Append(")") .Append(" ").Append(DeviceInfo.Idiom) ; VersionText = sb.ToString(); IsDebugModeEnabled = new ReactiveProperty <bool>((App.Current as App).IsDebugModeEnabled, mode: ReactivePropertyMode.DistinctUntilChanged) .AddTo(_CompositeDisposable); IsDebugModeEnabled.Subscribe(isEnabled => { (App.Current as App).IsDebugModeEnabled = isEnabled; }) .AddTo(_CompositeDisposable); }