public SyncthingEnvironmentalVariablesValidator() { RuleFor(x => x.Value).Must(str => { return(KeyValueStringParser.TryParse(str, out var result)); }).WithMessage(Resources.SettingsView_Validation_SyncthingEnvironmentalVariablesMustHaveFormat); }
public SyncthingCommandLineFlagsValidator() { RuleFor(x => x.Value).Must(str => { return(KeyValueStringParser.TryParse(str, out var result, mustHaveValue: false)); }).WithMessage(Resources.SettingsView_Validation_SyncthingCommandLineFlagsMustHaveFormat); RuleFor(x => x.Value).SetValidator(new IndividualFlagsValidator()); }
public SyncthingEnvironmentalVariablesValidator() { RuleFor(x => x.Value).Must(str => { IEnumerable <KeyValuePair <string, string> > result; return(KeyValueStringParser.TryParse(str, out result)); }).WithMessage(Resources.SettingsView_Validation_SyncthingEnvironmentalVariablesMustHaveFormat); RuleFor(x => x.Value).Must(str => { IEnumerable <KeyValuePair <string, string> > result; KeyValueStringParser.TryParse(str, out result); return(!result.Any(x => x.Key == "STTRACE")); }).WithMessage(Resources.SettingsView_Validation_SetSttraceInTab); }
public IndividualFlagsValidator() { this.RuleFor(x => x).Custom((str, ctx) => { KeyValueStringParser.TryParse(str, out var result, mustHaveValue: false); if (!result.All(flag => flag.Key.StartsWith("-"))) { ctx.AddFailure(Resources.SettingsView_Validation_SyncthingCommandLineFlagsMustBeginWithHyphen); } var firstFailure = result.Select(flag => flag.Key).FirstOrDefault(key => forbiddenArgs.Contains(key)); if (firstFailure != null) { ctx.AddFailure(Localizer.F(Resources.SettingsView_Validation_SyncthingCommandLineFlagIsNotAllowed, firstFailure)); } }); }
public IndividualFlagsValidator() { Custom(str => { IEnumerable <KeyValuePair <string, string> > result; KeyValueStringParser.TryParse(str, out result, mustHaveValue: false); if (!result.All(flag => flag.Key.StartsWith("-"))) { return(new ValidationFailure(null, Resources.SettingsView_Validation_SyncthingCommandLineFlagsMustBeginWithHyphen)); } var firstFailure = result.Select(flag => flag.Key).FirstOrDefault(key => forbiddenArgs.Contains(key)); if (firstFailure != null) { return(new ValidationFailure(null, Localizer.F(Resources.SettingsView_Validation_SyncthingCommandLineFlagIsNotAllowed, firstFailure))); } return(null); }); }
public SettingsViewModel( IConfigurationProvider configurationProvider, IAutostartProvider autostartProvider, IWindowManager windowManager, IProcessStartProvider processStartProvider, IAssemblyProvider assemblyProvider, IApplicationState applicationState, ISyncThingManager syncThingManager) { this.configurationProvider = configurationProvider; this.autostartProvider = autostartProvider; this.windowManager = windowManager; this.processStartProvider = processStartProvider; this.assemblyProvider = assemblyProvider; this.applicationState = applicationState; this.syncThingManager = syncThingManager; this.MinimizeToTray = this.CreateBasicSettingItem(x => x.MinimizeToTray); this.NotifyOfNewVersions = this.CreateBasicSettingItem(x => x.NotifyOfNewVersions); this.CloseToTray = this.CreateBasicSettingItem(x => x.CloseToTray); this.ObfuscateDeviceIDs = this.CreateBasicSettingItem(x => x.ObfuscateDeviceIDs); this.UseComputerCulture = this.CreateBasicSettingItem(x => x.UseComputerCulture); this.UseComputerCulture.RequiresSyncTrayzorRestart = true; this.DisableHardwareRendering = this.CreateBasicSettingItem(x => x.DisableHardwareRendering); this.DisableHardwareRendering.RequiresSyncTrayzorRestart = true; this.ShowTrayIconOnlyOnClose = this.CreateBasicSettingItem(x => x.ShowTrayIconOnlyOnClose); this.ShowSynchronizedBalloonEvenIfNothingDownloaded = this.CreateBasicSettingItem(x => x.ShowSynchronizedBalloonEvenIfNothingDownloaded); this.ShowDeviceConnectivityBalloons = this.CreateBasicSettingItem(x => x.ShowDeviceConnectivityBalloons); this.StartSyncThingAutomatically = this.CreateBasicSettingItem(x => x.StartSyncthingAutomatically); this.SyncthingPriorityLevel = this.CreateBasicSettingItem(x => x.SyncthingPriorityLevel); this.SyncthingPriorityLevel.RequiresSyncthingRestart = true; this.SyncthingUseDefaultHome = this.CreateBasicSettingItem(x => !x.SyncthingUseCustomHome, (x, v) => x.SyncthingUseCustomHome = !v); this.SyncthingUseDefaultHome.RequiresSyncthingRestart = true; this.SyncThingAddress = this.CreateBasicSettingItem(x => x.SyncthingAddress, new SyncThingAddressValidator()); this.SyncThingAddress.RequiresSyncthingRestart = true; this.SyncThingApiKey = this.CreateBasicSettingItem(x => x.SyncthingApiKey, new SyncThingApiKeyValidator()); this.SyncThingApiKey.RequiresSyncthingRestart = true; 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.SyncThingCommandLineFlags = this.CreateBasicSettingItem( x => String.Join(" ", x.SyncthingCommandLineFlags), (x, v) => { IEnumerable <KeyValuePair <string, string> > envVars; KeyValueStringParser.TryParse(v, out envVars, mustHaveValue: false); x.SyncthingCommandLineFlags = envVars.Select(item => KeyValueStringParser.FormatItem(item.Key, item.Value)).ToList(); }, new SyncThingCommandLineFlagsValidator()); this.SyncThingCommandLineFlags.RequiresSyncthingRestart = true; this.SyncThingEnvironmentalVariables = this.CreateBasicSettingItem( x => KeyValueStringParser.Format(x.SyncthingEnvironmentalVariables), (x, v) => { IEnumerable <KeyValuePair <string, string> > envVars; KeyValueStringParser.TryParse(v, out envVars); x.SyncthingEnvironmentalVariables = new EnvironmentalVariableCollection(envVars); }, new SyncThingEnvironmentalVariablesValidator()); this.SyncThingEnvironmentalVariables.RequiresSyncthingRestart = true; this.SyncthingDenyUpgrade = this.CreateBasicSettingItem(x => x.SyncthingDenyUpgrade); this.SyncthingDenyUpgrade.RequiresSyncthingRestart = true; var configuration = this.configurationProvider.Load(); foreach (var settingItem in this.settings) { settingItem.LoadValue(configuration); } this.FolderSettings = new BindableCollection <FolderSettings>(); if (syncThingManager.State == SyncThingState.Running) { this.FolderSettings.AddRange(configuration.Folders.OrderByDescending(x => x.ID).Select(x => new FolderSettings() { FolderName = x.ID, IsWatched = x.IsWatched, IsNotified = x.NotificationsEnabled, })); } foreach (var folderSetting in this.FolderSettings) { folderSetting.Bind(s => s.IsWatched, (o, e) => this.UpdateAreAllFoldersWatched()); folderSetting.Bind(s => s.IsNotified, (o, e) => this.UpdateAreAllFoldersNotified()); } this.PriorityLevels = new BindableCollection <LabelledValue <SyncThingPriorityLevel> >() { LabelledValue.Create(Resources.SettingsView_Syncthing_ProcessPriority_AboveNormal, SyncThingPriorityLevel.AboveNormal), LabelledValue.Create(Resources.SettingsView_Syncthing_ProcessPriority_Normal, SyncThingPriorityLevel.Normal), LabelledValue.Create(Resources.SettingsView_Syncthing_ProcessPriority_BelowNormal, SyncThingPriorityLevel.BelowNormal), LabelledValue.Create(Resources.SettingsView_Syncthing_ProcessPriority_Idle, SyncThingPriorityLevel.Idle), }; this.Bind(s => s.AreAllFoldersNotified, (o, e) => { if (this.updatingFolderSettings) { return; } this.updatingFolderSettings = true; foreach (var folderSetting in this.FolderSettings) { folderSetting.IsNotified = e.NewValue.GetValueOrDefault(false); } this.updatingFolderSettings = false; }); this.Bind(s => s.AreAllFoldersWatched, (o, e) => { if (this.updatingFolderSettings) { return; } this.updatingFolderSettings = true; foreach (var folderSetting in this.FolderSettings) { folderSetting.IsWatched = e.NewValue.GetValueOrDefault(false); } this.updatingFolderSettings = false; }); this.UpdateAreAllFoldersWatched(); this.UpdateAreAllFoldersNotified(); }
public SettingsViewModel( IConfigurationProvider configurationProvider, IAutostartProvider autostartProvider, IWindowManager windowManager, IProcessStartProvider processStartProvider, IAssemblyProvider assemblyProvider, IApplicationState applicationState, IApplicationPathsProvider applicationPathsProvider, ISyncthingManager syncthingManager, IMeteredNetworkManager meteredNetworkManager) { this.configurationProvider = configurationProvider; this.autostartProvider = autostartProvider; this.windowManager = windowManager; this.processStartProvider = processStartProvider; this.assemblyProvider = assemblyProvider; this.applicationState = applicationState; this.applicationPathsProvider = applicationPathsProvider; this.syncthingManager = syncthingManager; this.MinimizeToTray = this.CreateBasicSettingItem(x => x.MinimizeToTray); this.NotifyOfNewVersions = this.CreateBasicSettingItem(x => x.NotifyOfNewVersions); this.CloseToTray = this.CreateBasicSettingItem(x => x.CloseToTray); this.ObfuscateDeviceIDs = this.CreateBasicSettingItem(x => x.ObfuscateDeviceIDs); this.UseComputerCulture = this.CreateBasicSettingItem(x => x.UseComputerCulture); this.UseComputerCulture.RequiresSyncTrayzorRestart = true; this.DisableHardwareRendering = this.CreateBasicSettingItem(x => x.DisableHardwareRendering); this.DisableHardwareRendering.RequiresSyncTrayzorRestart = true; this.EnableConflictFileMonitoring = this.CreateBasicSettingItem(x => x.EnableConflictFileMonitoring); this.EnableFailedTransferAlerts = this.CreateBasicSettingItem(x => x.EnableFailedTransferAlerts); this.PauseDevicesOnMeteredNetworks = this.CreateBasicSettingItem(x => x.PauseDevicesOnMeteredNetworks); this.PauseDevicesOnMeteredNetworksSupported = meteredNetworkManager.IsSupportedByWindows; this.ShowTrayIconOnlyOnClose = this.CreateBasicSettingItem(x => x.ShowTrayIconOnlyOnClose); this.ShowSynchronizedBalloonEvenIfNothingDownloaded = this.CreateBasicSettingItem(x => x.ShowSynchronizedBalloonEvenIfNothingDownloaded); this.ShowDeviceConnectivityBalloons = this.CreateBasicSettingItem(x => x.ShowDeviceConnectivityBalloons); this.ShowDeviceOrFolderRejectedBalloons = this.CreateBasicSettingItem(x => x.ShowDeviceOrFolderRejectedBalloons); this.IconAnimationModes = new BindableCollection <LabelledValue <IconAnimationMode> >() { LabelledValue.Create(Resources.SettingsView_TrayIconAnimation_DataTransferring, Services.Config.IconAnimationMode.DataTransferring), LabelledValue.Create(Resources.SettingsView_TrayIconAnimation_Syncing, Services.Config.IconAnimationMode.Syncing), LabelledValue.Create(Resources.SettingsView_TrayIconAnimation_Disabled, Services.Config.IconAnimationMode.Disabled), }; this.IconAnimationMode = this.CreateBasicSettingItem(x => x.IconAnimationMode); this.StartSyncthingAutomatically = this.CreateBasicSettingItem(x => x.StartSyncthingAutomatically); this.SyncthingPriorityLevel = this.CreateBasicSettingItem(x => x.SyncthingPriorityLevel); this.SyncthingPriorityLevel.RequiresSyncthingRestart = true; this.SyncthingAddress = this.CreateBasicSettingItem(x => x.SyncthingAddress, new SyncthingAddressValidator()); this.SyncthingAddress.RequiresSyncthingRestart = true; 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.SyncthingCommandLineFlags = this.CreateBasicSettingItem( x => String.Join(" ", x.SyncthingCommandLineFlags), (x, v) => { KeyValueStringParser.TryParse(v, out var envVars, mustHaveValue: false); x.SyncthingCommandLineFlags = envVars.Select(item => KeyValueStringParser.FormatItem(item.Key, item.Value)).ToList(); }, new SyncthingCommandLineFlagsValidator());