mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
fix: save config + manifests by first writing them to another file and moving them over
Should hopefully make corrupted configs a bit more rare
This commit is contained in:
parent
111eea290c
commit
86181cd2d4
4 changed files with 22 additions and 6 deletions
|
|
@ -355,17 +355,17 @@ internal sealed class DalamudConfiguration : IServiceType
|
|||
/// Gets or sets hitch threshold for game network up in milliseconds.
|
||||
/// </summary>
|
||||
public double GameNetworkUpHitch { get; set; } = 30;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets hitch threshold for game network down in milliseconds.
|
||||
/// </summary>
|
||||
public double GameNetworkDownHitch { get; set; } = 30;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets hitch threshold for framework update in milliseconds.
|
||||
/// </summary>
|
||||
public double FrameworkUpdateHitch { get; set; } = 50;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets hitch threshold for ui builder in milliseconds.
|
||||
/// </summary>
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public sealed class GameConfig : IServiceType
|
|||
public GameConfigSection UiConfig { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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).
|
||||
/// </summary>
|
||||
public GameConfigSection UiControl { get; private set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ internal record LocalPluginManifest : PluginManifest
|
|||
/// Save a plugin manifest to file.
|
||||
/// </summary>
|
||||
/// <param name="manifestFile">Path to save at.</param>
|
||||
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));
|
||||
|
||||
/// <summary>
|
||||
/// Loads a plugin manifest from file.
|
||||
|
|
|
|||
|
|
@ -568,6 +568,22 @@ public static class Util
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overwrite text in a file by first writing it to a temporary file, and then
|
||||
/// moving that file to the path specified.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to write to.</param>
|
||||
/// <param name="text">The text to write.</param>
|
||||
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<string> path, Type type, object value)
|
||||
{
|
||||
if (type.IsPointer)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue