public void LoadConfiguration() { var mainViewModel = (MainViewModel)Resources["MainViewModel"]; var settings = BeatSaberCameraSettings.LoadFromFile(); if (settings == null) { settings = new BeatSaberCameraSettings() { AppConfigModel = new AppConfigModel(), CameraConfigModel = new CameraConfigModel(), TwitchBotConfigModel = new TwitchBotConfigModel(), ChatConfigModel = new ChatConfigModel() }; settings.AppConfigModel.CameraPlusConfig = SearchCameraPlusConfig(); settings.CameraConfigModel.Profiles.Add(new CameraProfile() { Name = "Default", CameraPlusConfig = new CameraPlusConfig() }); if (File.Exists(settings.AppConfigModel.CameraPlusConfig)) { settings.CameraConfigModel.CurrentCameraProfile.CameraPlusConfig.LoadDataFromBeatSaber(settings.AppConfigModel); } settings.AppConfigModel.IsDirty = true; settings.CameraConfigModel.IsDirty = true; settings.TwitchBotConfigModel.IsDirty = true; } mainViewModel.AppConfigModel = settings.AppConfigModel; mainViewModel.CameraConfigModel = settings.CameraConfigModel; mainViewModel.TwitchBotConfigModel = settings.TwitchBotConfigModel; mainViewModel.ChatViewModel.Chatters.CollectionChanged -= Chatters_CollectionChanged; mainViewModel.ChatViewModel = new ChatViewModel() { Chatters = new ObservableCollection <Chatter>(settings.ChatConfigModel.ChatterList ?? new List <Chatter>()), IsSpeechEmojiEnabled = settings.ChatConfigModel.IsSpeechEmojiEnabled, MaxPitchFactor = settings.ChatConfigModel.MaxPitchFactor, IsReadingStreamerMessagesEnabled = settings.ChatConfigModel.IsReadingStreamerMessagesEnabled, IsSendMessagesEnabled = settings.ChatConfigModel.IsSendMessagesEnabled, IsTextToSpeechEnabled = settings.ChatConfigModel.IsTextToSpeechEnabled, ReadUserNames = settings.ChatConfigModel.ReadUserNames, }; mainViewModel.ChatViewModel.Clean(); mainViewModel.ChatViewModel.Chatters.CollectionChanged += Chatters_CollectionChanged; }
private void Chatters_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if (_isSaving) { return; } _isSaving = true; var mainViewModel = (MainViewModel)Resources["MainViewModel"]; Task.Run(() => { try { var settings = BeatSaberCameraSettings.LoadFromFile(); if (settings == null) { return; } // only update chatters settings lock (mainViewModel.ChatViewModel.Chatters) { settings.ChatConfigModel.ChatterList = mainViewModel.ChatViewModel.Chatters.ToList(); } BeatSaberCameraSettings.Save(settings); foreach (var chatter in settings.ChatConfigModel.ChatterList) { chatter.Clean(); } } finally { _isSaving = false; } }); }
private void SaveCommand_OnExecuted(object sender, ExecutedRoutedEventArgs e) { BeatSaberCameraSettings.Save(MainViewModel.AsSettings()); MainViewModel.ChatViewModel.Clean(); }