Limo
A simple mod manager
Loading...
Searching...
No Matches
PluginDeployer Class Referenceabstract

Base class for autonomous deployers that collects all files which match a given critereon, called plugins, in the source directory and adds them to a file in the target directory. More...

#include <plugindeployer.h>

Inheritance diagram for PluginDeployer:
Collaboration diagram for PluginDeployer:

Public Member Functions

 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 std::vector< std::string > getModNames () const override
 Generates a vector of names for every plugin.
 
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 setProfile (int profile) override
 Setter for the active profile. Changes the currently active plugin files to the ones saved in the new 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 std::unordered_set< int > getModConflicts (int mod_id, std::optional< ProgressNode * > progress_node={}) override
 Not supported by this type.
 
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.
 
virtual void unDeploy (std::optional< ProgressNode * > progress_node={})
 Removes all deployed mods from the target directory and restores backups.
 
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 ()
 Updates current plugins to reflect plugins actually in the source directory.
 
virtual void loadPlugins ()
 Load plugins from the plugins file.
 
virtual void writePlugins () const
 Writes current load order to plugins file.
 
virtual void saveSettings () const
 Saves number of profiles and active profile to the config file.
 
virtual void loadSettings ()
 Loads number of profiles and active profile from the config file.
 
virtual void resetSettings ()
 Resets all settings to default values.
 
virtual void updatePluginTags ()=0
 Updates the plugin tags for every currently loaded plugin. Must be implemented in derived classes.
 
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 updateSourceMods ()
 Updates the source mod map with files created by another deployer.
 
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::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 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.
 

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

Base class for autonomous deployers that collects all files which match a given critereon, called plugins, in the source directory and adds them to a file in the target directory.

Constructor & Destructor Documentation

◆ PluginDeployer()

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

Constructor.

Parameters
source_pathDirectory containing the plugin files.
dest_pathDirectory containing the file(s) into which plugin names are to be written.
nameCustom name for this deployer instance.

Member Function Documentation

◆ addMod()

bool PluginDeployer::addMod ( int mod_id,
bool enabled = true,
bool update_conflicts = true )
overridevirtual

Does nothing since this deployer manages its own mods.

Parameters
mod_idIgnored.
enabledIgnored.
update_conflictsIgnored.
Returns
False.

Reimplemented from Deployer.

◆ addProfile()

void PluginDeployer::addProfile ( int source = -1)
overridevirtual

Adds a new profile and optionally copies it's load order from an existing profile. Profiles are stored in the target directory.

Parameters
sourceThe profile to be copied. A value of -1 indicates no copy.

Reimplemented from Deployer.

Reimplemented in LootDeployer.

◆ changeLoadorder()

void PluginDeployer::changeLoadorder ( int from_index,
int to_index )
overridevirtual

Moves a mod from one position in the load order to another. Saves changes to disk.

Parameters
from_indexIndex of mod to be moved.
to_indexDestination index.

Reimplemented from Deployer.

◆ cleanup()

void PluginDeployer::cleanup ( )
overridevirtual

Deletes the config file and all profile files.

Reimplemented from Deployer.

Reimplemented in LootDeployer.

◆ deploy() [1/2]

std::map< int, unsigned long > PluginDeployer::deploy ( const std::vector< int > & loadorder,
std::optional< ProgressNode * > progress_node = {} )
overridevirtual

Reloads all deployed plugins.

Parameters
loadorderIgnored.
progress_nodeUsed to inform about the current progress of deployment.
Returns
Since this is an autonomous deployer, the returned map is always empty.

Reimplemented from Deployer.

◆ deploy() [2/2]

std::map< int, unsigned long > PluginDeployer::deploy ( std::optional< ProgressNode * > progress_node = {})
overridevirtual

Reloads all deployed plugins.

Parameters
progress_nodeUsed to inform about the current progress of deployment.
Returns
Since this is an autonomous deployer, the returned map is always empty.

Reimplemented from Deployer.

◆ fixInvalidLinkDeployMode()

void PluginDeployer::fixInvalidLinkDeployMode ( )
overridevirtual

Since this deployer type does not use normal deployment methods, this does nothing.

Reimplemented from Deployer.

◆ getAutoTagMap()

std::map< std::string, int > PluginDeployer::getAutoTagMap ( )
overridevirtual

Returns all available auto tag names.

Returns
The tag names.

Reimplemented from Deployer.

Reimplemented in LootDeployer, and OpenMwPluginDeployer.

◆ getAutoTags()

std::vector< std::vector< std::string > > PluginDeployer::getAutoTags ( )
overridevirtual

Getter for mod tags.

Returns
For every mod: A vector of auto tags added to that mod.

Reimplemented from Deployer.

◆ getConflictGroups()

std::vector< std::vector< int > > PluginDeployer::getConflictGroups ( ) const
overridevirtual

Conflict groups are not supported by this type.

Returns
All plugins in the non conflicting group.

Reimplemented from Deployer.

Reimplemented in OpenMwPluginDeployer.

◆ getDeployPriority()

int PluginDeployer::getDeployPriority ( ) const
overridevirtual

Returns the order in which the deploy function of different deployers should be called.

Returns
The priority.

Reimplemented from Deployer.

◆ getExternallyModifiedFiles()

std::vector< std::pair< std::filesystem::path, int > > PluginDeployer::getExternallyModifiedFiles ( std::optional< ProgressNode * > progress_node = {}) const
overridevirtual

Not supported by this Deployer type.

Parameters
progress_nodeIgnored
Returns
An empty vector

Reimplemented from Deployer.

◆ getFileConflicts()

std::vector< ConflictInfo > PluginDeployer::getFileConflicts ( int mod_id,
bool show_disabled = false,
std::optional< ProgressNode * > progress_node = {} ) const
overridevirtual

Not supported.

Parameters
mod_idIgnored.
show_disabledIgnored.
progress_nodeSet to 100%.
Returns
An empty vector.

Reimplemented from Deployer.

◆ getLoadorder()

std::vector< std::tuple< int, bool > > PluginDeployer::getLoadorder ( ) const
overridevirtual

Getter for the current plugin load order.

Returns
The load order.

Reimplemented from Deployer.

◆ getModConflicts()

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

Not supported by this type.

Parameters
mod_idThe mod to be checked.
progress_nodeUsed to inform about the current progress.
Returns
An empty set.

Reimplemented from Deployer.

Reimplemented in Bg3Deployer, and LootDeployer.

◆ getModNames()

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

Generates a vector of names for every plugin.

Returns
The name vector.

Reimplemented from Deployer.

Reimplemented in Bg3Deployer.

◆ getNumMods()

int PluginDeployer::getNumMods ( ) const
overridevirtual

Returns the number of plugins on the load order.

Returns
The number of plugins.

Reimplemented from Deployer.

◆ getRootOfTargetDirectory()

std::optional< sfs::path > PluginDeployer::getRootOfTargetDirectory ( std::filesystem::path target) const
protected

Finds the directory serving as a target directory for the deployer which manages the given target path.

Parameters
targetTarget path to check.
Returns
The deployers target directory or an empty optional if no directory was found.

◆ getValidModActions()

std::vector< std::vector< int > > PluginDeployer::getValidModActions ( ) const
overridevirtual

Returns a vector containing valid mod actions.

Returns
For every mod: IDs of every valid mod_action which is valid for that mod.

Reimplemented from Deployer.

Reimplemented in OpenMwPluginDeployer.

◆ hasMod()

bool PluginDeployer::hasMod ( int mod_id) const
overridevirtual

Since this deployer uses its own internal mod ids, this function always returns false.

Parameters
mod_idIgnores
Returns
False.

Reimplemented from Deployer.

◆ hideFile()

std::string PluginDeployer::hideFile ( const std::string & name)
protected

Converts the given file name to a hidden file by prepending a ".", if necessary.

Parameters
nameFile name to hide.
Returns
The hidden file.

◆ idsAreSourceReferences()

bool PluginDeployer::idsAreSourceReferences ( ) const
overridevirtual

Returns whether or not this deployer type uses mod ids as references to source mods. This is usually done by autonomous deployers.

Returns
True

Reimplemented from Deployer.

◆ keepOrRevertFileModifications()

void PluginDeployer::keepOrRevertFileModifications ( const FileChangeChoices & changes_to_keep)
overridevirtual

Not supported by this Deployer type.

Parameters
changes_to_keepIgnored.

Reimplemented from Deployer.

◆ loadSettings()

void PluginDeployer::loadSettings ( )
protectedvirtual

Loads number of profiles and active profile from the config file.

Reimplemented in Bg3Deployer, and LootDeployer.

◆ removeMod()

bool PluginDeployer::removeMod ( int mod_id)
overridevirtual

Not supported by this type.

Parameters
mod_idIgnored.
Returns
False.

Reimplemented from Deployer.

◆ removeProfile()

void PluginDeployer::removeProfile ( int profile)
overridevirtual

Removes a profile.

Parameters
profileThe profile to be removed.

Reimplemented from Deployer.

Reimplemented in LootDeployer.

◆ resetSettings()

void PluginDeployer::resetSettings ( )
protectedvirtual

Resets all settings to default values.

Reimplemented in Bg3Deployer, and LootDeployer.

◆ restoreUndeployBackupIfExists()

void PluginDeployer::restoreUndeployBackupIfExists ( )
protectedvirtual

If plugin file backups exist, restore it and override the current file.

Reimplemented in LootDeployer.

◆ saveSettings()

void PluginDeployer::saveSettings ( ) const
protectedvirtual

Saves number of profiles and active profile to the config file.

Reimplemented in Bg3Deployer, and LootDeployer.

◆ setConflictGroups()

void PluginDeployer::setConflictGroups ( const std::vector< std::vector< int > > & newConflict_groups)
overridevirtual

Not supported by this type.

Parameters
newConflict_groupsIgnored.

Reimplemented from Deployer.

◆ setDeployMode()

void PluginDeployer::setDeployMode ( DeployMode deploy_mode)
overridevirtual

This deployer always uses copy deploy mode.

Parameters
deploy_modeignored.

Reimplemented from Deployer.

◆ setModStatus()

void PluginDeployer::setModStatus ( int mod_id,
bool status )
overridevirtual

Enables or disables the given mod in the load order. Saves changes to disk.

Parameters
mod_idMod to be edited.
statusThe new status.

Reimplemented from Deployer.

◆ setProfile()

void PluginDeployer::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 Deployer.

Reimplemented in Bg3Deployer, and LootDeployer.

◆ sortModsByConflicts()

void PluginDeployer::sortModsByConflicts ( std::optional< ProgressNode * > progress_node = {})
overridevirtual

Not supported by this type.

Parameters
progress_nodeUsed to inform about the current progress.

Reimplemented from Deployer.

Reimplemented in LootDeployer, and OpenMwPluginDeployer.

◆ supportsFileBrowsing()

bool PluginDeployer::supportsFileBrowsing ( ) const
overridevirtual

Returns whether or not this deployer type supports browsing mod files.

Returns
True if supported.

Reimplemented from Deployer.

◆ supportsFileConflicts()

bool PluginDeployer::supportsFileConflicts ( ) const
overridevirtual

Returns whether or not this deployer type supports showing file conflicts.

Returns
True if supported.

Reimplemented from Deployer.

◆ swapMod()

bool PluginDeployer::swapMod ( int old_id,
int new_id )
overridevirtual

Does nothing since this deployer manages its own mods.

Parameters
old_idIgnored.
new_idIgnored
Returns
False.

Reimplemented from Deployer.

◆ updateDeployedFilesForMod()

void PluginDeployer::updateDeployedFilesForMod ( int mod_id,
std::optional< ProgressNode * > progress_node = {} ) const
overridevirtual

Updates the deployed files for one mod to match those in the mod's source directory. This is not supported for this deployer type.

Parameters
mod_idIgnored.
progress_nodeIgnored.

Reimplemented from Deployer.

◆ updatePlugins()

void PluginDeployer::updatePlugins ( )
protectedvirtual

Updates current plugins to reflect plugins actually in the source directory.

Reimplemented in Bg3Deployer.

◆ updatePluginTags()

virtual void PluginDeployer::updatePluginTags ( )
protectedpure virtual

Updates the plugin tags for every currently loaded plugin. Must be implemented in derived classes.

Implemented in Bg3Deployer, LootDeployer, OpenMwArchiveDeployer, and OpenMwPluginDeployer.

◆ updateSourceMods()

void PluginDeployer::updateSourceMods ( )
protectedvirtual

Updates the source mod map with files created by another deployer.

Reimplemented in Bg3Deployer.

◆ writePlugins()

void PluginDeployer::writePlugins ( ) const
protectedvirtual

Writes current load order to plugins file.

Reimplemented in Bg3Deployer, LootDeployer, OpenMwArchiveDeployer, and OpenMwPluginDeployer.

◆ writePluginTags()

void PluginDeployer::writePluginTags ( ) const
protectedvirtual

Writes the current tags_ to disk.

Reimplemented in OpenMwPluginDeployer.


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