/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { var commandLine = new CommandLine(args); if (commandLine.RunAsService) { ServiceBase[] servicesToRun = new ServiceBase[] { new ShredHostService() }; ServiceBase.Run(servicesToRun); } else if (!String.IsNullOrEmpty(commandLine.PreviousExeConfigurationFilename)) { var groups = SettingsGroupDescriptor.ListInstalledSettingsGroups(SettingsGroupFilter.LocalStorage); foreach (var group in groups) { SettingsMigrator.MigrateSharedSettings(group, commandLine.PreviousExeConfigurationFilename); } ShredSettingsMigrator.MigrateAll(commandLine.PreviousExeConfigurationFilename); } else { Thread.CurrentThread.Name = "Main thread"; if (!ManifestVerification.Valid) { Console.WriteLine("The manifest detected an invalid installation."); } ShredHostService.InternalStart(); Console.WriteLine("Press <Enter> to terminate the ShredHost."); Console.WriteLine(); Console.ReadLine(); ShredHostService.InternalStop(); } }
private static void MigrateSharedSettings(string previousExeConfigFilename) { foreach (var group in SettingsGroupDescriptor.ListInstalledSettingsGroups(false)) { SettingsMigrator.MigrateSharedSettings(group, previousExeConfigFilename); } }
public Task LoadPlugins() { var pluginDir = new DirectoryInfo(AppInfo.Current.PluginDirectory); if (pluginDir.Exists) { var pluginManager = AppInfo.PluginManager; pluginManager.Load(); // Migrate if settings is available to avoid invalid settings if (Settings != null) { Settings = SettingsMigrator.Migrate(Settings); } // Add services to inject on plugin construction pluginManager.AddService <IDriver>(() => this.Driver); } else { pluginDir.Create(); Log.Write("Plugin", $"The plugin directory '{pluginDir.FullName}' has been created"); } return(Task.CompletedTask); }
private static void TestLocalSharedSettingsMigration(Type mixedScopeSettingsClass) { if (!mixedScopeSettingsClass.IsSubclassOf(typeof(MixedScopeSettingsBase))) { throw new ArgumentException(); } var configuration = SystemConfigurationHelper.GetExeConfiguration(); var values = CreateSettingsValues(mixedScopeSettingsClass, MigrationScope.Shared, SettingValue.Current); configuration.PutSettingsValues(mixedScopeSettingsClass, values); string directory = Path.GetDirectoryName(configuration.FilePath); string previousExeFilename = String.Format("{0}{1}Previous.exe.config", directory, Path.DirectorySeparatorChar); try { TestConfigResourceToFile(previousExeFilename); ValidateLocalMixedScopeSettingsValuesInConfig(mixedScopeSettingsClass, configuration, SettingValue.Current); SettingsMigrator.MigrateSharedSettings(mixedScopeSettingsClass, previousExeFilename); configuration = SystemConfigurationHelper.GetExeConfiguration(); ValidateLocalMixedScopeSettingsValuesInConfig(mixedScopeSettingsClass, configuration, SettingValue.Previous); } finally { File.Delete(previousExeFilename); configuration.RemoveSettingsValues(mixedScopeSettingsClass); } }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { var commandLine = new CommandLine(args); if (commandLine.RunAsService) { var ServicesToRun = new ServiceBase[] { new ShredHostService() }; ServiceBase.Run(ServicesToRun); } else if (!String.IsNullOrEmpty(commandLine.PreviousExeConfigurationFilename)) { var groups = SettingsGroupDescriptor.ListInstalledLocalSettingsGroups(); groups.Add(new SettingsGroupDescriptor(typeof(ShredSettingsMigrator).Assembly.GetType("ClearCanvas.Server.ShredHost.ShredHostServiceSettings"))); foreach (var group in groups) { SettingsMigrator.MigrateSharedSettings(group, commandLine.PreviousExeConfigurationFilename); } ShredSettingsMigrator.MigrateAll(commandLine.PreviousExeConfigurationFilename); } else { ShredHostService.InternalStart(); Console.WriteLine("Press <Enter> to terminate the ShredHost."); Console.WriteLine(); Console.ReadLine(); ShredHostService.InternalStop(); } }
public void TestLocalSharedSettingsMigration() { Type settingsClass = typeof(LocalMixedScopeSettings); var configuration = SystemConfigurationHelper.GetExeConfiguration(); var values = CreateSettingsValues(settingsClass, MigrationScope.Shared, SettingValue.Current); SystemConfigurationHelper.PutSettingsValues(configuration, settingsClass, values); string directory = Path.GetDirectoryName(configuration.FilePath); string previousExeFilename = String.Format("{0}{1}Previous.exe.config", directory, Path.DirectorySeparatorChar); try { TestConfigResourceToFile(previousExeFilename); ValidateLocalMixedScopeSettingsValuesInConfig(configuration, SettingValue.Current); SettingsMigrator.MigrateSharedSettings(settingsClass, previousExeFilename); configuration = SystemConfigurationHelper.GetExeConfiguration(); ValidateLocalMixedScopeSettingsValuesInConfig(configuration, SettingValue.Previous); } finally { File.Delete(previousExeFilename); SystemConfigurationHelper.RemoveSettingsValues(configuration, settingsClass); } }
public Task LoadPlugins() { var pluginDir = new DirectoryInfo(AppInfo.Current.PluginDirectory); if (pluginDir.Exists) { var pluginManager = AppInfo.PluginManager; pluginManager.Load(); // Migrate if settings is available to avoid invalid settings if (Settings != null) { Settings = SettingsMigrator.Migrate(Settings); } // Add services to inject on plugin construction pluginManager.ResetServices(); pluginManager.AddService <IServiceProvider>(() => pluginManager); pluginManager.AddService <IDriver>(() => this.Driver); pluginManager.AddService(() => DesktopInterop.Timer); pluginManager.AddService(() => DesktopInterop.AbsolutePointer); pluginManager.AddService(() => DesktopInterop.RelativePointer); pluginManager.AddService(() => DesktopInterop.VirtualScreen); pluginManager.AddService(() => DesktopInterop.VirtualKeyboard); } else { pluginDir.Create(); Log.Write("Plugin", $"The plugin directory '{pluginDir.FullName}' has been created"); } return(Task.CompletedTask); }
public void Can_delete_and_add_setting_entries() { var settings = context.Set <Setting>(); settings.Any().ShouldBeFalse(); var entries = GetDefaultSettingEntries(); var migrator = new SettingsMigrator(context); migrator.Migrate(entries); var builder = new SettingsBuilder(); builder.Delete("type1.setting1", "type2.setting1"); migrator.Migrate(builder.Build()); settings.ToList().Count.ShouldEqual(6); builder.Reset(); builder.DeleteGroup("type1"); migrator.Migrate(builder.Build()); settings.ToList().Count.ShouldEqual(3); builder.Reset(); builder.Add("type3.Setting1", true); builder.Add("type3.Setting2", 20); migrator.Migrate(builder.Build()); var db = settings.ToList(); db.Count.ShouldEqual(5); var st = settings.Where(x => x.Name == "type3.Setting2").FirstOrDefault(); st.Value.ShouldEqual("20"); }
public void TestSimpleUserSettingsMigration() { ResetUpgradeSettings(); Type settingsClass = typeof(SimpleUserSettings); PopulateSimpleStore(settingsClass); Assert.IsTrue(SettingsMigrator.MigrateUserSettings(settingsClass)); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); SettingsProperty property = settings.Properties[SimpleUserSettings.PropertyUser]; string expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Previous); string actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Previous); Assert.IsFalse(SettingsMigrator.MigrateUserSettings(settingsClass)); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); actual = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, actual); }
public void TestNeverMigrateProductSettings() { ResetUpgradeSettings(); ResetAllSettingsClasses(); Type settingsClass = typeof(ProductSettings); Assert.IsFalse(SettingsMigrator.MigrateUserSettings(settingsClass)); Assert.IsFalse(SettingsMigrator.MigrateSharedSettings(settingsClass, null)); }
public void RunApplication(string[] args) { var commandLine = new CommandLine(args); var groups = SettingsGroupDescriptor.ListInstalledSettingsGroups(SettingsGroupFilter.LocalStorage); foreach (var group in groups) { SettingsMigrator.MigrateSharedSettings(group, commandLine.PreviousExeConfigurationFilename); } }
private static void TestMultipleSharedSettingsMigrated(Type mixedScopeSettingsClass) { if (!mixedScopeSettingsClass.IsSubclassOf(typeof(MixedScopeSettingsBase))) { throw new ArgumentException(); } ResetSimpleStore(); ResetAllSettingsClasses(); PopulateSimpleStore(mixedScopeSettingsClass); SettingsMigrator.MigrateSharedSettings(mixedScopeSettingsClass, null); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(mixedScopeSettingsClass); SettingsProperty property = settings.Properties[MixedScopeSettingsBase.PropertyUser1]; string expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Current); var actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyUser2]; expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Current); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyApp1]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous); actual = (string)settings.GetSharedPropertyValue(property.Name); Assert.AreEqual(expected, actual); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyApp2]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous); actual = (string)settings.GetSharedPropertyValue(property.Name); Assert.AreEqual(expected, actual); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyUser1]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous); actual = (string)settings.GetSharedPropertyValue(property.Name); Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyUser2]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous); actual = (string)settings.GetSharedPropertyValue(property.Name); Assert.AreEqual(expected, actual); }
protected SettingsMigratorTest(MockRepository factory = null) { _factory = factory ?? new MockRepository(MockBehavior.Strict); _vimApplicationSettings = _factory.Create <IVimApplicationSettings>(MockBehavior.Loose); _vimApplicationSettings.SetupAllProperties(); _legacySettings = _factory.Create <ILegacySettings>(MockBehavior.Loose); _legacySettings.SetupGet(x => x.RemovedBindings).Returns(EmptyBindings); var dte = MockObjectFactory.CreateDteWithCommands(); _settingsMigrator = new SettingsMigrator( dte.Object, _vimApplicationSettings.Object, _legacySettings.Object); }
public void MigrateSettingsNoChanges() { TestSettingsStore.Instance.Reset(); var settings = new MigrationAppSettings(); SettingsMigrator.MigrateSharedSettings(typeof(MigrationAppSettings), null); var settings3 = new MigrationAppSettings(); Assert.AreEqual(settings3.App1, MigrationAppSettings.DefaultValueApp); Assert.AreEqual(settings3.App2, MigrationAppSettings.DefaultValueApp); Assert.AreEqual(settings3.App3, MigrationAppSettings.DefaultValueApp); }
public void Can_add_setting_entries() { var settings = context.Set <Setting>(); settings.Any().ShouldBeFalse(); var entries = GetDefaultSettingEntries(); var migrator = new SettingsMigrator(context); migrator.Migrate(entries); ReloadContext(); settings = context.Set <Setting>(); settings.ToList().Count.ShouldEqual(8); }
public void TestCustomUserSettingsMigration() { ResetSimpleStore(); ResetAllSettingsClasses(); Type settingsClass = typeof(CustomMigrationMixedScopeSettings); PopulateSimpleStore(settingsClass); SettingsMigrator.MigrateUserSettings(settingsClass); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); SettingsProperty property = settings.Properties[MixedScopeSettingsBase.PropertyUser1]; string expected = "CustomUser1"; var actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyUser2]; expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Previous); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyApp1]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); actual = (string)settings.GetSharedPropertyValue(property.Name); Assert.AreEqual(expected, actual); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyApp2]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); actual = (string)settings.GetSharedPropertyValue(property.Name); Assert.AreEqual(expected, actual); actual = (string)settings[property.Name]; Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyUser1]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); actual = (string)settings.GetSharedPropertyValue(property.Name); Assert.AreEqual(expected, actual); property = settings.Properties[MixedScopeSettingsBase.PropertyUser2]; expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); actual = (string)settings.GetSharedPropertyValue(property.Name); Assert.AreEqual(expected, actual); }
public Task SetSettings(Settings settings) { // Dispose all interpolators to begin changing settings foreach (var interpolator in Driver.Interpolators) { interpolator.Dispose(); } Driver.Interpolators.Clear(); Settings = SettingsMigrator.Migrate(settings); var pluginRef = Settings.OutputMode?.GetPluginReference() ?? AppInfo.PluginManager.GetPluginReference(typeof(AbsoluteMode)); Driver.OutputMode = pluginRef.Construct <IOutputMode>(); if (Driver.OutputMode != null) { Log.Write("Settings", $"Output mode: {pluginRef.Name ?? pluginRef.Path}"); } if (Driver.OutputMode is IOutputMode outputMode) { SetOutputModeSettings(outputMode); } if (Driver.OutputMode is AbsoluteOutputMode absoluteMode) { SetAbsoluteModeSettings(absoluteMode); } if (Driver.OutputMode is RelativeOutputMode relativeMode) { SetRelativeModeSettings(relativeMode); } SetBindingHandlerSettings(); if (Settings.AutoHook) { Driver.EnableInput = true; Log.Write("Settings", "Driver is auto-enabled."); } SetToolSettings(); SetInterpolatorSettings(); return(Task.CompletedTask); }
private static void MigrateSharedSettings(string previousExeConfigFilename) { foreach (var group in SettingsGroupDescriptor.ListInstalledSettingsGroups()) { try { SettingsMigrator.MigrateSharedSettings(group, previousExeConfigFilename); } catch (Exception e) { //Failure to migrate a settings is not good enough reason to cause the whole app to fail. //Some of the viewer settings classes SHOULD actually fail to migrate in the context of the ImageServer. // Platform.Log(LogLevel.Warn, e, "Failed to migrate settings '{0}'", group.AssemblyQualifiedTypeName); } } }
protected SettingsMigratorTest(MockRepository factory = null, SVsServiceProvider serviceProvider = null) { _factory = factory ?? new MockRepository(MockBehavior.Strict); _vimApplicationSettings = _factory.Create <IVimApplicationSettings>(MockBehavior.Loose); _legacySettings = _factory.Create <ILegacySettings>(MockBehavior.Loose); _legacySettings.SetupGet(x => x.RemovedBindings).Returns(EmptyBindings); _protectedOperations = _factory.Create <IProtectedOperations>(); if (serviceProvider == null) { var dte = MockObjectFactory.CreateDteWithCommands(); serviceProvider = MockObjectFactory.CreateVsServiceProvider(Tuple.Create <Type, object>(typeof(SDTE), dte.Object)).Object; } _settingsMigrator = new SettingsMigrator( serviceProvider, _vimApplicationSettings.Object, _legacySettings.Object, _protectedOperations.Object); }
private static void TestMigrateXmlSettings(Type xmlSettingsClass) { if (!xmlSettingsClass.IsSubclassOf(typeof(LocalXmlSettingsBase))) { throw new ArgumentException(); } var configuration = SystemConfigurationHelper.GetExeConfiguration(); var settings = (LocalXmlSettingsBase)ApplicationSettingsHelper.GetSettingsClassInstance(xmlSettingsClass); var document = new XmlDocument(); document.LoadXml((string)settings.Properties[LocalXmlSettingsBase.PropertyApp].DefaultValue); var node = document.SelectSingleNode("//test"); node.InnerText = "CurrentApp"; var values = new Dictionary <string, string>(); values[LocalXmlSettingsBase.PropertyApp] = document.InnerXml; configuration.PutSettingsValues(xmlSettingsClass, values); string directory = Path.GetDirectoryName(configuration.FilePath); string previousExeFilename = String.Format("{0}{1}Previous.exe.config", directory, Path.DirectorySeparatorChar); try { TestConfigResourceToFile(previousExeFilename); SettingsMigrator.MigrateSharedSettings(xmlSettingsClass, previousExeFilename); configuration = SystemConfigurationHelper.GetExeConfiguration(); settings = (LocalXmlSettingsBase)ApplicationSettingsHelper.GetSettingsClassInstance(xmlSettingsClass); settings.Reload(); document = (XmlDocument)settings.GetSharedPropertyValue(LocalXmlSettingsBase.PropertyApp); Assert.AreEqual("PreviousApp", document.SelectSingleNode("//test").InnerXml); document = settings.App; Assert.AreEqual("PreviousApp", document.SelectSingleNode("//test").InnerXml); } finally { File.Delete(previousExeFilename); configuration.RemoveSettingsValues(xmlSettingsClass); } }
public Task LoadPlugins() { var pluginDir = new DirectoryInfo(AppInfo.Current.PluginDirectory); if (pluginDir.Exists) { AppInfo.PluginManager.Load(); // Migrate if settings is available to avoid invalid settings if (Settings != null) { Settings = SettingsMigrator.Migrate(Settings); } } else { pluginDir.Create(); Log.Write("Detect", $"The plugin directory '{pluginDir.FullName}' has been created"); } return(Task.CompletedTask); }
public void TestNonMigratableSharedSettings() { ResetUpgradeSettings(); Type settingsClass = typeof(NonMigratableSharedSettings); PopulateSimpleStore(settingsClass); Assert.IsFalse(SettingsMigrator.MigrateSharedSettings(settingsClass, null)); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); SettingsProperty property = settings.Properties[NonMigratableSharedSettings.PropertyApp]; string expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Current); Assert.AreEqual(expected, settings[property.Name]); string current = (string)ApplicationSettingsExtensions.GetSharedPropertyValue(settings, property.Name); Assert.AreEqual(expected, current); }
public void RunApplication(string[] args) { var cmd = new CommandLine(); try { cmd.Parse(args); } catch (Exception) { cmd.PrintUsage(Console.Out); Environment.Exit(-1); } //Hack to redirect local shared settings to a different exe's config file. ExtendedLocalFileSettingsProvider.ExeConfigFileName = cmd.Target; foreach (var settingsClass in _applicationSettingsClasses) { var settingsType = Type.GetType(settingsClass); SettingsMigrator.MigrateSharedSettings(settingsType, cmd.Source); } try { if (!String.IsNullOrEmpty(cmd.DicomServersFileName) && File.Exists(cmd.DicomServersFileName)) { var existingServerTree = new ServerTree.ServerTree(); if (existingServerTree.RootServerGroup.GetAllServers().Count == 0) { //Settings NOT from an old xml file were just migrated, so //if there's still no servers defined, import from old xml file. var serverTree = new ServerTree.ServerTree(cmd.DicomServersFileName); serverTree.Save(); } } } catch (Exception e) { Platform.Log(LogLevel.Warn, e, "Failed to import legacy server tree '{0}'.", cmd.DicomServersFileName); } }
public Task SetSettings(Settings settings) { Settings = SettingsMigrator.Migrate(settings); Driver.OutputMode = new PluginReference(Settings.OutputMode).Construct <IOutputMode>(); if (Driver.OutputMode != null) { Log.Write("Settings", $"Output mode: {Driver.OutputMode.GetType().FullName}"); } if (Driver.OutputMode is IOutputMode outputMode) { SetOutputModeSettings(outputMode); } if (Driver.OutputMode is AbsoluteOutputMode absoluteMode) { SetAbsoluteModeSettings(absoluteMode); } if (Driver.OutputMode is RelativeOutputMode relativeMode) { SetRelativeModeSettings(relativeMode); } if (Driver.OutputMode is IBindingHandler <IBinding> bindingHandler) { SetBindingHandlerSettings(bindingHandler); } if (Settings.AutoHook) { Driver.EnableInput = true; Log.Write("Settings", "Driver is auto-enabled."); } SetToolSettings(); SetInterpolatorSettings(); return(Task.CompletedTask); }
public void MigrateSettings() { TestSettingsStore.Instance.Reset(); var settings = new MigrationAppSettings(); const string testVal1 = "A man, a plan, a canal, panama"; const string testVal2 = "Now is the time for all good men to come to the aide of their country"; settings.App1 = testVal1; settings.App2 = testVal2; settings.Save(); Assert.IsTrue(SettingsMigrator.MigrateSharedSettings(typeof(MigrationAppSettings), null)); var settings1a = new MigrationAppSettings(); Assert.AreEqual(settings1a.App1, testVal1); Assert.AreEqual(settings1a.App2, testVal2); Assert.AreEqual(settings1a.App3, MigrationAppSettings.DefaultValueApp); var group = new SettingsGroupDescriptor(typeof(MigrationAppSettings)); TestSettingsStore.Instance.GetPreviousSettingsGroup(group); TestSettingsStore.Instance.RemoveSettingsGroup(group); var settings2 = new MigrationAppSettings(); Assert.AreEqual(settings2.App1, MigrationAppSettings.DefaultValueApp); Assert.AreEqual(settings2.App2, MigrationAppSettings.DefaultValueApp); Assert.AreEqual(settings2.App3, MigrationAppSettings.DefaultValueApp); Assert.IsTrue(SettingsMigrator.MigrateSharedSettings(typeof(MigrationAppSettings), null)); var settings3 = new MigrationAppSettings(); Assert.AreEqual(settings3.App1, testVal1 + TestSettingsStore.TestString); Assert.AreEqual(settings3.App2, testVal2 + TestSettingsStore.TestString); Assert.AreEqual(settings3.App3, MigrationAppSettings.DefaultValueApp); }
public void TestUserDefaultSettingsMigrated() { ResetUpgradeSettings(); Type settingsClass = typeof(SimpleUserSettings); PopulateSimpleStore(settingsClass); Assert.IsTrue(SettingsMigrator.MigrateSharedSettings(settingsClass, null)); var settings = ApplicationSettingsHelper.GetSettingsClassInstance(settingsClass); SettingsProperty property = settings.Properties[SimpleUserSettings.PropertyUser]; string expected = CreateSettingValue(property, MigrationScope.User, SettingValue.Current); Assert.AreEqual(expected, settings[property.Name]); expected = CreateSettingValue(property, MigrationScope.Shared, SettingValue.Previous); string current = (string)settings.GetSharedPropertyValue(property.Name); Assert.AreEqual(expected, current); }
private async void LoadUserSettings() { AppInfo.PluginManager.Clean(); await LoadPlugins(); await DetectTablets(); var appdataDir = new DirectoryInfo(AppInfo.Current.AppDataDirectory); if (!appdataDir.Exists) { appdataDir.Create(); Log.Write("Settings", $"Created OpenTabletDriver application data directory: {appdataDir.FullName}"); } var settingsFile = new FileInfo(AppInfo.Current.SettingsFile); if (settingsFile.Exists) { SettingsMigrator.Migrate(AppInfo.Current); var settings = Settings.Deserialize(settingsFile); if (settings != null) { await SetSettings(settings); } else { Log.Write("Settings", "Invalid settings detected. Attempting recovery.", LogLevel.Error); settings = Settings.GetDefaults(); Settings.Recover(settingsFile, settings); Log.Write("Settings", "Recovery complete"); await SetSettings(settings); } } else { await ResetSettings(); } }
public async Task SetSettings(Settings settings) { // Dispose filters that implement IDisposable interface if (Driver.OutputMode?.Elements != null) { foreach (var element in Driver.OutputMode.Elements) { try { if (element is IDisposable disposable) { disposable.Dispose(); } } catch (Exception) { Log.Write("Plugin", $"Unable to dispose object '{element.GetType().Name}'", LogLevel.Error); } } } if (settings == null) { await ResetSettings(); } Settings = SettingsMigrator.Migrate(settings); var pluginRef = Settings.OutputMode?.GetPluginReference() ?? AppInfo.PluginManager.GetPluginReference(typeof(AbsoluteMode)); Driver.OutputMode = pluginRef.Construct <IOutputMode>(); if (Driver.OutputMode != null) { Log.Write("Settings", $"Output mode: {pluginRef.Name ?? pluginRef.Path}"); } if (Driver.OutputMode is AbsoluteOutputMode absoluteMode) { SetAbsoluteModeSettings(absoluteMode); } if (Driver.OutputMode is RelativeOutputMode relativeMode) { SetRelativeModeSettings(relativeMode); } if (Driver.OutputMode is IOutputMode outputMode) { SetOutputModeSettings(outputMode); } SetBindingHandlerSettings(); if (Settings.AutoHook) { Driver.EnableInput = true; Log.Write("Settings", "Driver is auto-enabled."); } SetToolSettings(); }
public Task SetSettings(Settings settings) { // Dispose all interpolators to begin changing settings foreach (var interpolator in Driver.Interpolators) { interpolator.Dispose(); } Driver.Interpolators.Clear(); // Dispose filters that implement IDisposable interface if (Driver.OutputMode?.Filters != null) { foreach (var filter in Driver.OutputMode.Filters) { try { if (filter is IDisposable disposableFilter) { disposableFilter.Dispose(); } } catch (Exception) { Log.Write("Plugin", $"Unable to dispose object '{filter.GetType().Name}'", LogLevel.Error); } } } Settings = SettingsMigrator.Migrate(settings); var pluginRef = Settings.OutputMode?.GetPluginReference() ?? AppInfo.PluginManager.GetPluginReference(typeof(AbsoluteMode)); Driver.OutputMode = pluginRef.Construct <IOutputMode>(); if (Driver.OutputMode != null) { Log.Write("Settings", $"Output mode: {pluginRef.Name ?? pluginRef.Path}"); } if (Driver.OutputMode is IOutputMode outputMode) { SetOutputModeSettings(outputMode); } if (Driver.OutputMode is AbsoluteOutputMode absoluteMode) { SetAbsoluteModeSettings(absoluteMode); } if (Driver.OutputMode is RelativeOutputMode relativeMode) { SetRelativeModeSettings(relativeMode); } SetBindingHandlerSettings(); if (Settings.AutoHook) { Driver.EnableInput = true; Log.Write("Settings", "Driver is auto-enabled."); } SetToolSettings(); SetInterpolatorSettings(); return(Task.CompletedTask); }