Allow to lock steam controller locking files

- This locks `controller_neptune` configs when adding steam detection
- This overwrites default desktop/chord template
- This enables a desktop template
This commit is contained in:
Kamil Trzciński 2022-12-02 11:29:06 +01:00
parent cc085bfc2a
commit 19e7ed7012
14 changed files with 279 additions and 23 deletions

View file

@ -262,6 +262,83 @@ namespace SteamController.Helpers
}
}
public static bool? IsConfigFileOverwritten(String path, byte[] content)
{
try
{
var configPath = GetConfigPath(path);
if (configPath is null)
return null;
byte[] diskContent = File.ReadAllBytes(configPath);
return content.SequenceEqual(diskContent);
}
catch (IOException)
{
return null;
}
}
public static bool? ResetConfigFile(String path)
{
try
{
var configPath = GetConfigPath(path);
if (configPath is null)
return null;
File.Copy(configPath + ".orig", configPath, true);
return true;
}
catch (UnauthorizedAccessException)
{
return false;
}
catch (System.Security.SecurityException)
{
return false;
}
catch (IOException)
{
return null;
}
}
public static bool? OverwriteConfigFile(String path, byte[] content, bool backup)
{
try
{
var configPath = GetConfigPath(path);
if (configPath is null)
return null;
try
{
byte[] diskContent = File.ReadAllBytes(configPath);
if (content.Equals(diskContent))
return false;
}
catch (IOException) { }
if (backup)
File.Copy(configPath, configPath + ".orig", true);
File.WriteAllBytes(configPath, content);
return true;
}
catch (UnauthorizedAccessException)
{
return false;
}
catch (System.Security.SecurityException)
{
return false;
}
catch (IOException)
{
return null;
}
}
private static T? GetValue<T>(string key, string value) where T : struct
{
try