private void ApplyNewConfiguration(Configuration configuration) { this.notifyIconManager.MinimizeToTray = configuration.MinimizeToTray; this.notifyIconManager.CloseToTray = configuration.CloseToTray; this.notifyIconManager.ShowOnlyOnClose = configuration.ShowTrayIconOnlyOnClose; this.notifyIconManager.FolderNotificationsEnabled = configuration.Folders.ToDictionary(x => x.ID, x => x.NotificationsEnabled); this.notifyIconManager.ShowSynchronizedBalloonEvenIfNothingDownloaded = configuration.ShowSynchronizedBalloonEvenIfNothingDownloaded; this.notifyIconManager.ShowDeviceConnectivityBalloons = configuration.ShowDeviceConnectivityBalloons; this.syncThingManager.PreferredAddress = new Uri("https://" + configuration.SyncthingAddress); this.syncThingManager.ApiKey = configuration.SyncthingApiKey; this.syncThingManager.SyncthingCommandLineFlags = configuration.SyncthingCommandLineFlags; this.syncThingManager.SyncthingEnvironmentalVariables = configuration.SyncthingEnvironmentalVariables; this.syncThingManager.SyncthingCustomHomeDir = configuration.SyncthingUseCustomHome ? EnvVarTransformer.Transform(configuration.SyncthingCustomHomePath) : null; this.syncThingManager.SyncthingDenyUpgrade = configuration.SyncthingDenyUpgrade; this.syncThingManager.SyncthingPriorityLevel = configuration.SyncthingPriorityLevel; this.syncThingManager.SyncthingHideDeviceIds = configuration.ObfuscateDeviceIDs; this.syncThingManager.ExecutablePath = EnvVarTransformer.Transform(configuration.SyncthingPath); this.watchedFolderMonitor.WatchedFolderIDs = configuration.Folders.Where(x => x.IsWatched).Select(x => x.ID); this.updateManager.LatestIgnoredVersion = configuration.LatestNotifiedVersion; this.updateManager.CheckForUpdates = configuration.NotifyOfNewVersions; }
private void ApplyNewConfiguration(Configuration configuration) { this.notifyIconManager.MinimizeToTray = configuration.MinimizeToTray; this.notifyIconManager.CloseToTray = configuration.CloseToTray; this.notifyIconManager.ShowOnlyOnClose = configuration.ShowTrayIconOnlyOnClose; this.notifyIconManager.FolderNotificationsEnabled = configuration.Folders.ToDictionary(x => x.ID, x => x.NotificationsEnabled); this.notifyIconManager.ShowSynchronizedBalloonEvenIfNothingDownloaded = configuration.ShowSynchronizedBalloonEvenIfNothingDownloaded; this.notifyIconManager.ShowDeviceConnectivityBalloons = configuration.ShowDeviceConnectivityBalloons; this.notifyIconManager.ShowDeviceOrFolderRejectedBalloons = configuration.ShowDeviceOrFolderRejectedBalloons; this.syncthingManager.PreferredHostAndPort = configuration.SyncthingAddress; this.syncthingManager.ApiKey = configuration.SyncthingApiKey; this.syncthingManager.SyncthingCommandLineFlags = configuration.SyncthingCommandLineFlags; this.syncthingManager.SyncthingEnvironmentalVariables = configuration.SyncthingEnvironmentalVariables; this.syncthingManager.SyncthingCustomHomeDir = configuration.SyncthingUseCustomHome ? EnvVarTransformer.Transform(configuration.SyncthingCustomHomePath) : null; this.syncthingManager.SyncthingDenyUpgrade = configuration.SyncthingDenyUpgrade; this.syncthingManager.SyncthingPriorityLevel = configuration.SyncthingPriorityLevel; this.syncthingManager.SyncthingHideDeviceIds = configuration.ObfuscateDeviceIDs; this.syncthingManager.ExecutablePath = EnvVarTransformer.Transform(configuration.SyncthingPath); this.syncthingManager.DebugFacilities.SetEnabledDebugFacilities(configuration.SyncthingDebugFacilities); this.watchedFolderMonitor.WatchedFolderIDs = configuration.Folders.Where(x => x.IsWatched).Select(x => x.ID); this.updateManager.LatestIgnoredVersion = configuration.LatestNotifiedVersion; this.updateManager.CheckForUpdates = configuration.NotifyOfNewVersions; this.conflictFileWatcher.IsEnabled = configuration.EnableConflictFileMonitoring; this.meteredNetworkManager.IsEnabled = configuration.PauseDevicesOnMeteredNetworks; this.alertsManager.EnableConflictedFileAlerts = configuration.EnableConflictFileMonitoring; this.alertsManager.EnableFailedTransferAlerts = configuration.EnableFailedTransferAlerts; }
public void Initialize(Configuration defaultConfiguration) { if (defaultConfiguration == null) { throw new ArgumentNullException("defaultConfiguration"); } if (!this.filesystem.DirectoryExists(Path.GetDirectoryName(this.paths.ConfigurationFilePath))) { this.filesystem.CreateDirectory(Path.GetDirectoryName(this.paths.ConfigurationFilePath)); } this.currentConfig = this.LoadFromDisk(defaultConfiguration); bool updateConfigInstallCount = false; int latestInstallCount = 0; // Might be portable, in which case this file won't exist if (this.filesystem.FileExists(this.paths.InstallCountFilePath)) { latestInstallCount = Int32.Parse(this.filesystem.ReadAllText(this.paths.InstallCountFilePath).Trim()); if (latestInstallCount != this.currentConfig.LastSeenInstallCount) { logger.Debug("InstallCount changed from {0} to {1}", this.currentConfig.LastSeenInstallCount, latestInstallCount); this.WasUpgraded = true; updateConfigInstallCount = true; } } var expandedSyncthingPath = EnvVarTransformer.Transform(this.currentConfig.SyncthingPath); if (!this.filesystem.FileExists(this.paths.SyncthingBackupPath)) { throw new CouldNotFindSyncthingException(this.paths.SyncthingBackupPath); } // They might be the same if we're portable, in which case, nothing to do if (!this.filesystem.FileExists(expandedSyncthingPath)) { // We know that this.paths.SyncthingBackupPath exists, because we checked this above logger.Info("Syncthing doesn't exist at {0}, so copying from {1}", expandedSyncthingPath, this.paths.SyncthingBackupPath); this.filesystem.Copy(this.paths.SyncthingBackupPath, expandedSyncthingPath); } if (updateConfigInstallCount) { this.currentConfig.LastSeenInstallCount = latestInstallCount; this.SaveToFile(this.currentConfig); } }
protected override void Configure() { // Have to set the log path before anything else var pathConfiguration = Settings.Default.PathConfiguration; GlobalDiagnosticsContext.Set("LogFilePath", EnvVarTransformer.Transform(pathConfiguration.LogFilePath)); AppDomain.CurrentDomain.UnhandledException += (o, e) => OnAppDomainUnhandledException(e); if (Settings.Default.EnforceSingleProcessPerUser) { if (this.Container.Get <ISingleApplicationInstanceManager>().ShouldExit()) { Environment.Exit(0); } } this.Container.Get <IApplicationPathsProvider>().Initialize(pathConfiguration); var configurationProvider = this.Container.Get <IConfigurationProvider>(); configurationProvider.Initialize(Settings.Default.DefaultUserConfiguration); var configuration = this.Container.Get <IConfigurationProvider>().Load(); if (Settings.Default.EnforceSingleProcessPerUser) { this.Container.Get <ISingleApplicationInstanceManager>().StartServer(); } // Has to be done before the VMs are fetched from the container var languageArg = this.Args.FirstOrDefault(x => x.StartsWith("-culture=")); if (languageArg != null) { Thread.CurrentThread.CurrentUICulture = new CultureInfo(languageArg.Substring("-culture=".Length)); } else if (!configuration.UseComputerCulture) { Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); } // WPF ignores the current culture by default - so we have to force it FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.IetfLanguageTag))); var autostartProvider = this.Container.Get <IAutostartProvider>(); #if DEBUG autostartProvider.IsEnabled = false; #endif // If it's not in portable mode, and if we had to create config (i.e. it's the first start ever), then enable autostart if (autostartProvider.CanWrite && Settings.Default.EnableAutostartOnFirstStart && configurationProvider.HadToCreateConfiguration) { autostartProvider.SetAutoStart(new AutostartConfiguration() { AutoStart = true, StartMinimized = true }); } // Needs to be done before ConfigurationApplicator is run this.Container.Get <IApplicationWindowState>().Setup((ShellViewModel)this.RootViewModel); this.Container.Get <ConfigurationApplicator>().ApplyConfiguration(); this.Container.Get <MemoryUsageLogger>().Enabled = true; // Handles Restart Manager requests - sent by the installer. We need to shutdown syncthing in this case this.Application.SessionEnding += (o, e) => { LogManager.GetCurrentClassLogger().Info("Shutting down: {0}", e.ReasonSessionEnding); var manager = this.Container.Get <ISyncThingManager>(); manager.StopAndWaitAsync().Wait(2000); manager.Kill(); }; MessageBoxViewModel.ButtonLabels = new Dictionary <MessageBoxResult, string>() { { MessageBoxResult.Cancel, Resources.Generic_Dialog_Cancel }, { MessageBoxResult.No, Resources.Generic_Dialog_No }, { MessageBoxResult.OK, Resources.Generic_Dialog_OK }, { MessageBoxResult.Yes, Resources.Generic_Dialog_Yes }, }; }