public SettingsViewModel( IConfigurationProvider configurationProvider, IAutostartProvider autostartProvider, IModelValidator <SettingsViewModel> validator) : base(validator) { this.configurationProvider = configurationProvider; this.autostartProvider = autostartProvider; var configuration = this.configurationProvider.Load(); this.MinimizeToTray = configuration.MinimizeToTray; this.CloseToTray = configuration.CloseToTray; this.NotifyOfNewVersions = configuration.NotifyOfNewVersions; this.ObfuscateDeviceIDs = configuration.ObfuscateDeviceIDs; this.UseComputerCulture = configuration.UseComputerCulture; this.ShowTrayIconOnlyOnClose = configuration.ShowTrayIconOnlyOnClose; this.ShowSynchronizedBalloon = configuration.ShowSynchronizedBalloon; this.ShowDeviceConnectivityBalloons = configuration.ShowDeviceConnectivityBalloons; this.StartSyncThingAutomatically = configuration.StartSyncthingAutomatically; this.SyncthingRunLowPriority = configuration.SyncthingRunLowPriority; this.SyncThingAddress = configuration.SyncthingAddress; this.SyncThingApiKey = configuration.SyncthingApiKey; this.CanReadAutostart = this.autostartProvider.CanRead; this.CanWriteAutostart = this.autostartProvider.CanWrite; if (this.autostartProvider.CanRead) { var currentSetup = this.autostartProvider.GetCurrentSetup(); this.StartOnLogon = currentSetup.AutoStart; this.StartMinimized = currentSetup.StartMinimized; } this.WatchedFolders = new BindableCollection <WatchedFolder>(configuration.Folders.Select(x => new WatchedFolder() { Folder = x.ID, IsSelected = x.IsWatched })); this.SyncthingUseCustomHome = configuration.SyncthingUseCustomHome; this.SyncThingEnvironmentalVariables = EnvironmentalVariablesParser.Format(configuration.SyncthingEnvironmentalVariables); this.SyncthingDenyUpgrade = configuration.SyncthingDenyUpgrade; }
public void Save() { var configuration = this.configurationProvider.Load(); configuration.MinimizeToTray = this.MinimizeToTray; configuration.CloseToTray = this.CloseToTray; configuration.NotifyOfNewVersions = this.NotifyOfNewVersions; configuration.ObfuscateDeviceIDs = this.ObfuscateDeviceIDs; configuration.UseComputerCulture = this.UseComputerCulture; configuration.ShowTrayIconOnlyOnClose = this.ShowTrayIconOnlyOnClose; configuration.ShowSynchronizedBalloon = this.ShowSynchronizedBalloon; configuration.ShowDeviceConnectivityBalloons = this.ShowDeviceConnectivityBalloons; configuration.StartSyncthingAutomatically = this.StartSyncThingAutomatically; configuration.SyncthingRunLowPriority = this.SyncthingRunLowPriority; configuration.SyncthingAddress = this.SyncThingAddress; configuration.SyncthingApiKey = this.SyncThingApiKey; if (this.autostartProvider.CanWrite) { var autostartConfig = new AutostartConfiguration() { AutoStart = this.StartOnLogon, StartMinimized = this.StartMinimized }; this.autostartProvider.SetAutoStart(autostartConfig); } configuration.Folders = this.WatchedFolders.Select(x => new FolderConfiguration(x.Folder, x.IsSelected)).ToList(); configuration.SyncthingUseCustomHome = this.SyncthingUseCustomHome; EnvironmentalVariableCollection envVars; EnvironmentalVariablesParser.TryParse(this.SyncThingEnvironmentalVariables, out envVars); configuration.SyncthingEnvironmentalVariables = envVars; configuration.SyncthingDenyUpgrade = this.SyncthingDenyUpgrade; this.configurationProvider.Save(configuration); this.RequestClose(true); }
public SettingsViewModelValidator() { RuleFor(x => x.SyncThingAddress).NotEmpty().WithMessage(Localizer.Translate("SettingsView_Validation_NotShouldBeEmpty")); RuleFor(x => x.SyncThingAddress).Must(str => { // URI seems to think https://http://something is valid... if (str.StartsWith("http:") || str.StartsWith("https:")) { return(false); } str = "https://" + str; Uri uri; return(Uri.TryCreate(str, UriKind.Absolute, out uri) && uri.IsWellFormedOriginalString()); }).WithMessage(Localizer.Translate("SettingsView_Validation_InvalidUrl")); RuleFor(x => x.SyncThingApiKey).NotEmpty().WithMessage(Localizer.Translate("SettingsView_Validation_NotShouldBeEmpty")); RuleFor(x => x.SyncThingEnvironmentalVariables).Must(str => { EnvironmentalVariableCollection result; return(EnvironmentalVariablesParser.TryParse(str, out result)); }).WithMessage(Localizer.Translate("SettingsView_Validation_SyncthingEnvironmentalVariablesMustHaveFormat")); }