Load default config when an invalid config is found (#1008)

- Bind toggle events after setting up their current values. This fixes the issue where the config is saved 10 times when the main window is opened 😬

- Write to disk immediately to decrease the chances of corruption
This commit is contained in:
Xpl0itR 2021-02-09 09:24:37 +00:00 committed by GitHub
parent 51f7cc1483
commit 94f93727cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 35 deletions

View file

@ -227,9 +227,20 @@ namespace Ryujinx.Configuration
/// Loads a configuration file from disk
/// </summary>
/// <param name="path">The path to the JSON configuration file</param>
public static ConfigurationFileFormat Load(string path)
public static bool TryLoad(string path, out ConfigurationFileFormat configurationFileFormat)
{
return JsonHelper.DeserializeFromFile<ConfigurationFileFormat>(path);
try
{
configurationFileFormat = JsonHelper.DeserializeFromFile<ConfigurationFileFormat>(path);
return true;
}
catch
{
configurationFileFormat = null;
return false;
}
}
/// <summary>
@ -238,7 +249,8 @@ namespace Ryujinx.Configuration
/// <param name="path">The path to the JSON configuration file</param>
public void SaveConfig(string path)
{
File.WriteAllText(path, JsonHelper.Serialize(this, true));
using FileStream fileStream = File.Create(path, 4096, FileOptions.WriteThrough);
JsonHelper.Serialize(fileStream, this, true);
}
}
}