Changeset View
Changeset View
Standalone View
Standalone View
source/ps/ModInstaller.cpp
Show All 35 Lines | |||||
{ | { | ||||
m_VFS.reset(); | m_VFS.reset(); | ||||
DeleteDirectory(m_TempDir); | DeleteDirectory(m_TempDir); | ||||
} | } | ||||
CModInstaller::ModInstallationResult CModInstaller::Install( | CModInstaller::ModInstallationResult CModInstaller::Install( | ||||
const OsPath& mod, | const OsPath& mod, | ||||
const std::shared_ptr<ScriptRuntime>& scriptRuntime, | const std::shared_ptr<ScriptRuntime>& scriptRuntime, | ||||
bool deleteAfterInstall) | bool keepFile) | ||||
{ | { | ||||
const OsPath modTemp = m_TempDir / mod.Basename() / mod.Filename().ChangeExtension(L".zip"); | const OsPath modTemp = m_TempDir / mod.Basename() / mod.Filename().ChangeExtension(L".zip"); | ||||
CreateDirectories(modTemp.Parent(), 0700); | CreateDirectories(modTemp.Parent(), 0700); | ||||
if (keepFile) | |||||
CopyFile(mod, modTemp, true); | CopyFile(mod, modTemp, true); | ||||
else | |||||
wrename(mod, modTemp); | |||||
// 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) | ||||
return FAIL_ON_VFS_MOUNT; | return FAIL_ON_VFS_MOUNT; | ||||
CVFSFile modinfo; | CVFSFile modinfo; | ||||
PSRETURN modinfo_status = modinfo.Load(m_VFS, m_CacheDir / modTemp.Basename() / "mod.json", false); | PSRETURN modinfo_status = modinfo.Load(m_VFS, m_CacheDir / modTemp.Basename() / "mod.json", false); | ||||
m_VFS->Clear(); | m_VFS->Clear(); | ||||
if (modinfo_status != PSRETURN_OK) | if (modinfo_status != PSRETURN_OK) | ||||
Show All 33 Lines | #ifdef OS_WIN | ||||
std::ofstream mod_json((modDir / "mod.json").string8()); | std::ofstream mod_json((modDir / "mod.json").string8()); | ||||
if (mod_json.good()) | if (mod_json.good()) | ||||
{ | { | ||||
mod_json << modinfo.GetAsString(); | mod_json << modinfo.GetAsString(); | ||||
mod_json.close(); | mod_json.close(); | ||||
} | } | ||||
#endif // OS_WIN | #endif // OS_WIN | ||||
// Remove the original file if requested | |||||
if (deleteAfterInstall) | |||||
wunlink(mod); | |||||
m_InstalledMods.emplace_back(modName); | m_InstalledMods.emplace_back(modName); | ||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
const std::vector<CStr>& CModInstaller::GetInstalledMods() const | const std::vector<CStr>& CModInstaller::GetInstalledMods() const | ||||
{ | { | ||||
return m_InstalledMods; | return m_InstalledMods; | ||||
} | } |
Wildfire Games · Phabricator