UESaveFile: don't create a backup if the file is already temporary.

Also improve error handling.
This commit is contained in:
Guillaume Jacquemin 2022-04-04 09:21:31 +02:00
parent 704f6e2f49
commit 70ddb0ce39

View file

@ -67,6 +67,13 @@ auto UESaveFile::props() -> Containers::ArrayView<UnrealPropertyBase::ptr> {
}
auto UESaveFile::saveToFile() -> bool {
bool temp_file = _filepath.hasSuffix(".tmp");
if(!temp_file && !Utility::Path::copy(_filepath, _filepath + ".bak"_s)) {
_lastError = "Couldn't create a backup for " + _filepath;
return false;
}
BinaryWriter writer{_filepath + ".tmp"_s};
if(!writer.open()) {
@ -125,12 +132,8 @@ auto UESaveFile::saveToFile() -> bool {
writer.closeFile();
if(!Utility::Path::copy(_filepath, _filepath + ".bak"_s)) {
return false;
}
if(!Utility::Path::copy(_filepath + ".tmp"_s, _filepath)) {
Utility::Path::copy(_filepath + ".bak"_s, _filepath);
if(!temp_file && !Utility::Path::copy(_filepath + ".tmp"_s, _filepath)) {
_lastError = "Couldn't save the file properly.";
return false;
}
else {