Fix for backup failing when it's in use

The backup file may still be in use by older launcher versions (v2.0.71) if they update
This commit is contained in:
Tixx 2025-07-17 14:33:25 +02:00
parent e6e5bf8327
commit c0ed056440
No known key found for this signature in database
GPG Key ID: EC6E7A2BAABF0B8C

View File

@ -185,8 +185,14 @@ void CheckForUpdates(const std::string& CV) {
"&pk="
+ PublicKey + "&branch=" + Branch,
beammp_wide("new_") + EP);
std::error_code ec;
fs::remove(Back, ec);
if (ec == std::errc::permission_denied) {
error("Failed to remove old backup file: " + ec.message() + ". Using alternative name.");
fs::rename(EP, Back + beammp_wide(".") + Utils::ToWString(FileHash.substr(0, 8)));
} else {
fs::rename(EP, Back);
}
fs::rename(beammp_wide("new_") + EP, EP);
URelaunch();
#endif