Exemple #1
0
        private void CheckHardwareConflicts()
        {
            var settingsWereModified = false;

            if (!BindingMappingManager.VerifyBindings(ref settingsWereModified))
            {
                var modifiedBindings = _hardwareConflictResolver.ResolveConflicts();
                BindingMappingManager.MergeModifiedBindings(modifiedBindings);
                settingsWereModified = modifiedBindings != null && modifiedBindings.Count > 0;
            }
            if (settingsWereModified)
            {
                SetIsDirty();
            }
        }
Exemple #2
0
        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);
            }
        }