This commit is contained in:
JustArchi 2018-01-02 08:19:37 +01:00
parent 6916d2c070
commit cc1f99d5d4
2 changed files with 8 additions and 4 deletions

View file

@ -256,11 +256,13 @@ namespace ArchiSteamFarm {
return;
}
// We always want to write entire content to temporary file first, in order to never load corrupted data, also when target file doesn't exist
await File.WriteAllTextAsync(newFilePath, json).ConfigureAwait(false);
if (File.Exists(FilePath)) {
await File.WriteAllTextAsync(newFilePath, json).ConfigureAwait(false);
File.Replace(newFilePath, FilePath, null);
} else {
await File.WriteAllTextAsync(FilePath, json).ConfigureAwait(false);
File.Move(newFilePath, FilePath);
}
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);

View file

@ -166,11 +166,13 @@ namespace ArchiSteamFarm {
await FileSemaphore.WaitAsync().ConfigureAwait(false);
try {
// We always want to write entire content to temporary file first, in order to never load corrupted data, also when target file doesn't exist
await File.WriteAllTextAsync(newFilePath, json).ConfigureAwait(false);
if (File.Exists(FilePath)) {
await File.WriteAllTextAsync(newFilePath, json).ConfigureAwait(false);
File.Replace(newFilePath, FilePath, null);
} else {
await File.WriteAllTextAsync(FilePath, json).ConfigureAwait(false);
File.Move(newFilePath, FilePath);
}
} catch (Exception e) {
ASF.ArchiLogger.LogGenericException(e);