Fix updating existing mods

Replace wrename, that fails when mod exists already with RenameFile by
@Stan
Check if mod was actually installed when downloading it
error if mod cannot be coppied into modTemp

Differential revision: D4222
This was SVN commit r25854.
This commit is contained in:
Angen
2021-08-22 11:35:34 +00:00
parent 83bb6f3ed5
commit 52baaa4bbd
6 changed files with 48 additions and 8 deletions
+17 -4
View File
@@ -49,9 +49,18 @@ CModInstaller::ModInstallationResult CModInstaller::Install(
CreateDirectories(modTemp.Parent(), 0700);
if (keepFile)
CopyFile(mod, modTemp, true);
else
wrename(mod, modTemp);
{
if (CopyFile(mod, modTemp, true) != INFO::OK)
{
LOGERROR("Failed to copy '%s' to '%s'", mod.string8().c_str(), modTemp.string8().c_str());
return FAIL_ON_MOD_COPY;
}
}
else if (RenameFile(mod, modTemp) != INFO::OK)
{
LOGERROR("Failed to rename '%s' into '%s'", mod.string8().c_str(), modTemp.string8().c_str());
return FAIL_ON_MOD_MOVE;
}
// Load the mod to VFS
if (m_VFS->Mount(m_CacheDir, m_TempDir / "") != INFO::OK)
@@ -88,8 +97,12 @@ CModInstaller::ModInstallationResult CModInstaller::Install(
// mod-name.zip
// mod.json
CreateDirectories(modDir, 0700);
if (wrename(modTemp, modPath) != 0)
if (RenameFile(modTemp, modPath) != INFO::OK)
{
LOGERROR("Failed to rename '%s' into '%s'", modTemp.string8().c_str(), modPath.string8().c_str());
return FAIL_ON_MOD_MOVE;
}
DeleteDirectory(modTemp.Parent());
std::ofstream mod_json((modDir / "mod.json").string8());