![]() |
Limo
A simple mod manager
|
Handles deployment of mods to target directory. More...
#include <deployer.h>
Public Types | |
enum | DeployMode { hard_link = 0 , sym_link = 1 , copy = 2 } |
Describes how files should be deployed to the target directory. More... | |
Public Member Functions | |
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 std::map< int, unsigned long > | deploy (const std::vector< int > &loadorder, std::optional< ProgressNode * > progress_node={}) |
Deploys all mods to the target directory using hard links. If any file already exists in the target directory, a backup for that file is created. Previously backed up files are automatically restored if no mod in the current load order overwrites them. Conflicts are handled by overwriting mods earlier in the load order with later mods. | |
virtual std::map< int, unsigned long > | deploy (std::optional< ProgressNode * > progress_node={}) |
Deploys all mods to the target directory using hard links. If any file already exists in the target directory, a backup for that file is created. Previously backed up files are automatically restored if no mod in the current load order overwrites them. Conflicts are handled by overwriting mods earlier in the load order with later mods. This function uses the internal load order. | |
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. | |
virtual std::vector< std::tuple< int, bool > > | getLoadorder () const |
Getter for the current mod load order. | |
std::string | getType () const |
Returns the type of this deployer, i.e. SIMPLEDEPLOYER. | |
virtual void | changeLoadorder (int from_index, int to_index) |
Moves a mod from one position in the load order to another. | |
virtual bool | addMod (int mod_id, bool enabled=true, bool update_conflicts=true) |
Appends a new mod to the load order. | |
virtual bool | removeMod (int mod_id) |
Removes a mod from the load order. | |
virtual void | setModStatus (int mod_id, bool status) |
Enables or disables the given mod in the load order. | |
virtual bool | hasMod (int mod_id) const |
Checks if given mod id is part of the load order. | |
virtual std::vector< ConflictInfo > | getFileConflicts (int mod_id, bool show_disabled=false, std::optional< ProgressNode * > progress_node={}) const |
Checks for file conflicts of given mod with all other mods in the load order. | |
virtual int | getNumMods () const |
Returns the number of mods in the load order. | |
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. | |
virtual std::unordered_set< int > | getModConflicts (int mod_id, std::optional< ProgressNode * > progress_node={}) |
Checks for conflicts with other mods. Two mods are conflicting if they share at least one file. | |
virtual void | addProfile (int source=-1) |
Adds a new profile and optionally copies it's load order from an existing profile. | |
virtual void | removeProfile (int profile) |
Removes a profile. | |
virtual void | setProfile (int profile) |
Setter for the active profile. | |
int | getProfile () const |
Getter for the active profile. | |
std::pair< int, std::string > | verifyDirectories () |
Checks if writing to the deployment directory is possible. | |
virtual bool | swapMod (int old_id, int new_id) |
Replaces the given id in the load order with a new id. | |
virtual void | sortModsByConflicts (std::optional< ProgressNode * > progress_node={}) |
Sorts the load order by grouping mods which contain conflicting files. | |
virtual std::vector< std::vector< int > > | getConflictGroups () const |
Getter for the conflict groups of the current profile. | |
virtual void | setConflictGroups (const std::vector< std::vector< int > > &newConflict_groups) |
Setter for the conflict groups of the current profile. | |
DeployMode | getDeployMode () const |
Getter for the current DeployMode. | |
virtual void | setDeployMode (DeployMode deploy_mode) |
Sets the current DeployMode. | |
bool | isAutonomous () |
Getter for is_autonomous_. | |
virtual std::vector< std::string > | getModNames () const |
Autonomous deployers override this tho provide names for their mods. Non Autonomous deployers return an empty vector. | |
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. | |
virtual void | cleanup () |
Removes all deployed mods from the target directory and deletes the file which stores the state of this deployer. | |
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 std::vector< std::vector< std::string > > | getAutoTags () |
Getter for auto tags. Only implemented in autonomous deployers. | |
virtual std::map< std::string, int > | getAutoTagMap () |
Returns all available auto tag names mapped to the number of mods for that tag. Only implemented in autonomous deployers. | |
virtual std::vector< std::pair< std::filesystem::path, int > > | getExternallyModifiedFiles (std::optional< ProgressNode * > progress_node={}) const |
Currently only supports hard link deployment. Checks if hard links of deployed files have been overwritten with new files. | |
virtual void | keepOrRevertFileModifications (const FileChangeChoices &changes_to_keep) |
Currently only supports hard link deployment. For every given file: Moves the modified file into the source mods directory and links it back in, if the changes are to be kept. Else: Deletes that file and restores the original link. | |
virtual void | updateDeployedFilesForMod (int mod_id, std::optional< ProgressNode * > progress_node={}) const |
Updates the deployed files for one mod to match those in the mod's source directory. | |
virtual void | fixInvalidLinkDeployMode () |
If using hard_link deploy mode and links cannot be created: Switch to sym links. | |
virtual int | getDeployPriority () const |
Returns the order in which the deploy function of different deployers should be called. | |
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 bool | supportsFileConflicts () const |
Returns whether or not this deployer type supports showing file conflicts. | |
virtual bool | supportsFileBrowsing () const |
Returns whether or not this deployer type supports browsing mod files. | |
virtual bool | idsAreSourceReferences () const |
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::pair< std::string, std::string > > | getModActions () const |
Returns names and icon names for additional actions which can be applied to a mod. | |
virtual std::vector< std::vector< int > > | getValidModActions () const |
Returns a vector containing valid mod actions. | |
virtual void | applyModAction (int action, int mod_id) |
Applies the given mod action to the given mod. | |
Protected Member Functions | |
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 | 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. | |
Handles deployment of mods to target directory.
enum Deployer::DeployMode |
Deployer::Deployer | ( | const std::filesystem::path & | source_path, |
const std::filesystem::path & | dest_path, | ||
const std::string & | name, | ||
DeployMode | deploy_mode = hard_link ) |
Constructor.
source_path | Path to directory containing mods installed using the Installer class. |
dest_path | Path to target directory for mod deployment. |
name | A custom name for this instance. |
deploy_mode | Determines how files are deployed to the target directory. |
|
virtual |
Appends a new mod to the load order.
mod_id | Id of the mod to be added. |
enabled | Controls if the new mod will be enabled. |
update_conflicts | If true: Update mod conflict groups. |
Reimplemented in PluginDeployer, and ReverseDeployer.
|
virtual |
Adds a new profile and optionally copies it's load order from an existing profile.
source | The profile to be copied. A value of -1 indicates no copy. |
Reimplemented in LootDeployer, PluginDeployer, and ReverseDeployer.
|
virtual |
Applies the given mod action to the given mod.
action | Action to be applied. |
mod_id | Target mod. |
Reimplemented in OpenMwPluginDeployer.
|
protected |
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.
source_files | A map of files to be deployed to their source mods. |
dest_files | A map of files currently deployed to their source mods. |
|
virtual |
Moves a mod from one position in the load order to another.
from_index | Index of mod to be moved. |
to_index | Destination index. |
Reimplemented in PluginDeployer, and ReverseDeployer.
|
protected |
Checks if the directory containing the given mod exists, if not logs an error.
mod_id | If of the mod to check. |
|
virtual |
Removes all deployed mods from the target directory and deletes the file which stores the state of this deployer.
Reimplemented in LootDeployer, PluginDeployer, and ReverseDeployer.
|
virtual |
Deploys all mods to the target directory using hard links. If any file already exists in the target directory, a backup for that file is created. Previously backed up files are automatically restored if no mod in the current load order overwrites them. Conflicts are handled by overwriting mods earlier in the load order with later mods.
loadorder | A vector of mod ids representing the load order. |
progress_node | Used to inform about the current progress of deployment. |
Reimplemented in CaseMatchingDeployer, PluginDeployer, and ReverseDeployer.
|
virtual |
Deploys all mods to the target directory using hard links. If any file already exists in the target directory, a backup for that file is created. Previously backed up files are automatically restored if no mod in the current load order overwrites them. Conflicts are handled by overwriting mods earlier in the load order with later mods. This function uses the internal load order.
progress_node | Used to inform about the current progress of deployment. |
Reimplemented in CaseMatchingDeployer, PluginDeployer, and ReverseDeployer.
|
protected |
Hard links all given files to target directory.
source_files | A map of files to be deployed to their source mods. |
progress_node | Used to inform about the current progress of deployment. |
const std::filesystem::path & Deployer::destPath | ( | ) | const |
Getter for path to deployment target directory.
|
virtual |
If using hard_link deploy mode and links cannot be created: Switch to sym links.
Reimplemented in PluginDeployer.
|
virtual |
Returns all available auto tag names mapped to the number of mods for that tag. Only implemented in autonomous deployers.
Reimplemented in LootDeployer, OpenMwPluginDeployer, PluginDeployer, and ReverseDeployer.
|
virtual |
Getter for auto tags. Only implemented in autonomous deployers.
Reimplemented in PluginDeployer, and ReverseDeployer.
|
virtual |
Getter for the conflict groups of the current profile.
Reimplemented in OpenMwPluginDeployer, PluginDeployer, and ReverseDeployer.
|
protected |
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.
loadorder | The load order used for file checks. |
Deployer::DeployMode Deployer::getDeployMode | ( | ) | const |
Getter for the current DeployMode.
|
virtual |
Returns the order in which the deploy function of different deployers should be called.
Reimplemented in PluginDeployer, and ReverseDeployer.
std::string Deployer::getDestPath | ( | ) | const |
Getter for path to deployment target directory.
|
virtual |
Currently only supports hard link deployment. Checks if hard links of deployed files have been overwritten with new files.
progress_node | Used to inform about the current progress. |
Reimplemented in PluginDeployer, and ReverseDeployer.
|
virtual |
Checks for file conflicts of given mod with all other mods in the load order.
mod_id | Mod to be checked. |
show_disabled | If true: Also check for conflicts with disabled mods. |
progress_node | Used to inform about the current progress. |
Reimplemented in PluginDeployer, and ReverseDeployer.
|
virtual |
Getter for the current mod load order.
Reimplemented in PluginDeployer, and ReverseDeployer.
|
virtual |
Returns names and icon names for additional actions which can be applied to a mod.
Reimplemented in OpenMwPluginDeployer.
|
virtual |
Checks for conflicts with other mods. Two mods are conflicting if they share at least one file.
mod_id | The mod to be checked. |
progress_node | Used to inform about the current progress. |
Reimplemented in Bg3Deployer, LootDeployer, PluginDeployer, and ReverseDeployer.
|
protected |
Creates a vector containing every file contained in one mod. Files are represented as paths relative to the mods root directory.
mod_id | Target mod. |
include_directories | If true: Also include all directories in the mod. |
|
virtual |
Autonomous deployers override this tho provide names for their mods. Non Autonomous deployers return an empty vector.
Reimplemented in Bg3Deployer, PluginDeployer, and ReverseDeployer.
std::optional< bool > Deployer::getModStatus | ( | int | mod_id | ) |
Searches the load order for the given mod id and returns the corresponding mods activation status, if found.
mod_id | Mod to be found. |
std::string Deployer::getName | ( | ) | const |
Getter for deployer name.
|
virtual |
Returns the number of mods in the load order.
Reimplemented in PluginDeployer, and ReverseDeployer.
int Deployer::getProfile | ( | ) | const |
Getter for the active profile.
std::string Deployer::getSourcePath | ( | ) | const |
Getter for the path to the deployer's source directory.
std::string Deployer::getType | ( | ) | const |
Returns the type of this deployer, i.e. SIMPLEDEPLOYER.
|
virtual |
Returns a vector containing valid mod actions.
Reimplemented in OpenMwPluginDeployer, PluginDeployer, and ReverseDeployer.
|
virtual |
Checks if given mod id is part of the load order.
mod_id | Mod to be checked. |
Reimplemented in PluginDeployer, and ReverseDeployer.
|
virtual |
Returns whether or not this deployer type uses mod ids as references to source mods. This is usually done by autonomous deployers.
Reimplemented in PluginDeployer.
|
virtual |
Currently only supports hard link deployment. For every given file: Moves the modified file into the source mods directory and links it back in, if the changes are to be kept. Else: Deletes that file and restores the original link.
changes_to_keep | Contains paths to modified files, the id of the mod currently responsible for that file and a bool which indicates whether or not changes to that file should be kept. |
Reimplemented in PluginDeployer, and ReverseDeployer.
|
protected |
Creates a map of currently deployed files to their source mods.
progress_node | Used to inform about the current progress. |
dest_path | Directory containing the file in which deployed file names are stored. If empty: Use the location in dest_path_ instead. |
|
protected |
modPathExists Checks if the directory containing the given mod exists.
mod_id | If of the mod to check. |
|
protected |
Removes a legacy file that is no longer needed and may cause issues.
directory | Directory from which to remove the file. |
|
virtual |
Removes a mod from the load order.
mod_id | Id of the mod to be removed. |
Reimplemented in PluginDeployer, and ReverseDeployer.
|
virtual |
Removes a profile.
profile | The profile to be removed. |
Reimplemented in LootDeployer, PluginDeployer, and ReverseDeployer.
|
protected |
Creates a file containing information about currently deployed files.
deployed_files | The currently deployed files. |
progress_node | Used to inform about the current progress. |
|
virtual |
Setter for the conflict groups of the current profile.
newConflict_groups | The new conflict groups. |
Reimplemented in PluginDeployer, and ReverseDeployer.
|
virtual |
Sets the current DeployMode.
deploy_mode | The new DeployMode. |
Reimplemented in PluginDeployer.
void Deployer::setDestPath | ( | const std::filesystem::path & | path | ) |
Setter for path to deployment target directory.
newDest_path | the new path. |
void Deployer::setLoadorder | ( | const std::vector< std::tuple< int, bool > > & | loadorder | ) |
Setter for the load order used for deployment.
loadorder | The new load order. |
void Deployer::setLog | ( | const std::function< void(Log::LogLevel, const std::string &)> & | newLog | ) |
Setter for log callback.
newLog | New log callback |
|
virtual |
Enables or disables the given mod in the load order.
mod_id | Mod to be edited. |
status | The new status. |
Reimplemented in PluginDeployer, and ReverseDeployer.
void Deployer::setName | ( | const std::string & | name | ) |
Setter for deployer name.
name | The new name. |
|
virtual |
Setter for the active profile.
profile | The new profile. |
Reimplemented in Bg3Deployer, LootDeployer, PluginDeployer, and ReverseDeployer.
void Deployer::setSourcePath | ( | const std::filesystem::path & | newSourcePath | ) |
Setter for mod source path.
New | source path. |
|
virtual |
Sorts the load order by grouping mods which contain conflicting files.
progress_node | Used to inform about the current progress. |
Reimplemented in LootDeployer, OpenMwPluginDeployer, PluginDeployer, and ReverseDeployer.
|
virtual |
Returns whether or not this deployer type supports browsing mod files.
Reimplemented in PluginDeployer, and ReverseDeployer.
|
virtual |
Returns whether or not this deployer type supports showing file conflicts.
Reimplemented in PluginDeployer, and ReverseDeployer.
|
virtual |
Returns whether or not this deployer type supports showing mod conflicts.
Reimplemented in OpenMwArchiveDeployer, OpenMwPluginDeployer, and ReverseDeployer.
|
virtual |
Returns whether or not this deployer type supports reordering mods.
Reimplemented in ReverseDeployer.
|
virtual |
Returns whether or not this deployer type supports sorting mods.
Reimplemented in OpenMwArchiveDeployer, and ReverseDeployer.
|
virtual |
Replaces the given id in the load order with a new id.
old_id | The mod to be replaced. |
new_id | The new mod. |
Reimplemented in PluginDeployer, and ReverseDeployer.
|
virtual |
Removes all deployed mods from the target directory and restores backups.
progress_node | Used to inform about the current progress. |
Reimplemented in Bg3Deployer, LootDeployer, OpenMwArchiveDeployer, OpenMwPluginDeployer, and ReverseDeployer.
void Deployer::updateConflictGroups | ( | std::optional< ProgressNode * > | progress_node = {} | ) |
Updates conflict_groups_ for the current profile.
progress_node | Used to inform about the current progress. |
|
virtual |
Updates the deployed files for one mod to match those in the mod's source directory.
mod_id | Target mod. |
progress_node | Used to inform about progress. |
Reimplemented in CaseMatchingDeployer, PluginDeployer, and ReverseDeployer.
std::pair< int, std::string > Deployer::verifyDirectories | ( | ) |
Checks if writing to the deployment directory is possible.
|
protected |
Callback for logging.