mirror of
https://github.com/netchx/netch.git
synced 2026-03-14 17:43:18 +08:00
Fixup Touch Configuration File
This commit is contained in:
@@ -112,13 +112,11 @@ namespace Netch.Utils
|
||||
|
||||
var tempFile = Path.Combine(DataDirectoryFullName, FileFullName + ".tmp");
|
||||
await using (var fileStream = new FileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true))
|
||||
await using (fileStream.ConfigureAwait(false))
|
||||
{
|
||||
await JsonSerializer.SerializeAsync(fileStream, Global.Settings, JsonSerializerOptions).ConfigureAwait(false);
|
||||
await JsonSerializer.SerializeAsync(fileStream, Global.Settings, JsonSerializerOptions);
|
||||
}
|
||||
|
||||
if (!File.Exists(FileFullName))
|
||||
File.Create(FileFullName);
|
||||
await EnsureConfigFileExistsAsync();
|
||||
|
||||
File.Replace(tempFile, FileFullName, BackupFileFullName);
|
||||
}
|
||||
@@ -127,5 +125,13 @@ namespace Netch.Utils
|
||||
Log.Error(e, "保存配置异常");
|
||||
}
|
||||
}
|
||||
|
||||
private static async ValueTask EnsureConfigFileExistsAsync()
|
||||
{
|
||||
if (!File.Exists(FileFullName))
|
||||
{
|
||||
await File.Create(FileFullName).DisposeAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user