public static void AddBinding(GenericPanelBinding genericBinding) { if (genericBinding != null) { if (Exists(genericBinding)) { foreach (var binding in _genericBindings) { /* * Tricky considering old profiles that haven't got this property * In the future it should be phased out. */ if (string.IsNullOrEmpty(binding.BindingHash)) { binding.BindingHash = genericBinding.BindingHash; binding.Settings = genericBinding.Settings; } else if (binding.BindingHash == genericBinding.BindingHash) { binding.Settings = genericBinding.Settings; } } } else { _genericBindings.Add(genericBinding); } } }
//PROCESSING OF BIPLINKS AND STREAM LINKS STILL MISSING public static bool FindSolution(GenericPanelBinding genericBinding, ref bool settingsWereModified) { settingsWereModified = false; /* * 1) Check, are there multiple such panels where hardware does not match? If so user must map them * If only 1, then we can map it without asking questions. */ var count = _genericBindings.FindAll(o => (o.HardwareWasFound == false) && (o.PanelType == genericBinding.PanelType)).Count; if (count == 1) { var hidSkeleton = HIDHandler.GetInstance().HIDSkeletons.Find(o => o.PanelInfo.GamingPanelType == genericBinding.PanelType); if (hidSkeleton != null) { //This we can map ourselves! genericBinding.HIDInstance = hidSkeleton.InstanceId; settingsWereModified = true; MessageBox.Show("USB settings has changed. Please save the profile.", "USB changes found", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Reference found in bindings file to a " + genericBinding.PanelType.GetDescriptionField() + ", no such hardware found.", "Hardware missing", MessageBoxButton.OK, MessageBoxImage.Exclamation); } return(true); } return(false); }
public static bool Exists(GenericPanelBinding genericPanelBinding) { foreach (var binding in _genericBindings) { if (binding.HIDInstance == genericPanelBinding.HIDInstance) { return(true); } } return(false); }
/* * This to be used when loading from file. * Checks that bindinghash exists, if not creates it. */ public static void RegisterBindingFromFile(GenericPanelBinding genericBinding) { if (genericBinding != null) { if (!Exists(genericBinding)) { if (string.IsNullOrEmpty(genericBinding.BindingHash)) { genericBinding.BindingHash = Common.GetRandomMd5Hash(); } _genericBindings.Add(genericBinding); } } }
public static bool Exists(GenericPanelBinding genericPanelBinding) { lock (_genericBindingsLock) { foreach (var binding in _genericBindings) { if (binding.Match(genericPanelBinding)) { return(true); } } } return(false); }
// PROCESSING OF BIPLINKS AND STREAM LINKS STILL MISSING public static bool FindSolution(GenericPanelBinding genericBinding, ref bool settingsWereModified) { settingsWereModified = false; /* * 1) Check, are there multiple such panels where hardware does not match? If so user must map them * If only 1, then we can map it without asking questions. */ var count = 0; lock (_genericBindingsLock) { count = _genericBindings .FindAll(o => (o.InUse == false) && (o.PanelType == genericBinding.PanelType)).Count; } if (count == 1) { var hidSkeleton = HIDHandler.GetInstance().HIDSkeletons.Find(o => o.PanelInfo.GamingPanelType == genericBinding.PanelType && o.IsAttached); if (hidSkeleton != null) { // This we can map ourselves! genericBinding.HIDInstance = hidSkeleton.HIDInstance; settingsWereModified = true; MessageBox.Show("USB settings has changed. Please save the profile.", "USB changes found", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Reference found in bindings file to a " + genericBinding.PanelType.GetEnumDescriptionField() + ", no such hardware found.", "Hardware missing", MessageBoxButton.OK, MessageBoxImage.Exclamation); if (MessageBox.Show( "Do you want to remove the configuration(s) for the " + genericBinding.PanelType.GetEnumDescriptionField() + ".", "Delete configuration", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { settingsWereModified = true; genericBinding.HasBeenDeleted = true; MessageBox.Show( "Profile has been changed, please save the profile.", "Panel Removed", MessageBoxButton.OK, MessageBoxImage.Information); } } return(true); } return(false); }
public abstract void ImportSettings(GenericPanelBinding genericPanelBinding);
public bool LoadProfile(string filename, IHardwareConflictResolver hardwareConflictResolver) { try { /* * 0 Open specified filename (parameter) if not null * 1 If exists open last profile used (settings) * 2 Try and open default profile located in My Documents * 3 If none found create default file */ _hardwareConflictResolver = hardwareConflictResolver; _isNewProfile = false; ClearAll(); if (!string.IsNullOrEmpty(filename)) { _filename = filename; _lastProfileUsed = filename; } else { if (!string.IsNullOrEmpty(_lastProfileUsed) && File.Exists(_lastProfileUsed)) { _filename = _lastProfileUsed; } else { return(false); } } if (string.IsNullOrEmpty(_filename) || !File.Exists(_filename)) { //Main window will handle this return(false); } /* * Read all information and add InstanceID to all lines using BeginPanel and EndPanel * * PanelType=PZ55SwitchPanel * PanelInstanceID=\\?\hid#vid_06a3&pid_0d06#8&3f11a32&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030} * BeginPanel * SwitchPanelKey{1KNOB_ENGINE_RIGHT}\o/OSKeyPress{FiftyMilliSec,LSHIFT + VK_Q} * SwitchPanelKey{1KNOB_ENGINE_LEFT}\o/OSKeyPress{FiftyMilliSec,LCONTROL + VK_Q} * SwitchPanelKey{1KNOB_ENGINE_BOTH}\o/OSKeyPress{FiftyMilliSec,LSHIFT + VK_C} * EndPanel * */ _profileLoaded = true; Debug.WriteLine("ProfileHandler reading file ".Append(_filename)); var fileLines = File.ReadAllLines(_filename); var currentPanelType = GamingPanelEnum.Unknown; string currentPanelInstanceID = null; string currentBindingHash = null; var insidePanel = false; var insideJSONPanel = false; GenericPanelBinding genericPanelBinding = null; foreach (var fileLine in fileLines) { if (fileLine.StartsWith("Airframe=")) { if (fileLine.StartsWith("Airframe=NONE")) { //Backward compability _airframe = DCSAirframe.KEYEMULATOR; } else { //Backward compability var airframeAsString = fileLine.Replace("Airframe=", "").Trim(); if (airframeAsString.StartsWith("SA342")) { _airframe = DCSAirframe.SA342M; } else if (airframeAsString.StartsWith("P51D") || airframeAsString.StartsWith("TF51D")) { _airframe = DCSAirframe.P51D; } else if (airframeAsString.StartsWith("L39")) { _airframe = DCSAirframe.L39ZA; } else { _airframe = (DCSAirframe)Enum.Parse(typeof(DCSAirframe), airframeAsString); } } DCSBIOSControlLocator.Airframe = _airframe; } else if (fileLine.StartsWith("OperationLevelFlag=")) { Common.SetOperationModeFlag(int.Parse(fileLine.Replace("OperationLevelFlag=", "").Trim())); } else if (fileLine.StartsWith("UseGenericRadio=")) { Common.UseGenericRadio = (bool.Parse(fileLine.Replace("UseGenericRadio=", "").Trim())); } else if (!fileLine.StartsWith("#") && fileLine.Length > 0) { //Process all these lines. if (fileLine.StartsWith("PanelType=")) { currentPanelType = (GamingPanelEnum)Enum.Parse(typeof(GamingPanelEnum), fileLine.Replace("PanelType=", "").Trim()); genericPanelBinding = new GenericPanelBinding(); genericPanelBinding.PanelType = currentPanelType; } else if (fileLine.StartsWith("PanelInstanceID=")) { currentPanelInstanceID = fileLine.Replace("PanelInstanceID=", "").Trim(); genericPanelBinding.HIDInstance = currentPanelInstanceID; _profileFileInstanceIDs.Add(new KeyValuePair <string, GamingPanelEnum>(currentPanelInstanceID, currentPanelType)); } else if (fileLine.StartsWith("BindingHash=")) { currentBindingHash = fileLine.Replace("BindingHash=", "").Trim(); genericPanelBinding.BindingHash = currentBindingHash; } else if (fileLine.StartsWith("PanelSettingsVersion=")) { //do nothing, this will be phased out } else if (fileLine.Equals("BeginPanel")) { insidePanel = true; } else if (fileLine.Equals("EndPanel")) { if (genericPanelBinding != null) { BindingMappingManager.RegisterBindingFromFile(genericPanelBinding); } insidePanel = false; } else if (fileLine.Equals("BeginPanelJSON")) { insideJSONPanel = true; } else if (fileLine.Equals("EndPanelJSON")) { if (genericPanelBinding != null) { BindingMappingManager.RegisterBindingFromFile(genericPanelBinding); } insideJSONPanel = false; } else { if (insidePanel) { var line = fileLine; if (line.StartsWith("\t")) { line = line.Replace("\t", ""); } genericPanelBinding.Settings.Add(line); } if (insideJSONPanel) { genericPanelBinding.JSONAddLine(fileLine); } } } } //For backwards compability 10.11.2018 if (Common.GetOperationModeFlag() == 0) { SetOperationLevelFlag(); } CheckHardwareConflicts(); SendBindingsReadEvent(); return(true); } catch (Exception ex) { Common.ShowErrorMessageBox(ex); return(false); } }