aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Common/Configuration/ConfigurationFileFormat.cs
diff options
context:
space:
mode:
authorXpl0itR <xpl0itr@outlook.com>2021-02-09 09:24:37 +0000
committerGitHub <noreply@github.com>2021-02-09 10:24:37 +0100
commit94f93727cffc2249cae83b9582f82c843f25a652 (patch)
tree24b6620814d5358b511e3190df79ea46883e4d78 /Ryujinx.Common/Configuration/ConfigurationFileFormat.cs
parent51f7cc1483f9c9b2a0c2a55693756c60238fb1b6 (diff)
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
Diffstat (limited to 'Ryujinx.Common/Configuration/ConfigurationFileFormat.cs')
-rw-r--r--Ryujinx.Common/Configuration/ConfigurationFileFormat.cs18
1 files changed, 15 insertions, 3 deletions
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
/// </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);
}
}
} \ No newline at end of file