Append controller_blacklist to config.vdf if missing

This commit is contained in:
Kamil Trzciński 2022-11-27 20:15:04 +01:00
parent 78b8470d3d
commit d4392dd47c
2 changed files with 17 additions and 12 deletions

View file

@ -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

View file

@ -176,7 +176,7 @@ namespace SteamController.Helpers
return value.Split(',', StringSplitOptions.RemoveEmptyEntries).ToHashSet();
}
return null;
return new HashSet<String>();
}
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<T>(string key, string value) where T : struct