2024-11-09 22:29:07 +02:00
|
|
|
/*
|
|
|
|
* ModManager.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../json/JsonNode.h"
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
class JsonNode;
|
|
|
|
class ModDescription;
|
|
|
|
struct CModVersion;
|
|
|
|
|
|
|
|
using TModID = std::string;
|
|
|
|
using TModList = std::vector<TModID>;
|
|
|
|
using TModSet = std::set<TModID>;
|
|
|
|
|
|
|
|
/// Provides interface to access list of locally installed mods
|
|
|
|
class ModsState : boost::noncopyable
|
|
|
|
{
|
|
|
|
TModList modList;
|
|
|
|
|
|
|
|
TModList scanModsDirectory(const std::string & modDir) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ModsState();
|
|
|
|
|
2024-11-14 17:41:22 +02:00
|
|
|
TModList getInstalledMods() const;
|
2024-11-14 20:22:02 +02:00
|
|
|
double getInstalledModSizeMegabytes(const TModID & modName) const;
|
2024-11-14 17:41:22 +02:00
|
|
|
|
|
|
|
uint32_t computeChecksum(const TModID & modName) const;
|
2024-11-09 22:29:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Provides interface to access or change current mod preset
|
|
|
|
class ModsPresetState : boost::noncopyable
|
|
|
|
{
|
|
|
|
JsonNode modConfig;
|
|
|
|
|
|
|
|
void createInitialPreset();
|
|
|
|
void importInitialPreset();
|
|
|
|
|
2024-11-11 13:19:14 +02:00
|
|
|
const JsonNode & getActivePresetConfig() const;
|
|
|
|
|
2024-11-09 22:29:07 +02:00
|
|
|
public:
|
|
|
|
ModsPresetState();
|
|
|
|
|
2024-12-08 22:56:19 +02:00
|
|
|
void createNewPreset(const std::string & presetName);
|
|
|
|
void deletePreset(const std::string & presetName);
|
|
|
|
void activatePreset(const std::string & presetName);
|
|
|
|
void renamePreset(const std::string & oldPresetName, const std::string & newPresetName);
|
|
|
|
|
|
|
|
std::vector<std::string> getAllPresets() const;
|
|
|
|
std::string getActivePreset() const;
|
|
|
|
|
2024-11-14 22:56:19 +02:00
|
|
|
void setModActive(const TModID & modName, bool isActive);
|
|
|
|
|
|
|
|
void addRootMod(const TModID & modName);
|
|
|
|
void eraseRootMod(const TModID & modName);
|
2024-11-26 15:31:32 +02:00
|
|
|
void removeOldMods(const TModList & modsToKeep);
|
2024-11-14 22:56:19 +02:00
|
|
|
|
|
|
|
void setSettingActive(const TModID & modName, const TModID & settingName, bool isActive);
|
|
|
|
void eraseModSetting(const TModID & modName, const TModID & settingName);
|
2024-11-09 22:29:07 +02:00
|
|
|
|
|
|
|
/// Returns list of all mods active in current preset. Mod order is unspecified
|
|
|
|
TModList getActiveMods() const;
|
2024-11-11 13:19:14 +02:00
|
|
|
|
|
|
|
/// Returns list of currently active root mods (non-submod)
|
|
|
|
TModList getActiveRootMods() const;
|
|
|
|
|
|
|
|
/// Returns list of all known settings (submods) for a specified mod
|
|
|
|
std::map<TModID, bool> getModSettings(const TModID & modID) const;
|
2024-11-14 17:41:22 +02:00
|
|
|
std::optional<uint32_t> getValidatedChecksum(const TModID & modName) const;
|
|
|
|
void setValidatedChecksum(const TModID & modName, std::optional<uint32_t> value);
|
|
|
|
|
|
|
|
void saveConfigurationState() const;
|
2024-11-09 22:29:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Provides access to mod properties
|
|
|
|
class ModsStorage : boost::noncopyable
|
|
|
|
{
|
|
|
|
std::map<TModID, ModDescription> mods;
|
|
|
|
|
|
|
|
public:
|
2024-11-13 19:25:59 +02:00
|
|
|
ModsStorage(const TModList & modsToLoad, const JsonNode & repositoryList);
|
2024-11-09 22:29:07 +02:00
|
|
|
|
|
|
|
const ModDescription & getMod(const TModID & fullID) const;
|
2024-11-13 19:25:59 +02:00
|
|
|
|
|
|
|
TModList getAllMods() const;
|
2024-11-09 22:29:07 +02:00
|
|
|
};
|
|
|
|
|
2024-11-14 22:56:19 +02:00
|
|
|
class ModDependenciesResolver : boost::noncopyable
|
2024-11-09 22:29:07 +02:00
|
|
|
{
|
|
|
|
/// all currently active mods, in their load order
|
|
|
|
TModList activeMods;
|
|
|
|
|
|
|
|
/// Mods from current preset that failed to load due to invalid dependencies
|
|
|
|
TModList brokenMods;
|
|
|
|
|
2024-11-14 22:56:19 +02:00
|
|
|
public:
|
|
|
|
ModDependenciesResolver(const TModList & modsToResolve, const ModsStorage & storage);
|
|
|
|
|
|
|
|
void tryAddMods(TModList modsToResolve, const ModsStorage & storage);
|
|
|
|
|
|
|
|
const TModList & getActiveMods() const;
|
|
|
|
const TModList & getBrokenMods() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Provides public interface to access mod state
|
|
|
|
class DLL_LINKAGE ModManager : boost::noncopyable
|
|
|
|
{
|
2024-11-09 22:29:07 +02:00
|
|
|
std::unique_ptr<ModsState> modsState;
|
|
|
|
std::unique_ptr<ModsPresetState> modsPreset;
|
|
|
|
std::unique_ptr<ModsStorage> modsStorage;
|
2024-11-14 22:56:19 +02:00
|
|
|
std::unique_ptr<ModDependenciesResolver> depedencyResolver;
|
2024-11-09 22:29:07 +02:00
|
|
|
|
|
|
|
void generateLoadOrder(TModList desiredModList);
|
2024-11-11 13:19:14 +02:00
|
|
|
void eraseMissingModsFromPreset();
|
|
|
|
void addNewModsToPreset();
|
2024-11-14 22:56:19 +02:00
|
|
|
void updatePreset(const ModDependenciesResolver & newData);
|
|
|
|
|
|
|
|
TModList collectDependenciesRecursive(const TModID & modID) const;
|
2024-11-09 22:29:07 +02:00
|
|
|
|
2024-11-20 00:15:05 +02:00
|
|
|
void tryEnableMod(const TModID & modList);
|
|
|
|
|
2024-11-09 22:29:07 +02:00
|
|
|
public:
|
2024-11-13 19:25:59 +02:00
|
|
|
ModManager(const JsonNode & repositoryList);
|
2024-11-09 22:29:07 +02:00
|
|
|
ModManager();
|
|
|
|
~ModManager();
|
|
|
|
|
|
|
|
const ModDescription & getModDescription(const TModID & modID) const;
|
|
|
|
const TModList & getActiveMods() const;
|
2024-11-13 19:25:59 +02:00
|
|
|
TModList getAllMods() const;
|
2024-11-14 17:41:22 +02:00
|
|
|
|
2024-11-21 23:11:02 +02:00
|
|
|
bool isModSettingActive(const TModID & rootModID, const TModID & modSettingID) const;
|
2024-11-09 22:29:07 +02:00
|
|
|
bool isModActive(const TModID & modID) const;
|
2024-11-14 17:41:22 +02:00
|
|
|
uint32_t computeChecksum(const TModID & modName) const;
|
|
|
|
std::optional<uint32_t> getValidatedChecksum(const TModID & modName) const;
|
|
|
|
void setValidatedChecksum(const TModID & modName, std::optional<uint32_t> value);
|
|
|
|
void saveConfigurationState() const;
|
2024-11-14 20:22:02 +02:00
|
|
|
double getInstalledModSizeMegabytes(const TModID & modName) const;
|
2024-11-14 22:56:19 +02:00
|
|
|
|
2024-11-20 00:15:05 +02:00
|
|
|
void tryEnableMods(const TModList & modList);
|
2024-11-14 22:56:19 +02:00
|
|
|
void tryDisableMod(const TModID & modName);
|
2024-12-08 22:56:19 +02:00
|
|
|
|
|
|
|
void createNewPreset(const std::string & presetName);
|
|
|
|
void deletePreset(const std::string & presetName);
|
|
|
|
void activatePreset(const std::string & presetName);
|
|
|
|
void renamePreset(const std::string & oldPresetName, const std::string & newPresetName);
|
|
|
|
|
|
|
|
std::vector<std::string> getAllPresets() const;
|
|
|
|
std::string getActivePreset() const;
|
2024-11-09 22:29:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|