mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-09-21 20:06:40 +00:00
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:
@@ -193,6 +193,24 @@ Status DeleteDirectory(const OsPath& path)
|
|||||||
return INFO::OK;
|
return INFO::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Status RenameFile(const OsPath& path, const OsPath& newPath)
|
||||||
|
{
|
||||||
|
if (path.empty())
|
||||||
|
return INFO::OK;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fs::rename(path.string8(), newPath.string8());
|
||||||
|
}
|
||||||
|
catch (fs::filesystem_error& err)
|
||||||
|
{
|
||||||
|
debug_printf("RenameFile: failed to rename %s to %s.\n%s\n", path.string8().c_str(), path.string8().c_str(), err.what());
|
||||||
|
return ERR::EXCEPTION;
|
||||||
|
}
|
||||||
|
|
||||||
|
return INFO::OK;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Status CopyFile(const OsPath& path, const OsPath& newPath, bool override_if_exists/* = false*/)
|
Status CopyFile(const OsPath& path, const OsPath& newPath, bool override_if_exists/* = false*/)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright (C) 2020 Wildfire Games.
|
/* Copyright (C) 2021 Wildfire Games.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
* a copy of this software and associated documentation files (the
|
* a copy of this software and associated documentation files (the
|
||||||
@@ -88,4 +88,6 @@ LIB_API Status DeleteDirectory(const OsPath& dirPath);
|
|||||||
|
|
||||||
LIB_API Status CopyFile(const OsPath& path, const OsPath& newPath, bool override_if_exists = false);
|
LIB_API Status CopyFile(const OsPath& path, const OsPath& newPath, bool override_if_exists = false);
|
||||||
|
|
||||||
|
LIB_API Status RenameFile(const OsPath& path, const OsPath& newPath);
|
||||||
|
|
||||||
#endif // #ifndef INCLUDED_FILE_SYSTEM
|
#endif // #ifndef INCLUDED_FILE_SYSTEM
|
||||||
|
|||||||
+5
-1
@@ -665,7 +665,11 @@ static void RunGameOrAtlas(int argc, const char* argv[])
|
|||||||
|
|
||||||
// Install the mods without deleting the pyromod files
|
// Install the mods without deleting the pyromod files
|
||||||
for (const OsPath& modPath : modsToInstall)
|
for (const OsPath& modPath : modsToInstall)
|
||||||
installer.Install(modPath, g_ScriptContext, true);
|
{
|
||||||
|
CModInstaller::ModInstallationResult result = installer.Install(modPath, g_ScriptContext, true);
|
||||||
|
if (result != CModInstaller::ModInstallationResult::SUCCESS)
|
||||||
|
LOGERROR("Failed to install '%s'", modPath.string8().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
installedMods = installer.GetInstalledMods();
|
installedMods = installer.GetInstalledMods();
|
||||||
|
|
||||||
|
|||||||
@@ -49,9 +49,18 @@ CModInstaller::ModInstallationResult CModInstaller::Install(
|
|||||||
CreateDirectories(modTemp.Parent(), 0700);
|
CreateDirectories(modTemp.Parent(), 0700);
|
||||||
|
|
||||||
if (keepFile)
|
if (keepFile)
|
||||||
CopyFile(mod, modTemp, true);
|
{
|
||||||
else
|
if (CopyFile(mod, modTemp, true) != INFO::OK)
|
||||||
wrename(mod, modTemp);
|
{
|
||||||
|
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
|
// Load the mod to VFS
|
||||||
if (m_VFS->Mount(m_CacheDir, m_TempDir / "") != INFO::OK)
|
if (m_VFS->Mount(m_CacheDir, m_TempDir / "") != INFO::OK)
|
||||||
@@ -88,8 +97,12 @@ CModInstaller::ModInstallationResult CModInstaller::Install(
|
|||||||
// mod-name.zip
|
// mod-name.zip
|
||||||
// mod.json
|
// mod.json
|
||||||
CreateDirectories(modDir, 0700);
|
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;
|
return FAIL_ON_MOD_MOVE;
|
||||||
|
}
|
||||||
|
|
||||||
DeleteDirectory(modTemp.Parent());
|
DeleteDirectory(modTemp.Parent());
|
||||||
|
|
||||||
std::ofstream mod_json((modDir / "mod.json").string8());
|
std::ofstream mod_json((modDir / "mod.json").string8());
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ public:
|
|||||||
FAIL_ON_PARSE_JSON,
|
FAIL_ON_PARSE_JSON,
|
||||||
FAIL_ON_EXTRACT_NAME,
|
FAIL_ON_EXTRACT_NAME,
|
||||||
FAIL_ON_MOD_MOVE,
|
FAIL_ON_MOD_MOVE,
|
||||||
FAIL_ON_JSON_WRITE
|
FAIL_ON_JSON_WRITE,
|
||||||
|
FAIL_ON_MOD_COPY
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-1
@@ -485,7 +485,9 @@ bool ModIo::AdvanceRequest(const ScriptInterface& scriptInterface)
|
|||||||
{
|
{
|
||||||
Paths paths(g_CmdLineArgs);
|
Paths paths(g_CmdLineArgs);
|
||||||
CModInstaller installer(paths.UserData() / "mods", paths.Cache());
|
CModInstaller installer(paths.UserData() / "mods", paths.Cache());
|
||||||
installer.Install(m_DownloadFilePath, g_ScriptContext, false);
|
CModInstaller::ModInstallationResult result = installer.Install(m_DownloadFilePath, g_ScriptContext, false);
|
||||||
|
if (result != CModInstaller::ModInstallationResult::SUCCESS)
|
||||||
|
LOGERROR("Failed to install '%s'", m_DownloadFilePath.string8().c_str());
|
||||||
g_Mods.UpdateAvailableMods(scriptInterface);
|
g_Mods.UpdateAvailableMods(scriptInterface);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user