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

Automatically renames mod files to match the case of target files. More...

#include <casematchingdeployer.h>

Inheritance diagram for CaseMatchingDeployer:
Collaboration diagram for CaseMatchingDeployer:

Public Member Functions

 CaseMatchingDeployer (const std::filesystem::path &source_path, const std::filesystem::path &dest_path, const std::string &name, DeployMode deploy_mode=hard_link)
 Passes arguments to base class constructor.
 
virtual std::map< int, unsigned long > deploy (const std::vector< int > &loadorder, std::optional< ProgressNode * > progress_node={}) override
 Iterates over every file and directory contained in the mods in the given load order. If any name case insensitively matches the name of a file in the target directory, the source is renamed to be identical to the target. Then calls Deployer::deploy(loadorder).
 
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.
 
virtual std::map< int, unsigned long > deploy (std::optional< ProgressNode * > progress_node={})
 Use base class implementation of overloaded function.
 
- 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.
 
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< ConflictInfogetFileConflicts (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 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.
 

Private Member Functions

void adaptDirectoryFiles (const std::filesystem::path &path, int mod_id, const std::filesystem::path &target_path) const
 Recursively renames every file in source_path_/mod_id/path to the name of a file in dest_path_, if both match case insensitively.
 
void adaptLoadorderFiles (const std::vector< int > &loadorder, std::optional< ProgressNode * > progress_node={}) const
 Renames every file in every mod in the given load order such that all paths are case invariant and match the case of files in dest_path_.
 

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...
 
- 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 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.
 

Detailed Description

Automatically renames mod files to match the case of target files.

Constructor & Destructor Documentation

◆ CaseMatchingDeployer()

CaseMatchingDeployer::CaseMatchingDeployer ( const std::filesystem::path & source_path,
const std::filesystem::path & dest_path,
const std::string & name,
DeployMode deploy_mode = hard_link )

Passes arguments to base class constructor.

Parameters
source_pathPath to directory containing mods installed using the Installer class.
dest_pathPath to target directory for mod deployment.
nameA custom name for this instance.
deploy_modeDetermines how files are deployed to the target directory.

Member Function Documentation

◆ adaptDirectoryFiles()

void CaseMatchingDeployer::adaptDirectoryFiles ( const std::filesystem::path & path,
int mod_id,
const std::filesystem::path & target_path ) const
private

Recursively renames every file in source_path_/mod_id/path to the name of a file in dest_path_, if both match case insensitively.

Parameters
pathPath relative to the mods root directory.
mod_idId of the mod containing the source files.
target_pathPath used for file comparisons.

◆ adaptLoadorderFiles()

void CaseMatchingDeployer::adaptLoadorderFiles ( const std::vector< int > & loadorder,
std::optional< ProgressNode * > progress_node = {} ) const
private

Renames every file in every mod in the given load order such that all paths are case invariant and match the case of files in dest_path_.

Parameters
loadorderContains ids of mods the files of which will be adapted.
progress_nodeUsed to inform about the current progress of deployment.

◆ deploy() [1/2]

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

Iterates over every file and directory contained in the mods in the given load order. If any name case insensitively matches the name of a file in the target directory, the source is renamed to be identical to the target. Then calls Deployer::deploy(loadorder).

Parameters
loadorderA vector of mod ids representing the load order.
progress_nodeUsed to inform about the current progress of deployment.
Returns
A map from deployed mod ids to their respective mods total size on disk.

Reimplemented from Deployer.

◆ deploy() [2/2]

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

Use base class implementation of overloaded function.

Reimplemented from Deployer.

◆ updateDeployedFilesForMod()

void CaseMatchingDeployer::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.

Parameters
mod_idTarget mod.
progress_nodeUsed to inform about progress.

Reimplemented from Deployer.


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