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.
|
/// Gets or sets hitch threshold for game network up in milliseconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double GameNetworkUpHitch { get; set; } = 30;
|
public double GameNetworkUpHitch { get; set; } = 30;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets hitch threshold for game network down in milliseconds.
|
/// Gets or sets hitch threshold for game network down in milliseconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double GameNetworkDownHitch { get; set; } = 30;
|
public double GameNetworkDownHitch { get; set; } = 30;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets hitch threshold for framework update in milliseconds.
|
/// Gets or sets hitch threshold for framework update in milliseconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double FrameworkUpdateHitch { get; set; } = 50;
|
public double FrameworkUpdateHitch { get; set; } = 50;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets hitch threshold for ui builder in milliseconds.
|
/// Gets or sets hitch threshold for ui builder in milliseconds.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -428,7 +428,7 @@ internal sealed class DalamudConfiguration : IServiceType
|
||||||
{
|
{
|
||||||
ThreadSafety.AssertMainThread();
|
ThreadSafety.AssertMainThread();
|
||||||
|
|
||||||
File.WriteAllText(this.configPath, JsonConvert.SerializeObject(this, SerializerSettings));
|
Util.WriteAllTextSafe(this.configPath, JsonConvert.SerializeObject(this, SerializerSettings));
|
||||||
this.DalamudConfigurationSaved?.Invoke(this);
|
this.DalamudConfigurationSaved?.Invoke(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ public sealed class GameConfig : IServiceType
|
||||||
public GameConfigSection UiConfig { get; private set; }
|
public GameConfigSection UiConfig { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public GameConfigSection UiControl { get; private set; }
|
public GameConfigSection UiControl { get; private set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ internal record LocalPluginManifest : PluginManifest
|
||||||
/// Save a plugin manifest to file.
|
/// Save a plugin manifest to file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="manifestFile">Path to save at.</param>
|
/// <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>
|
/// <summary>
|
||||||
/// Loads a plugin manifest from file.
|
/// 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)
|
private static unsafe void ShowValue(ulong addr, IEnumerable<string> path, Type type, object value)
|
||||||
{
|
{
|
||||||
if (type.IsPointer)
|
if (type.IsPointer)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue