示例#1
0
        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");
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
        /// <summary>
        /// Invoked when the user clicks "Migrate"
        /// </summary>
        /// <param name="sender">The sender of the event</param>
        /// <param name="e">The event data</param>
        private void Migrate_Click(object sender, RoutedEventArgs e)
        {
            if (inFile == "")
            {
                MessageBox.Show("Select a settings file", "Select File", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            else if (!File.Exists(inFile))
            {
                MessageBox.Show("No such settings file", "Select File", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            else
            {
                migrator.Migrate(inFile, outFile);
                MessageBox.Show("Migrated to " + outFile, "Migration Complete", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
示例#7
0
        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 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);
        }
        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();
            }
        }
示例#10
0
        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();
        }
示例#11
0
        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);
        }