Update Available mods when installing them

Differential revision: D4211
Since 498f0d420b available mods where cached and not updated when new
where installed.
Fixing above.

This was SVN commit r25850.
This commit is contained in:
Angen
2021-08-17 17:32:10 +00:00
parent 8f5b5670ff
commit 6400a4a0c5
4 changed files with 16 additions and 11 deletions
+4
View File
@@ -79,6 +79,7 @@ that of Atlas depending on commandline parameters.
#include "rlinterface/RLInterface.h" #include "rlinterface/RLInterface.h"
#include "scriptinterface/ScriptContext.h" #include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptEngine.h" #include "scriptinterface/ScriptEngine.h"
#include "scriptinterface/ScriptInterface.h"
#include "scriptinterface/JSON.h" #include "scriptinterface/JSON.h"
#include "simulation2/Simulation2.h" #include "simulation2/Simulation2.h"
#include "simulation2/system/TurnManager.h" #include "simulation2/system/TurnManager.h"
@@ -665,6 +666,9 @@ static void RunGameOrAtlas(int argc, const char* argv[])
installer.Install(modPath, g_ScriptContext, true); installer.Install(modPath, g_ScriptContext, true);
installedMods = installer.GetInstalledMods(); installedMods = installer.GetInstalledMods();
ScriptInterface modInterface("Engine", "Mod", g_ScriptContext);
g_Mods.UpdateAvailableMods(modInterface);
} }
if (isNonVisual) if (isNonVisual)
+1
View File
@@ -866,6 +866,7 @@ bool Init(const CmdLineArgs& args, int flags)
if (flags & INIT_MODS) if (flags & INIT_MODS)
{ {
ScriptInterface modInterface("Engine", "Mod", g_ScriptContext); ScriptInterface modInterface("Engine", "Mod", g_ScriptContext);
g_Mods.UpdateAvailableMods(modInterface);
std::vector<CStr> mods; std::vector<CStr> mods;
if (args.Has("mod")) if (args.Has("mod"))
mods = args.GetMultiple("mod"); mods = args.GetMultiple("mod");
+1 -2
View File
@@ -156,8 +156,6 @@ bool Mod::EnableMods(const ScriptInterface& scriptInterface, const std::vector<C
if (counts["mod"] == 0) if (counts["mod"] == 0)
m_EnabledMods.insert(m_EnabledMods.begin(), "mod"); m_EnabledMods.insert(m_EnabledMods.begin(), "mod");
UpdateAvailableMods(scriptInterface);
m_IncompatibleMods = CheckForIncompatibleMods(m_EnabledMods); m_IncompatibleMods = CheckForIncompatibleMods(m_EnabledMods);
for (const CStr& mod : m_IncompatibleMods) for (const CStr& mod : m_IncompatibleMods)
@@ -233,6 +231,7 @@ void Mod::UpdateAvailableMods(const ScriptInterface& scriptInterface)
{ {
PROFILE2("UpdateAvailableMods"); PROFILE2("UpdateAvailableMods");
m_AvailableMods.clear();
const Paths paths(g_CmdLineArgs); const Paths paths(g_CmdLineArgs);
// loop over all possible paths // loop over all possible paths
+10 -9
View File
@@ -56,6 +56,16 @@ public:
const std::vector<CStr>& GetIncompatibleMods() const; const std::vector<CStr>& GetIncompatibleMods() const;
const std::vector<ModData>& GetAvailableMods() const; const std::vector<ModData>& GetAvailableMods() const;
/**
* Fetches available mods and stores some metadata about them.
* This may open the zipped mod archives, depending on the situation,
* and/or try to write files to the user mod folder,
* which can be quite slow, so should be run rarely.
* TODO: if this did not need the scriptInterface to parse JSON,
* we could run it in different contexts and possibly cleaner.
*/
void UpdateAvailableMods(const ScriptInterface& scriptInterface);
/** /**
* Enables specified mods (& mods required by the engine). * Enables specified mods (& mods required by the engine).
* @param addPublic - if true, enable the public mod. * @param addPublic - if true, enable the public mod.
@@ -83,15 +93,6 @@ public:
*/ */
static bool AreModsPlayCompatible(const std::vector<const Mod::ModData*>& modsA, const std::vector<const Mod::ModData*>& modsB); static bool AreModsPlayCompatible(const std::vector<const Mod::ModData*>& modsA, const std::vector<const Mod::ModData*>& modsB);
private: private:
/**
* Fetches available mods and stores some metadata about them.
* This may open the zipped mod archives, depending on the situation,
* and/or try to write files to the user mod folder,
* which can be quite slow, so should be run rarely.
* TODO: if this did not need the scriptInterface to parse JSON,
* we could run it in different contexts and possibly cleaner.
*/
void UpdateAvailableMods(const ScriptInterface& scriptInterface);
/** /**
* Checks a list of @a mods and returns the incompatible mods, if any. * Checks a list of @a mods and returns the incompatible mods, if any.