private void Reload() { var isCustom = false; var bindsFile = FileOperations.RetryIfNull( () => BindingPreset.FindActivePresetFile(_gameInstallFolder, _gameOptionsFolder, out isCustom), _reloadRetries); if (bindsFile == null) { return; } var bindingPreset = FileOperations.RetryIfNull( () => BindingPreset.FromFile(bindsFile), _reloadRetries); if (isCustom) { _customBindsWatcher.Filter = Path.GetFileName(bindsFile); _customBindsWatcher.Start(); } if (bindingPreset == null) { return; } Changed?.Invoke(this, bindingPreset); }
/// <summary> /// Read the binding presets from the given file. /// </summary> /// <param name="path">The path to the binding presets file.</param> /// <returns>The bindings preset, or <c>null</c> if the file couldn't be read (e.g. in the middle of an update).</returns> public static BindingPreset FromFile(string path) { XDocument xml; using (var fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { if (fs.Length == 0) { return(null); } xml = XDocument.Load(fs); } var res = new BindingPreset { PresetName = xml.Root.Attribute("PresetName")?.Value, KeyboardLayout = xml.Root.Element("KeyboardLayout")?.Value, }; var majorVersion = xml.Root.Attribute("MajorVersion")?.Value; var minorVersion = xml.Root.Attribute("MinorVersion")?.Value; if (Version.TryParse($"{majorVersion}.{minorVersion}", out var version)) { res.Version = version; } foreach (var xSetting in xml.Root.Elements()) { var binding = Binding.FromXml(xSetting); if (binding != null) { res._dict[binding.Name] = binding; } } return(res); }
private void Reload() { var bindsFiles = FileOperations.RetryIfNull( () => BindingPreset.FindActivePresetFiles(_gameInstallFolder, _gameOptionsFolder), _reloadRetries); if (bindsFiles == null) { return; } var uniquePresets = new Dictionary <string, BindingPreset>(StringComparer.Ordinal); foreach (var bindsFile in bindsFiles.Values) { if (uniquePresets.ContainsKey(bindsFile)) { continue; } var bindingPreset = FileOperations.RetryIfNull( () => BindingPreset.FromFile(bindsFile), _reloadRetries); if (bindingPreset == null) { return; } uniquePresets.Add(bindsFile, bindingPreset); } var binds = bindsFiles.ToDictionary(kv => kv.Key, kv => uniquePresets[kv.Value]); var merged = BindingPreset.MergeFromCategories(binds); Changed?.Invoke(this, merged); }
private void Reload() { var bindsFile = BindingPreset.FindActivePresetFile(_gameInstallFolder, _gameOptionsFolder, out var isCustom); if (bindsFile == null) { return; } var bindingPreset = BindingPreset.FromFile(bindsFile); if (isCustom) { _customBindsWatcher.Filter = Path.GetFileName(bindsFile); _customBindsWatcher.Start(); } if (bindingPreset == null) { return; } Changed?.Invoke(this, bindingPreset); }