Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/ps/Mod.cpp
/* Copyright (C) 2020 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | JS::Value Mod::GetAvailableMods(const ScriptInterface& scriptInterface) | ||||
// Sort modDirs so that we can do a fast lookup below | // Sort modDirs so that we can do a fast lookup below | ||||
std::sort(modDirs.begin(), modDirs.end()); | std::sort(modDirs.begin(), modDirs.end()); | ||||
PIVFS vfs = CreateVfs(); | PIVFS vfs = CreateVfs(); | ||||
for (DirectoryNames::iterator iter = modDirs.begin(); iter != modDirs.end(); ++iter) | for (DirectoryNames::iterator iter = modDirs.begin(); iter != modDirs.end(); ++iter) | ||||
{ | { | ||||
vfs->Clear(); | vfs->Clear(); | ||||
if (vfs->Mount(L"", modPath / *iter, VFS_MOUNT_MUST_EXIST) < 0) | // Mount with lowest priority, we don't want to overwrite anything | ||||
if (vfs->Mount(L"", modPath / *iter, VFS_MOUNT_MUST_EXIST, VFS_MIN_PRIORITY) < 0) | |||||
continue; | continue; | ||||
CVFSFile modinfo; | CVFSFile modinfo; | ||||
if (modinfo.Load(vfs, L"mod.json", false) != PSRETURN_OK) | if (modinfo.Load(vfs, L"mod.json", false) != PSRETURN_OK) | ||||
continue; | continue; | ||||
JS::RootedValue json(rq.cx); | JS::RootedValue json(rq.cx); | ||||
if (!scriptInterface.ParseJSON(modinfo.GetAsString(), &json)) | if (!scriptInterface.ParseJSON(modinfo.GetAsString(), &json)) | ||||
Show All 9 Lines | JS::Value Mod::GetAvailableMods(const ScriptInterface& scriptInterface) | ||||
for (DirectoryNames::iterator iter = modDirsUser.begin(); iter != modDirsUser.end(); ++iter) | for (DirectoryNames::iterator iter = modDirsUser.begin(); iter != modDirsUser.end(); ++iter) | ||||
{ | { | ||||
// If we are in a dev copy we do not mount mods in the user mod folder that | // If we are in a dev copy we do not mount mods in the user mod folder that | ||||
// are already present in the mod folder, thus we skip those here. | // are already present in the mod folder, thus we skip those here. | ||||
if (dev && std::binary_search(modDirs.begin(), modDirs.end(), *iter)) | if (dev && std::binary_search(modDirs.begin(), modDirs.end(), *iter)) | ||||
continue; | continue; | ||||
vfs->Clear(); | vfs->Clear(); | ||||
if (vfs->Mount(L"", modUserPath / *iter, VFS_MOUNT_MUST_EXIST) < 0) | // Mount with lowest priority, we don't want to overwrite anything | ||||
if (vfs->Mount(L"", modUserPath / *iter, VFS_MOUNT_MUST_EXIST, VFS_MIN_PRIORITY) < 0) | |||||
continue; | continue; | ||||
CVFSFile modinfo; | CVFSFile modinfo; | ||||
if (modinfo.Load(vfs, L"mod.json", false) != PSRETURN_OK) | if (modinfo.Load(vfs, L"mod.json", false) != PSRETURN_OK) | ||||
continue; | continue; | ||||
JS::RootedValue json(rq.cx); | JS::RootedValue json(rq.cx); | ||||
if (!scriptInterface.ParseJSON(modinfo.GetAsString(), &json)) | if (!scriptInterface.ParseJSON(modinfo.GetAsString(), &json)) | ||||
Show All 12 Lines | void Mod::CacheEnabledModVersions(const shared_ptr<ScriptContext>& scriptContext) | ||||
ScriptRequest rq(scriptInterface); | ScriptRequest rq(scriptInterface); | ||||
JS::RootedValue availableMods(rq.cx, GetAvailableMods(scriptInterface)); | JS::RootedValue availableMods(rq.cx, GetAvailableMods(scriptInterface)); | ||||
g_LoadedModVersions.clear(); | g_LoadedModVersions.clear(); | ||||
for (const CStr& mod : g_modsLoaded) | for (const CStr& mod : g_modsLoaded) | ||||
{ | { | ||||
// Ignore user and mod mod as they are irrelevant for compatibility checks | // Ignore mod mod as it is irrelevant for compatibility checks | ||||
if (mod == "mod" || mod == "user") | if (mod == "mod") | ||||
continue; | continue; | ||||
CStr version; | CStr version; | ||||
JS::RootedValue modData(rq.cx); | JS::RootedValue modData(rq.cx); | ||||
if (scriptInterface.GetProperty(availableMods, mod.c_str(), &modData)) | if (scriptInterface.GetProperty(availableMods, mod.c_str(), &modData)) | ||||
scriptInterface.GetProperty(modData, "version", version); | scriptInterface.GetProperty(modData, "version", version); | ||||
g_LoadedModVersions.push_back({mod, version}); | g_LoadedModVersions.push_back({mod, version}); | ||||
Show All 28 Lines |
Wildfire Games · Phabricator