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); } }
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(); } }
static void Main(string[] args) { // Uncomment this line of code to allow for debugging //while (!System.Diagnostics.Debugger.IsAttached) { System.Threading.Thread.Sleep(100); } Logger.Instance.LogMessage(TracingLevel.INFO, "Init Elite Api"); try { var journalPath = StandardDirectory.FullName; Logger.Instance.LogMessage(TracingLevel.INFO, "journal path " + journalPath); if (!Directory.Exists(journalPath)) { Logger.Instance.LogMessage(TracingLevel.FATAL, $"Directory doesn't exist {journalPath}"); } statusWatcher = new StatusWatcher(journalPath); statusWatcher.StatusUpdated += EliteData.HandleStatusEvents; statusWatcher.StartWatching(); watcher = new JournalWatcher(journalPath); watcher.AllEventHandler += EliteData.HandleEliteEvents; watcher.StartWatching().Wait(); var bindingsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Frontier Developments\Elite Dangerous\Options\Bindings"); Logger.Instance.LogMessage(TracingLevel.INFO, "bindings path " + bindingsPath); if (!Directory.Exists(bindingsPath)) { Logger.Instance.LogMessage(TracingLevel.FATAL, $"Directory doesn't exist {bindingsPath}"); } var bindsName = File.ReadAllText(Path.Combine(bindingsPath, "StartPreset.start")); 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)) { 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"); } } } } 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(); } catch (Exception ex) { Logger.Instance.LogMessage(TracingLevel.FATAL, $"Elite Api: {ex}"); } //EliteAPI.Events.AllEvent += (sender, e) => Console.Beep(); SDWrapper.Run(args); }