/// <summary> /// Reads a new setting from a file. /// </summary> /// <param name="filePath">Filepath of the settings file</param> /// <returns></returns> public static Settings Load(string filePath) { var settings = new Settings(); if (File.Exists(filePath)) { var text = File.ReadAllText(filePath); IniData ini = IniData.Deserialize(text); foreach (var section in ini.Content) { var id = section.Key; if (id == "General") { if (section.Value.ContainsKey("Language")) { LanguageManager.getInstance().Language = section.Value["Language"]; } } else if (id == "Keyboard") { settings.mappers[id] = KeyboardToXInputMapper.Parse(section.Value); } else { settings.mappers[id] = DirectToXInputMapper.Parse(section.Value); } } } return(settings); }
/// <summary> /// Gets the mapper with the given deviceID. If the mapper is not saved in this settings, a new mapper will be returned. /// </summary> /// <param name="id">DeviceID</param> /// <returns></returns> public InputMapperBase GetMapper(string id) { if (!mappers.ContainsKey(id)) { if (id == "Keyboard") { mappers[id] = new KeyboardToXInputMapper(); } else { mappers[id] = new DirectToXInputMapper(); } } return(mappers[id]); }
/// <summary> /// Reads a new setting from a file. /// </summary> /// <param name="filePath">Filepath of the settings file</param> /// <returns></returns> public static Settings Load(string filePath) { var settings = new Settings(); if (File.Exists(filePath)) { var text = File.ReadAllText(filePath); IniData ini = IniData.Deserialize(text); foreach (var section in ini.Content) { var id = section.Key; if (id == General) { if (section.Value.ContainsKey(LanguageKey)) { LanguageManager.Instance.Language = section.Value[LanguageKey]; } if (section.Value.ContainsKey(CloseToTrayKey)) { settings.CloseToTray = section.Value[CloseToTrayKey] == "true"; } if (section.Value.ContainsKey(ShowAllKey)) { settings.ShowAll = section.Value[ShowAllKey] == "true"; } if (section.Value.ContainsKey(HidGuardianEnabledKey)) { settings.HidGuardianEnabled = section.Value[HidGuardianEnabledKey] == "true"; } } else if (id == KeyboardKey) { settings.mappers[id] = KeyboardToXInputMapper.Parse(section.Value); logger.Debug("Mapper loaded for keyboard"); } else { settings.mappers[id] = DirectToXInputMapper.Parse(section.Value); logger.Debug("Mapper loaded for " + id); } } } return(settings); }