Limo
A simple mod manager
Loading...
Searching...
No Matches
Bg3Deployer Class Reference

Autonomous deployer which manages the modsettings.lsx file for Baldurs Gate 3. More...

#include <bg3deployer.h>

Inheritance diagram for Bg3Deployer:
Collaboration diagram for Bg3Deployer:

Public Member Functions

 Bg3Deployer (const std::filesystem::path &source_path, const std::filesystem::path &dest_path, const std::string &name)
 Loads mods.
 
virtual void unDeploy (std::optional< ProgressNode * > progress_node={}) override
 If no backup exists: Backs up the current plugin file, then reloads all plugins.
 
virtual std::vector< std::string > getModNames () const override
 Generates a vector of names for every plugin.
 
virtual void setProfile (int profile) override
 Setter for the active profile. Changes the currently active plugin files to the ones saved in the new profile.
 
virtual std::unordered_set< int > getModConflicts (int mod_id, std::optional< ProgressNode * > progress_node={}) override
 Checks for conflicts with other mods. Two mods are conflicting if they share at least one record.
 
- Public Member Functions inherited from PluginDeployer
 PluginDeployer (const std::filesystem::path &source_path, const std::filesystem::path &dest_path, const std::string &name)
 Constructor.
 
virtual std::map< int, unsigned long > deploy (std::optional< ProgressNode * > progress_node={}) override
 Reloads all deployed plugins.
 
virtual std::map< int, unsigned long > deploy (const std::vector< int > &loadorder, std::optional< ProgressNode * > progress_node={}) override
 Reloads all deployed plugins.
 
virtual void changeLoadorder (int from_index, int to_index) override
 Moves a mod from one position in the load order to another. Saves changes to disk.
 
virtual void setModStatus (int mod_id, bool status) override
 Enables or disables the given mod in the load order. Saves changes to disk.
 
virtual std::vector< std::vector< int > > getConflictGroups () const override
 Conflict groups are not supported by this type.
 
virtual void addProfile (int source=-1) override
 Adds a new profile and optionally copies it's load order from an existing profile. Profiles are stored in the target directory.
 
virtual void removeProfile (int profile) override
 Removes a profile.
 
virtual void setConflictGroups (const std::vector< std::vector< int > > &newConflict_groups) override
 Not supported by this type.
 
virtual int getNumMods () const override
 Returns the number of plugins on the load order.
 
virtual std::vector< std::tuple< int, bool > > getLoadorder () const override
 Getter for the current plugin load order.
 
virtual bool addMod (int mod_id, bool enabled=true, bool update_conflicts=true) override
 Does nothing since this deployer manages its own mods.
 
virtual bool removeMod (int mod_id) override
 Not supported by this type.
 
virtual bool hasMod (int mod_id) const override
 Since this deployer uses its own internal mod ids, this function always returns false.
 
virtual bool swapMod (int old_id, int new_id) override
 Does nothing since this deployer manages its own mods.
 
virtual std::vector< ConflictInfogetFileConflicts (int mod_id, bool show_disabled=false, std::optional< ProgressNode * > progress_node={}) const override
 Not supported.
 
virtual void sortModsByConflicts (std::optional< ProgressNode * > progress_node={}) override
 Not supported by this type.
 
virtual void cleanup () override
 Deletes the config file and all profile files.
 
virtual std::vector< std::vector< std::string > > getAutoTags () override
 Getter for mod tags.
 
virtual std::map< std::string, int > getAutoTagMap () override
 Returns all available auto tag names.
 
virtual std::vector< std::pair< std::filesystem::path, int > > getExternallyModifiedFiles (std::optional< ProgressNode * > progress_node={}) const override
 Not supported by this Deployer type.
 
virtual void keepOrRevertFileModifications (const FileChangeChoices &changes_to_keep) override
 Not supported by this Deployer type.
 
virtual void updateDeployedFilesForMod (int mod_id, std::optional< ProgressNode * > progress_node={}) const override
 Updates the deployed files for one mod to match those in the mod's source directory. This is not supported for this deployer type.
 
virtual void fixInvalidLinkDeployMode () override
 Since this deployer type does not use normal deployment methods, this does nothing.
 
virtual void setDeployMode (DeployMode deploy_mode) override
 This deployer always uses copy deploy mode.
 
virtual int getDeployPriority () const override
 Returns the order in which the deploy function of different deployers should be called.
 
virtual bool supportsFileConflicts () const override
 Returns whether or not this deployer type supports showing file conflicts.
 
virtual bool supportsFileBrowsing () const override
 Returns whether or not this deployer type supports browsing mod files.
 
virtual bool idsAreSourceReferences () const override
 Returns whether or not this deployer type uses mod ids as references to source mods. This is usually done by autonomous deployers.
 
virtual std::vector< std::vector< int > > getValidModActions () const override
 Returns a vector containing valid mod actions.
 
- Public Member Functions inherited from Deployer
 Deployer (const std::filesystem::path &source_path, const std::filesystem::path &dest_path, const std::string &name, DeployMode deploy_mode=hard_link)
 Constructor.
 
std::string getDestPath () const
 Getter for path to deployment target directory.
 
std::string getSourcePath () const
 Getter for the path to the deployer's source directory.
 
std::string getName () const
 Getter for deployer name.
 
void setName (const std::string &name)
 Setter for deployer name.
 
void setLoadorder (const std::vector< std::tuple< int, bool > > &loadorder)
 Setter for the load order used for deployment.
 
std::string getType () const
 Returns the type of this deployer, i.e. SIMPLEDEPLOYER.
 
const std::filesystem::path & destPath () const
 Getter for path to deployment target directory.
 
void setDestPath (const std::filesystem::path &path)
 Setter for path to deployment target directory.
 
int getProfile () const
 Getter for the active profile.
 
std::pair< int, std::string > verifyDirectories ()
 Checks if writing to the deployment directory is possible.
 
DeployMode getDeployMode () const
 Getter for the current DeployMode.
 
bool isAutonomous ()
 Getter for is_autonomous_.
 
std::filesystem::path sourcePath () const
 Getter for mod source path.
 
void setSourcePath (const std::filesystem::path &newSourcePath)
 Setter for mod source path.
 
void setLog (const std::function< void(Log::LogLevel, const std::string &)> &newLog)
 Setter for log callback.
 
void updateConflictGroups (std::optional< ProgressNode * > progress_node={})
 Updates conflict_groups_ for the current profile.
 
bool autoUpdateConflictGroups () const
 Getter for auto_update_conflict_groups_.
 
void setAutoUpdateConflictGroups (bool status)
 Setter for auto_update_conflict_groups_.
 
std::optional< bool > getModStatus (int mod_id)
 Searches the load order for the given mod id and returns the corresponding mods activation status, if found.
 
virtual bool supportsSorting () const
 Returns whether or not this deployer type supports sorting mods.
 
virtual bool supportsReordering () const
 Returns whether or not this deployer type supports reordering mods.
 
virtual bool supportsModConflicts () const
 Returns whether or not this deployer type supports showing mod conflicts.
 
virtual std::vector< std::pair< std::string, std::string > > getModActions () const
 Returns names and icon names for additional actions which can be applied to a mod.
 
virtual void applyModAction (int action, int mod_id)
 Applies the given mod action to the given mod.
 

Protected Member Functions

virtual void updatePlugins () override
 Wrapper for updatePluginsPrivate.
 
virtual void saveSettings () const override
 Wrapper for saveSettingsPrivate.
 
virtual void loadSettings () override
 Wrapper for loadSettingsPrivate.
 
virtual void resetSettings () override
 Resets profiles to 1 and active profile to 0.
 
void cleanState ()
 Ensures plugins_ uuid_map_ and pak_files_ are coherent.
 
virtual void writePlugins () const override
 Wrapper for writePluginsPrivate.
 
bool initPluginFile ()
 Reads current plugins from modsettings.lsx and writes them to the plugins file.
 
virtual void updateSourceMods () override
 Updates the source mod map.
 
virtual void updatePluginTags () override
 Tags are currently not supported by this type.
 
- Protected Member Functions inherited from PluginDeployer
virtual void loadPlugins ()
 Load plugins from the plugins file.
 
virtual void writePluginTags () const
 Writes the current tags_ to disk.
 
virtual void restoreUndeployBackupIfExists ()
 If plugin file backups exist, restore it and override the current file.
 
virtual void writeSourceMods () const
 Writes the source mods to disk.
 
virtual void readSourceMods ()
 Reads the source mods from disk.
 
std::optional< std::filesystem::path > getRootOfTargetDirectory (std::filesystem::path target) const
 Finds the directory serving as a target directory for the deployer which manages the given target path.
 
std::string hideFile (const std::string &name)
 Converts the given file name to a hidden file by prepending a ".", if necessary.
 
- Protected Member Functions inherited from Deployer
std::pair< std::map< std::filesystem::path, int >, std::map< int, unsigned long > > getDeploymentSourceFilesAndModSizes (const std::vector< int > &loadorder) const
 Creates a pair of maps. One maps relative file paths to the mod id from which that file is to be deployed. The other maps mod ids to their total file size on disk.
 
void backupOrRestoreFiles (const std::map< std::filesystem::path, int > &source_files, const std::map< std::filesystem::path, int > &dest_files) const
 Backs up all files which would be overwritten during deployment and restores all files backed up during previous deployments files which are no longer overwritten.
 
void deployFiles (const std::map< std::filesystem::path, int > &source_files, std::optional< ProgressNode * > progress_node={}) const
 Hard links all given files to target directory.
 
std::map< std::filesystem::path, int > loadDeployedFiles (std::optional< ProgressNode * > progress_node={}, std::filesystem::path dest_path="") const
 Creates a map of currently deployed files to their source mods.
 
void saveDeployedFiles (const std::map< std::filesystem::path, int > &deployed_files, std::optional< ProgressNode * > progress_node={}) const
 Creates a file containing information about currently deployed files.
 
std::vector< std::string > getModFiles (int mod_id, bool include_directories=false) const
 Creates a vector containing every file contained in one mod. Files are represented as paths relative to the mods root directory.
 
bool modPathExists (int mod_id) const
 modPathExists Checks if the directory containing the given mod exists.
 
bool checkModPathExistsAndMaybeLogError (int mod_id) const
 Checks if the directory containing the given mod exists, if not logs an error.
 
void removeManagedDirFile (const std::filesystem::path &directory) const
 Removes a legacy file that is no longer needed and may cause issues.
 

Protected Attributes

std::map< std::string, std::filesystem::path > uuid_map_
 Maps plugin UUIDs to the pak file containing them.
 
std::map< std::filesystem::path, Bg3PakFilepak_files_
 Maps pak file paths to the object containing that files plugin data.
 
- Protected Attributes inherited from PluginDeployer
std::string config_file_name_ = ".lmmconfig"
 Name of the file containing settings.
 
std::string source_mods_file_name_ = ".lmm_mod_sources"
 Name of the file containing source mod ids for plugins.
 
std::string plugin_file_name_ = "plugins.txt"
 Name of the file containing plugin activation status.
 
std::vector< std::pair< std::string, bool > > plugins_
 Contains names of all plugins and their activation status.
 
int num_profiles_ = 0
 Current number of profiles.
 
std::vector< std::vector< std::string > > tags_
 For every plugin: Every tag associated with that plugin.
 
std::map< std::string, int > source_mods_
 Maps every plugin to a source mod, if that plugin was created by another deployer.
 
std::regex plugin_regex_
 Regex used to match against files in the source directory.
 
std::regex plugin_file_line_regex_
 Regex used to match against lines in the plugin file.
 
std::string tags_file_name_ = ".plugin_tags"
 Name of the file containing loot tags.
 
- Protected Attributes inherited from Deployer
std::string type_ = "Simple Deployer"
 Type of this deployer, e.g. Simple Deployer.
 
std::filesystem::path source_path_
 Path to the directory containing all mods which are to be deployed.
 
std::filesystem::path dest_path_
 Path to the directory where all mods are deployed to.
 
const std::string backup_extension_ = ".lmmbak"
 The file extension appended to backed up files.
 
const std::string deployed_files_name_ = ".lmmfiles"
 The file name for a file in the target directory containing names of deployed files.
 
const std::string managed_dir_file_name_ = ".lmm_managed_dir"
 Name of the file indicating that the directory is managed by a deployer.
 
std::string name_
 The name of this deployer.
 
int current_profile_ = 0
 The currently active profile.
 
std::vector< std::vector< std::tuple< int, bool > > > loadorders_
 One load order per profile consisting of tuples of mod ids and their enabled status.
 
std::vector< std::vector< std::vector< int > > > conflict_groups_
 For every profile: Groups of mods which conflict with each other. The last group contains mods with no conflicts.
 
DeployMode deploy_mode_ = hard_link
 Determines how files should be deployed to the target directory.
 
bool is_autonomous_ = false
 Autonomous deployers manage their own mods and do not rely on ModdedApplication.
 
bool auto_update_conflict_groups_ = false
 If true: Automatically update conflict groups when necessary.
 
std::function< void(Log::LogLevel, const std::string &)> log_
 Callback for logging.
 

Static Protected Attributes

static constexpr std::string BG3_PLUGINS_FILE_NAME = "modsettings.lsx"
 Name of the mod settings file.
 
static const std::set< std::string > NON_PLUGIN_ARCHIVES = { "ModFixer.pak" }
 Mod fixer is a popular mod which does not contain plugins.
 
- Static Protected Attributes inherited from PluginDeployer
static constexpr std::string EXTENSION = ".lmmprof"
 Appended to profile file names.
 
static constexpr std::string UNDEPLOY_BACKUP_EXTENSION = ".undeplbak"
 File extension for plugins.txt and loadorder.txt backup files.
 

Private Member Functions

void updatePluginsPrivate ()
 Reads all pak files in the source directory and extracts all plugins.
 
void saveSettingsPrivate () const
 Saves pak file and profile data to disk.
 
void loadSettingsPrivate ()
 Reads pak file and profile data from disk.
 
void writePluginsPrivate () const
 Writes plugins to modsettings.lsx.
 

Additional Inherited Members

- Public Types inherited from Deployer
enum  DeployMode { hard_link = 0 , sym_link = 1 , copy = 2 }
 Describes how files should be deployed to the target directory. More...
 

Detailed Description

Autonomous deployer which manages the modsettings.lsx file for Baldurs Gate 3.

Constructor & Destructor Documentation

◆ Bg3Deployer()

Bg3Deployer::Bg3Deployer ( const std::filesystem::path & source_path,
const std::filesystem::path & dest_path,
const std::string & name )

Loads mods.

Parameters
source_pathPath to the directory containing installed mods.
dest_pathPath to the directory containing modsettings.lsx.
nameA custom name for this instance.

Member Function Documentation

◆ getModConflicts()

std::unordered_set< int > Bg3Deployer::getModConflicts ( int mod_id,
std::optional< ProgressNode * > progress_node = {} )
overridevirtual

Checks for conflicts with other mods. Two mods are conflicting if they share at least one record.

Parameters
mod_idThe mod to be checked.
progress_nodeUsed to inform about the current progress.
Returns
A set of mod ids which conflict with the given mod.

Reimplemented from PluginDeployer.

◆ getModNames()

std::vector< std::string > Bg3Deployer::getModNames ( ) const
overridevirtual

Generates a vector of names for every plugin.

Returns
The name vector.

Reimplemented from PluginDeployer.

◆ loadSettings()

void Bg3Deployer::loadSettings ( )
overrideprotectedvirtual

Wrapper for loadSettingsPrivate.

Reimplemented from PluginDeployer.

◆ resetSettings()

void Bg3Deployer::resetSettings ( )
overrideprotectedvirtual

Resets profiles to 1 and active profile to 0.

Reimplemented from PluginDeployer.

◆ saveSettings()

void Bg3Deployer::saveSettings ( ) const
overrideprotectedvirtual

Wrapper for saveSettingsPrivate.

Reimplemented from PluginDeployer.

◆ setProfile()

void Bg3Deployer::setProfile ( int profile)
overridevirtual

Setter for the active profile. Changes the currently active plugin files to the ones saved in the new profile.

Parameters
profileThe new profile.

Reimplemented from PluginDeployer.

◆ unDeploy()

void Bg3Deployer::unDeploy ( std::optional< ProgressNode * > progress_node = {})
overridevirtual

If no backup exists: Backs up the current plugin file, then reloads all plugins.

Parameters
progress_nodeUsed to inform about the current progress.

Reimplemented from Deployer.

◆ updatePlugins()

void Bg3Deployer::updatePlugins ( )
overrideprotectedvirtual

Wrapper for updatePluginsPrivate.

Reimplemented from PluginDeployer.

◆ updatePluginTags()

void Bg3Deployer::updatePluginTags ( )
overrideprotectedvirtual

Tags are currently not supported by this type.

Implements PluginDeployer.

◆ updateSourceMods()

void Bg3Deployer::updateSourceMods ( )
overrideprotectedvirtual

Updates the source mod map.

Reimplemented from PluginDeployer.

◆ writePlugins()

void Bg3Deployer::writePlugins ( ) const
overrideprotectedvirtual

Wrapper for writePluginsPrivate.

Reimplemented from PluginDeployer.


The documentation for this class was generated from the following files: