save mcdf to temporary path before renaming
This commit is contained in:
@@ -193,6 +193,8 @@ public class MareCharaFileManager : DisposableMediatorSubscriberBase
|
|||||||
public void SaveMareCharaFile(CharacterData? dto, string description, string filePath)
|
public void SaveMareCharaFile(CharacterData? dto, string description, string filePath)
|
||||||
{
|
{
|
||||||
CurrentlyWorking = true;
|
CurrentlyWorking = true;
|
||||||
|
var tempFilePath = filePath + ".tmp";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (dto == null) return;
|
if (dto == null) return;
|
||||||
@@ -200,7 +202,7 @@ public class MareCharaFileManager : DisposableMediatorSubscriberBase
|
|||||||
var mareCharaFileData = _factory.Create(description, dto);
|
var mareCharaFileData = _factory.Create(description, dto);
|
||||||
MareCharaFileHeader output = new(MareCharaFileHeader.CurrentVersion, mareCharaFileData);
|
MareCharaFileHeader output = new(MareCharaFileHeader.CurrentVersion, mareCharaFileData);
|
||||||
|
|
||||||
using var fs = new FileStream(filePath, FileMode.Create);
|
using var fs = new FileStream(tempFilePath, FileMode.Create);
|
||||||
using var lz4 = new LZ4Stream(fs, LZ4StreamMode.Compress, LZ4StreamFlags.HighCompression);
|
using var lz4 = new LZ4Stream(fs, LZ4StreamMode.Compress, LZ4StreamFlags.HighCompression);
|
||||||
using var writer = new BinaryWriter(lz4);
|
using var writer = new BinaryWriter(lz4);
|
||||||
output.WriteToStream(writer);
|
output.WriteToStream(writer);
|
||||||
@@ -224,11 +226,12 @@ public class MareCharaFileManager : DisposableMediatorSubscriberBase
|
|||||||
lz4.Flush();
|
lz4.Flush();
|
||||||
fs.Flush();
|
fs.Flush();
|
||||||
fs.Close();
|
fs.Close();
|
||||||
|
File.Move(tempFilePath, filePath, true);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Failure Saving Mare Chara File, deleting output");
|
_logger.LogError(ex, "Failure Saving Mare Chara File, deleting output");
|
||||||
File.Delete(filePath);
|
File.Delete(tempFilePath);
|
||||||
}
|
}
|
||||||
finally { CurrentlyWorking = false; }
|
finally { CurrentlyWorking = false; }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user