public static void LoadCommonData(string jsonDirectory)
        {
            if (DCSBIOSProfileLoadStatus.IsLoaded("CommonData") || Common.IsOperationModeFlagSet(OperationFlag.KeyboardEmulationOnly) || _airframe == DCSAirframe.NOFRAMELOADEDYET)
            {
                return;
            }

            try
            {
                lock (LockObject)
                {
                    var commonDataText         = File.ReadAllText(jsonDirectory + "\\CommonData.json");
                    var commonDataControlsText = DCSBIOSJsonFormatterVersion1.Format(commonDataText);
                    var commonDataControls     = JsonConvert.DeserializeObject <DCSBIOSControlRootObject>(commonDataControlsText);
                    _dcsbiosControls.AddRange(commonDataControls.DCSBIOSControls);
                    DCSBIOSProfileLoadStatus.SetLoaded("CommonData", true);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(DCSBIOSNotFoundErrorMessage + " ==>[" + jsonDirectory + "]<==" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
Exemple #2
0
        public static void LoadMetaDataEnd(string jsonDirectory)
        {
            if (DCSBIOSProfileLoadStatus.IsLoaded("MetadataEnd") || Common.IsOperationModeFlagSet(OperationFlag.KeyboardEmulationOnly) || _airframe == DCSAirframe.NOFRAMELOADEDYET)
            {
                return;
            }

            try
            {
                lock (LockObject)
                {
                    var metaDataEndText         = File.ReadAllText(jsonDirectory + "\\MetadataEnd.json");
                    var metaDataEndControlsText = DCSBIOSJsonFormatterVersion1.Format(metaDataEndText);
                    var metaDataEndControls     = JsonConvert.DeserializeObject <DCSBIOSControlRootObject>(metaDataEndControlsText);
                    _dcsbiosControls.AddRange(metaDataEndControls.DCSBIOSControls);
                    DCSBIOSProfileLoadStatus.SetLoaded("MetadataEnd", true);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error loading DCS-BIOS. Check that the DCS-BIOS location setting points to the JSON directory. " + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
        public static void LoadControls()
        {
            /*
             * Load profile for current airframe
             * Remove/Add NS430
             * Load Common Data
             * Load Metadata End
             *
             * This function will have to change when (if) new types of profiles are added to DCS-BIOS
             */
            try
            {
                if (_airframe == DCSAirframe.NOFRAMELOADEDYET ||
                    Common.IsOperationModeFlagSet(OperationFlag.KeyboardEmulationOnly))
                {
                    return;
                }

                if (!Common.IsOperationModeFlagSet(OperationFlag.NS430Enabled))
                {
                    if (DCSBIOSProfileLoadStatus.IsLoaded(DCSAirframe.NS430.GetDescription()))
                    {
                        //Discard all DCS-BIOS controls if user "unloaded" NS430. Not possible to remove them specifically
                        //Better to force load all controls
                        Reset();
                    }
                    else
                    {
                        DCSBIOSProfileLoadStatus.Remove(DCSAirframe.NS430.GetDescription());
                    }
                }

                if (Common.IsOperationModeFlagSet(OperationFlag.NS430Enabled))
                {
                    LoadControls(_jsonDirectory, DCSAirframe.NS430.GetDescription());
                }

                if (_airframe == DCSAirframe.FC3_CD_SRS)
                {
                    LoadCommonData(_jsonDirectory);
                    LoadMetaDataEnd(_jsonDirectory);
                }
                else
                {
                    LoadCommonData(_jsonDirectory);
                    LoadMetaDataEnd(_jsonDirectory);
                    //Load the controls for the actual aircraft/helicopter
                    LoadControls(_jsonDirectory, _airframe.GetDescription());
                }

                //Remove duplicates which may come from loading NS430 or other additional profiles
                while (_dcsbiosControls.Count(controlObject => controlObject.identifier.Equals("_UPDATE_COUNTER")) > 1)
                {
                    _dcsbiosControls.Remove(_dcsbiosControls.FindLast(controlObject =>
                                                                      controlObject.identifier.Equals("_UPDATE_COUNTER")));
                }

                while (_dcsbiosControls.Count(controlObject =>
                                              controlObject.identifier.Equals("_UPDATE_SKIP_COUNTER")) > 1)
                {
                    _dcsbiosControls.Remove(_dcsbiosControls.FindLast(controlObject =>
                                                                      controlObject.identifier.Equals("_UPDATE_SKIP_COUNTER")));
                }
            }
            catch (Exception e)
            {
                throw new Exception(DCSBIOSNotFoundErrorMessage + " ==>[" + _jsonDirectory + "]<==" + e.Message);
            }
        }
 public static void Reset()
 {
     DCSBIOSProfileLoadStatus.Clear();
     _dcsbiosControls.Clear();
 }
        public static void LoadControls(string jsonDirectory, string profile)
        {
            if (DCSBIOSProfileLoadStatus.IsLoaded(profile) || profile == DCSAirframe.KEYEMULATOR.GetDescription() || profile == DCSAirframe.KEYEMULATOR_SRS.GetDescription() || profile == DCSAirframe.NOFRAMELOADEDYET.GetDescription())
            {
                return;
            }

            try
            {
                lock (LockObject)
                {
                    var directoryInfo = new DirectoryInfo(jsonDirectory);
                    IEnumerable <FileInfo> files;
                    Common.DebugP("Searching for " + profile + ".json in directory " + jsonDirectory);
                    try
                    {
                        files = directoryInfo.EnumerateFiles(profile + ".json", SearchOption.TopDirectoryOnly);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Failed to find DCS-BIOS files. -> " + Environment.NewLine + ex.Message);
                    }

                    foreach (var file in files)
                    {
                        Common.DebugP("Opening " + file.DirectoryName + "\\" + file.Name);
                        var    reader = file.OpenText();
                        string text;
                        try
                        {
                            text = reader.ReadToEnd();
                            //Debug.Print(text);
                        }
                        finally
                        {
                            reader.Close();
                        }

                        var jsonData = DCSBIOSJsonFormatterVersion1.Format(text);
//Console.WriteLine(jsonData);

                        /*var newfile = File.CreateText(@"e:\temp\regexp_debug_output.txt.txt");
                         * newfile.Write(jsonData);
                         * newfile.Close();*/
                        var dcsBiosControlList = JsonConvert.DeserializeObject <DCSBIOSControlRootObject>(jsonData);

                        /*foreach (var control in dcsBiosControlList.DCSBIOSControls)
                         * {
                         *  Debug.Print(control.identifier);
                         * }*/
                        //Debug.Print("\n--------------------------\n" + jsonData);
                        _dcsbiosControls.AddRange(dcsBiosControlList.DCSBIOSControls);
                        PrintDuplicateControlIdentifiers(dcsBiosControlList.DCSBIOSControls);

                        /*foreach (var control in _dcsbiosControls)
                         * {
                         *  Debug.Print(control.identifier);
                         * }*/
                    }

                    DCSBIOSProfileLoadStatus.SetLoaded(profile, true);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(DCSBIOSNotFoundErrorMessage + " ==>[" + jsonDirectory + "]<==" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
 private static void Reset()
 {
     DCSBIOSProfileLoadStatus.Clear();
     DCSBIOSControls.Clear();
 }