Esempio n. 1
0
        public Dictionary <int, QuickProfileItem> LoadQuickProfilesList(string fileName)
        {
            var path = BuildCurrentPath(fileName);

            if (!_fileIo.FileExists(path))
            {
                return(null);
            }

            using (var file = _fileIo.OpenText(path))
            {
                var serializer = new JsonSerializer();
                serializer.Converters.Add(new CustomJsonConverter());
                try
                {
                    var list = (Dictionary <int, QuickProfileItem>)serializer.Deserialize(file, typeof(Dictionary <int, QuickProfileItem>));
                    return(list);
                }
                catch (JsonException jsonException)
                {
                    Logging.Log.Error($"Could not deserialize {file}\nPlease verify this a SierraHOTAS compatible JSON file.\n\nStack:{jsonException}");
                    throw;
                }
                catch (Exception e)
                {
                    Logging.Log.Error($"Could not deserialize {fileName}\nStack:{e}");
                    throw;
                }
            }
        }