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);
            }
        }
Example #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(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);
            }
        }