From 94f93727cffc2249cae83b9582f82c843f25a652 Mon Sep 17 00:00:00 2001 From: Xpl0itR Date: Tue, 9 Feb 2021 09:24:37 +0000 Subject: 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 :grimacing: - Write to disk immediately to decrease the chances of corruption --- .../Configuration/ConfigurationFileFormat.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'Ryujinx.Common/Configuration/ConfigurationFileFormat.cs') diff --git a/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs b/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs index 72cc579c..79993d87 100644 --- a/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs +++ b/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs @@ -227,9 +227,20 @@ namespace Ryujinx.Configuration /// Loads a configuration file from disk /// /// The path to the JSON configuration file - public static ConfigurationFileFormat Load(string path) + public static bool TryLoad(string path, out ConfigurationFileFormat configurationFileFormat) { - return JsonHelper.DeserializeFromFile(path); + try + { + configurationFileFormat = JsonHelper.DeserializeFromFile(path); + + return true; + } + catch + { + configurationFileFormat = null; + + return false; + } } /// @@ -238,7 +249,8 @@ namespace Ryujinx.Configuration /// The path to the JSON configuration file 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); } } } \ No newline at end of file -- cgit v1.2.3