diff --git a/Dalamud/Configuration/Internal/DalamudConfiguration.cs b/Dalamud/Configuration/Internal/DalamudConfiguration.cs index e6f77eadf..d2f8c4aa1 100644 --- a/Dalamud/Configuration/Internal/DalamudConfiguration.cs +++ b/Dalamud/Configuration/Internal/DalamudConfiguration.cs @@ -355,17 +355,17 @@ internal sealed class DalamudConfiguration : IServiceType /// Gets or sets hitch threshold for game network up in milliseconds. /// public double GameNetworkUpHitch { get; set; } = 30; - + /// /// Gets or sets hitch threshold for game network down in milliseconds. /// public double GameNetworkDownHitch { get; set; } = 30; - + /// /// Gets or sets hitch threshold for framework update in milliseconds. /// public double FrameworkUpdateHitch { get; set; } = 50; - + /// /// Gets or sets hitch threshold for ui builder in milliseconds. /// @@ -428,7 +428,7 @@ internal sealed class DalamudConfiguration : IServiceType { ThreadSafety.AssertMainThread(); - File.WriteAllText(this.configPath, JsonConvert.SerializeObject(this, SerializerSettings)); + Util.WriteAllTextSafe(this.configPath, JsonConvert.SerializeObject(this, SerializerSettings)); this.DalamudConfigurationSaved?.Invoke(this); } } diff --git a/Dalamud/Game/Config/GameConfig.cs b/Dalamud/Game/Config/GameConfig.cs index 4310ca4a8..81112cd79 100644 --- a/Dalamud/Game/Config/GameConfig.cs +++ b/Dalamud/Game/Config/GameConfig.cs @@ -39,7 +39,7 @@ public sealed class GameConfig : IServiceType public GameConfigSection UiConfig { get; private set; } /// - /// Gets the collection of config options that are control mode specific. (Mouse & Keyboard / Gamepad). + /// Gets the collection of config options that are control mode specific. (Mouse and Keyboard / Gamepad). /// public GameConfigSection UiControl { get; private set; } diff --git a/Dalamud/Plugin/Internal/Types/LocalPluginManifest.cs b/Dalamud/Plugin/Internal/Types/LocalPluginManifest.cs index 0f5348ddd..52cc55b23 100644 --- a/Dalamud/Plugin/Internal/Types/LocalPluginManifest.cs +++ b/Dalamud/Plugin/Internal/Types/LocalPluginManifest.cs @@ -68,7 +68,7 @@ internal record LocalPluginManifest : PluginManifest /// Save a plugin manifest to file. /// /// Path to save at. - public void Save(FileInfo manifestFile) => File.WriteAllText(manifestFile.FullName, JsonConvert.SerializeObject(this, Formatting.Indented)); + public void Save(FileInfo manifestFile) => Util.WriteAllTextSafe(manifestFile.FullName, JsonConvert.SerializeObject(this, Formatting.Indented)); /// /// Loads a plugin manifest from file. diff --git a/Dalamud/Utility/Util.cs b/Dalamud/Utility/Util.cs index 5fb2784af..6a1fa7e46 100644 --- a/Dalamud/Utility/Util.cs +++ b/Dalamud/Utility/Util.cs @@ -568,6 +568,22 @@ public static class Util } } + /// + /// Overwrite text in a file by first writing it to a temporary file, and then + /// moving that file to the path specified. + /// + /// The path of the file to write to. + /// The text to write. + internal static void WriteAllTextSafe(string path, string text) + { + var tmpPath = path + ".tmp"; + if (File.Exists(tmpPath)) + File.Delete(tmpPath); + + File.WriteAllText(tmpPath, text); + File.Move(tmpPath, path, true); + } + private static unsafe void ShowValue(ulong addr, IEnumerable path, Type type, object value) { if (type.IsPointer)