コード例 #1
0
ファイル: Program.cs プロジェクト: mhwlng/streamdeck-elite
        private static void GetKeyBindings(Object threadContext)
        {
            if (KeyBindingWatcherStartPreset != null)
            {
                KeyBindingWatcherStartPreset.StopWatching();
                KeyBindingWatcherStartPreset.Dispose();
                KeyBindingWatcherStartPreset = null;
            }

            var bindingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Frontier Developments\Elite Dangerous\Options\Bindings");

            if (!Directory.Exists(bindingsPath))
            {
                Logger.Instance.LogMessage(TracingLevel.FATAL, $"Directory doesn't exist {bindingsPath}");
            }

            var startPresetPath = Path.Combine(bindingsPath, "StartPreset.4.start");

            if (!File.Exists(startPresetPath))
            {
                startPresetPath = Path.Combine(bindingsPath, "StartPreset.start");
            }

            //Logger.Instance.LogMessage(TracingLevel.INFO, "bindings path " + bindingsPath);

            var bindsNames = ReadStartPreset(startPresetPath);

            Logger.Instance.LogMessage(TracingLevel.INFO, "key bindings " + string.Join(",", bindsNames));

            var keyBindingPath = Path.GetDirectoryName(startPresetPath);

            Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding path #1 " + keyBindingPath);
            var keyBindingFileName = Path.GetFileName(startPresetPath);

            Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding file name #1 " + keyBindingFileName);
            KeyBindingWatcherStartPreset = new KeyBindingWatcher(keyBindingPath, keyBindingFileName);
            KeyBindingWatcherStartPreset.KeyBindingUpdated += HandleKeyBindingEvents;
            KeyBindingWatcherStartPreset.StartWatching();

            if (bindsNames.Length == 4) // odyssey
            {
                Logger.Instance.LogMessage(TracingLevel.INFO, "odyssey key bindings");

                HandleKeyBinding(BindingType.General, bindingsPath, bindsNames[0]);
                HandleKeyBinding(BindingType.Ship, bindingsPath, bindsNames[1]);
                HandleKeyBinding(BindingType.Srv, bindingsPath, bindsNames[2]);
                HandleKeyBinding(BindingType.OnFoot, bindingsPath, bindsNames[3]);
            }
            else // horizon
            {
                Logger.Instance.LogMessage(TracingLevel.INFO, "horizon key bindings");

                HandleKeyBinding(BindingType.General, bindingsPath, bindsNames.First());
                HandleKeyBinding(BindingType.Ship, bindingsPath, bindsNames.First());
                HandleKeyBinding(BindingType.Srv, bindingsPath, bindsNames.First());
                HandleKeyBinding(BindingType.OnFoot, bindingsPath, bindsNames.First());
            }
        }
コード例 #2
0
        public static void GetKeyBindings()
        {
            if (KeyBindingWatcher1 != null)
            {
                KeyBindingWatcher1.StopWatching();
                KeyBindingWatcher1.Dispose();
                KeyBindingWatcher1 = null;
            }

            if (KeyBindingWatcher2 != null)
            {
                KeyBindingWatcher2.StopWatching();
                KeyBindingWatcher2.Dispose();
                KeyBindingWatcher2 = null;
            }

            var bindingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Frontier Developments\Elite Dangerous\Options\Bindings");

            if (!Directory.Exists(bindingsPath))
            {
                Logger.Instance.LogMessage(TracingLevel.FATAL, $"Directory doesn't exist {bindingsPath}");
            }

            var startPresetPath = Path.Combine(bindingsPath, "StartPreset.start");

            //Logger.Instance.LogMessage(TracingLevel.INFO, "bindings path " + bindingsPath);

            var bindsName = File.ReadAllText(startPresetPath);

            var keyBindingPath = Path.GetDirectoryName(startPresetPath);

            Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding path #1 " + keyBindingPath);
            var keyBindingFileName = Path.GetFileName(startPresetPath);

            Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding file name #1 " + keyBindingFileName);
            KeyBindingWatcher1 = new KeyBindingWatcher(keyBindingPath, keyBindingFileName);
            KeyBindingWatcher1.KeyBindingUpdated += HandleKeyBindingEvents;
            KeyBindingWatcher1.StartWatching();

            var fileName = Path.Combine(bindingsPath, bindsName + ".3.0.binds");

            if (!File.Exists(fileName))
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName);

                fileName = fileName.Replace(".3.0.binds", ".binds");

                if (!File.Exists(fileName))
                {
                    Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName);

                    bindingsPath = SteamPath.FindSteamEliteDirectory();

                    if (!string.IsNullOrEmpty(bindingsPath))
                    {
                        fileName = Path.Combine(bindingsPath, bindsName + ".3.0.binds");

                        if (!File.Exists(fileName))
                        {
                            Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName);

                            fileName = fileName.Replace(".3.0.binds", ".binds");

                            if (!File.Exists(fileName))
                            {
                                Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName);
                            }
                        }
                    }
                }
            }

            if (File.Exists(fileName))
            {
                var serializer = new XmlSerializer(typeof(UserBindings));

                //Logger.Instance.LogMessage(TracingLevel.INFO, "using " + fileName);

                var reader = new StreamReader(fileName);
                Bindings = (UserBindings)serializer.Deserialize(reader);
                reader.Close();


                keyBindingPath = Path.GetDirectoryName(fileName);
                Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding path #2 " + keyBindingPath);
                keyBindingFileName = Path.GetFileName(fileName);
                Logger.Instance.LogMessage(TracingLevel.INFO,
                                           "monitoring key binding file name #2 " + keyBindingFileName);
                KeyBindingWatcher2 = new KeyBindingWatcher(keyBindingPath, keyBindingFileName);
                KeyBindingWatcher2.KeyBindingUpdated += HandleKeyBindingEvents;
                KeyBindingWatcher2.StartWatching();
            }
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: ajhewett/streamdeck-elite
        public static void HandleKeyBinding(BindingType bindingType, string bindingsPath, string bindsName)
        {
            Logger.Instance.LogMessage(TracingLevel.INFO, "handle key binding " + bindsName);

            if (KeyBindingWatcher[(int)bindingType] != null)
            {
                KeyBindingWatcher[(int)bindingType].StopWatching();
                KeyBindingWatcher[(int)bindingType].Dispose();
                KeyBindingWatcher[(int)bindingType] = null;
            }

            var fileName = Path.Combine(bindingsPath, bindsName + ".4.0.binds");

            if (!File.Exists(fileName))
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName);

                fileName = fileName.Replace(".4.0.binds", ".3.0.binds");

                if (!File.Exists(fileName))
                {
                    fileName = fileName.Replace(".3.0.binds", ".binds");

                    if (!File.Exists(fileName))
                    {
                        Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName);
                    }
                }
            }

            // steam
            if (!File.Exists(fileName))
            {
                bindingsPath = SteamPath.FindSteamEliteDirectory();

                if (!string.IsNullOrEmpty(bindingsPath))
                {
                    fileName = Path.Combine(bindingsPath, bindsName + ".4.0.binds");

                    if (!File.Exists(fileName))
                    {
                        Logger.Instance.LogMessage(TracingLevel.ERROR, "steam file not found " + fileName);

                        fileName = fileName.Replace(".4.0.binds", ".3.0.binds");

                        if (!File.Exists(fileName))
                        {
                            fileName = fileName.Replace(".3.0.binds", ".binds");

                            if (!File.Exists(fileName))
                            {
                                Logger.Instance.LogMessage(TracingLevel.ERROR, "steam file not found " + fileName);
                            }
                        }
                    }
                }
            }

            // epic
            if (!File.Exists(fileName))
            {
                bindingsPath = EpicPath.FindEpicEliteDirectory();

                if (!string.IsNullOrEmpty(bindingsPath))
                {
                    fileName = Path.Combine(bindingsPath, bindsName + ".4.0.binds");

                    if (!File.Exists(fileName))
                    {
                        Logger.Instance.LogMessage(TracingLevel.ERROR, "epic file not found " + fileName);

                        fileName = fileName.Replace(".4.0.binds", ".3.0.binds");

                        if (!File.Exists(fileName))
                        {
                            fileName = fileName.Replace(".3.0.binds", ".binds");

                            if (!File.Exists(fileName))
                            {
                                Logger.Instance.LogMessage(TracingLevel.ERROR, "epic file not found " + fileName);
                            }
                        }
                    }
                }
            }

            if (File.Exists(fileName))
            {
                var serializer = new XmlSerializer(typeof(UserBindings));

                //Logger.Instance.LogMessage(TracingLevel.INFO, "using " + fileName);

                var reader = new StreamReader(fileName);
                Binding[bindingType] = (UserBindings)serializer.Deserialize(reader);
                reader.Close();


                var keyBindingPath = Path.GetDirectoryName(fileName);
                Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding path #2 " + keyBindingPath);
                var keyBindingFileName = Path.GetFileName(fileName);


                Logger.Instance.LogMessage(TracingLevel.INFO, "monitoring key binding file name #2 " + keyBindingFileName);

                KeyBindingWatcher[(int)bindingType] = new KeyBindingWatcher(keyBindingPath, keyBindingFileName);
                KeyBindingWatcher[(int)bindingType].KeyBindingUpdated += HandleKeyBindingEvents;
                KeyBindingWatcher[(int)bindingType].StartWatching();
            }
            else
            {
                Logger.Instance.LogMessage(TracingLevel.ERROR, "file not found " + fileName);
            }
        }