diff --git a/RELEASE.md b/RELEASE.md index a31f25a..ffe3de7 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -20,6 +20,7 @@ - Fix double presses of A(RETURN)/B(BACKSPACE) in Desktop mode - Fix detection of SAS to switch into full lizard - STEAM + 3 dots brings Task Manager (CTRL+SHIFT+ESCAPE) +- Append `controller_blacklist` to `config.vdf` if missing ## 0.4.x diff --git a/SteamController/Helpers/SteamConfiguration.cs b/SteamController/Helpers/SteamConfiguration.cs index 1ba0971..00adf02 100644 --- a/SteamController/Helpers/SteamConfiguration.cs +++ b/SteamController/Helpers/SteamConfiguration.cs @@ -176,7 +176,7 @@ namespace SteamController.Helpers return value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToHashSet(); } - return null; + return new HashSet(); } public static bool? IsControllerBlacklisted(ushort vendorId, ushort productId) @@ -208,11 +208,21 @@ namespace SteamController.Helpers if (configPath is null) return false; - var lines = File.ReadLines(configPath).ToArray(); - bool result = true; + var lines = File.ReadLines(configPath).ToList(); + var id = String.Format("{0:x}/{1:x}", vendorId, productId); - for (int i = 0; i < lines.Length; i++) + for (int i = 0; i < lines.Count; i++) { + if (lines[i] == "}") + { + if (add) + { + // append controller_blacklist + lines.Insert(i, String.Format("\t\"controller_blacklist\"\t\t\"{0}\"", id)); + break; + } + } + var match = ControllerBlacklistRegex.Match(lines[i]); if (!match.Success) continue; @@ -220,8 +230,6 @@ namespace SteamController.Helpers var value = match.Groups[2].Captures[0].Value; var controllers = value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToHashSet(); - var id = String.Format("{0:x}/{1:x}", vendorId, productId); - if (add) controllers.Add(id); else @@ -232,16 +240,12 @@ namespace SteamController.Helpers String.Join(',', controllers), match.Groups[3].Captures[0].Value ); - result = true; break; } - if (result) - { - File.WriteAllLines(configPath, lines); - } + File.WriteAllLines(configPath, lines); - return result; + return true; } private static T? GetValue(string key, string value) where T : struct