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")); }