Limo
A simple mod manager
Loading...
Searching...
No Matches
deployer.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "conflictinfo.h"
9#include "filechangechoices.h"
10#include "log.h"
11#include "progressnode.h"
12#include <filesystem>
13#include <map>
14#include <optional>
15#include <unordered_set>
16#include <vector>
17
18
23{
24public:
27 {
33 copy = 2
34 };
35
43 Deployer(const std::filesystem::path& source_path,
44 const std::filesystem::path& dest_path,
45 const std::string& name,
46 DeployMode deploy_mode = hard_link);
47
52 std::string getDestPath() const;
57 std::string getSourcePath() const;
62 std::string getName() const;
67 void setName(const std::string& name);
78 virtual std::map<int, unsigned long> deploy(const std::vector<int>& loadorder,
79 std::optional<ProgressNode*> progress_node = {});
89 virtual std::map<int, unsigned long> deploy(std::optional<ProgressNode*> progress_node = {});
94 virtual void unDeploy(std::optional<ProgressNode*> progress_node = {});
99 void setLoadorder(const std::vector<std::tuple<int, bool>>& loadorder);
104 virtual std::vector<std::tuple<int, bool>> getLoadorder() const;
109 std::string getType() const;
115 virtual void changeLoadorder(int from_index, int to_index);
123 virtual bool addMod(int mod_id, bool enabled = true, bool update_conflicts = true);
129 virtual bool removeMod(int mod_id);
135 virtual void setModStatus(int mod_id, bool status);
141 virtual bool hasMod(int mod_id) const;
149 virtual std::vector<ConflictInfo> getFileConflicts(
150 int mod_id,
151 bool show_disabled = false,
152 std::optional<ProgressNode*> progress_node = {}) const;
157 virtual int getNumMods() const;
162 const std::filesystem::path& destPath() const;
167 void setDestPath(const std::filesystem::path& path);
175 virtual std::unordered_set<int> getModConflicts(int mod_id,
176 std::optional<ProgressNode*> progress_node = {});
181 virtual void addProfile(int source = -1);
186 virtual void removeProfile(int profile);
191 virtual void setProfile(int profile);
196 int getProfile() const;
203 std::pair<int, std::string> verifyDirectories();
210 virtual bool swapMod(int old_id, int new_id);
215 virtual void sortModsByConflicts(std::optional<ProgressNode*> progress_node = {});
220 virtual std::vector<std::vector<int>> getConflictGroups() const;
225 virtual void setConflictGroups(const std::vector<std::vector<int>>& newConflict_groups);
235 virtual void setDeployMode(DeployMode deploy_mode);
237 bool isAutonomous();
243 virtual std::vector<std::string> getModNames() const;
245 std::filesystem::path sourcePath() const;
250 void setSourcePath(const std::filesystem::path& newSourcePath);
255 void setLog(const std::function<void(Log::LogLevel, const std::string&)>& newLog);
260 virtual void cleanup();
265 void updateConflictGroups(std::optional<ProgressNode*> progress_node = {});
267 bool autoUpdateConflictGroups() const;
269 void setAutoUpdateConflictGroups(bool status);
276 std::optional<bool> getModStatus(int mod_id);
282 virtual std::vector<std::vector<std::string>> getAutoTags();
288 virtual std::map<std::string, int> getAutoTagMap();
296 virtual std::vector<std::pair<std::filesystem::path, int>> getExternallyModifiedFiles(
297 std::optional<ProgressNode*> progress_node = {}) const;
307 virtual void keepOrRevertFileModifications(const FileChangeChoices& changes_to_keep);
313 virtual void updateDeployedFilesForMod(int mod_id,
314 std::optional<ProgressNode*> progress_node = {}) const;
316 virtual void fixInvalidLinkDeployMode();
322 virtual int getDeployPriority() const;
327 virtual bool supportsSorting() const;
332 virtual bool supportsReordering() const;
337 virtual bool supportsModConflicts() const;
342 virtual bool supportsFileConflicts() const;
347 virtual bool supportsFileBrowsing() const;
353 virtual bool idsAreSourceReferences() const;
358 virtual std::vector<std::pair<std::string, std::string>> getModActions() const;
363 virtual std::vector<std::vector<int>> getValidModActions() const;
369 virtual void applyModAction(int action, int mod_id);
370
371protected:
373 std::string type_ = "Simple Deployer";
375 std::filesystem::path source_path_;
377 std::filesystem::path dest_path_;
379 const std::string backup_extension_ = ".lmmbak";
381 const std::string deployed_files_name_ = ".lmmfiles";
383 const std::string managed_dir_file_name_ = ".lmm_managed_dir";
385 std::string name_;
389 std::vector<std::vector<std::tuple<int, bool>>> loadorders_;
394 std::vector<std::vector<std::vector<int>>> conflict_groups_;
398 bool is_autonomous_ = false;
401
408 std::pair<std::map<std::filesystem::path, int>, std::map<int, unsigned long>>
409 getDeploymentSourceFilesAndModSizes(const std::vector<int>& loadorder) const;
416 void backupOrRestoreFiles(const std::map<std::filesystem::path, int>& source_files,
417 const std::map<std::filesystem::path, int>& dest_files) const;
423 void deployFiles(const std::map<std::filesystem::path, int>& source_files,
424 std::optional<ProgressNode*> progress_node = {}) const;
432 std::map<std::filesystem::path, int> loadDeployedFiles(
433 std::optional<ProgressNode*> progress_node = {}, std::filesystem::path dest_path = "") const;
439 void saveDeployedFiles(const std::map<std::filesystem::path, int>& deployed_files,
440 std::optional<ProgressNode*> progress_node = {}) const;
448 std::vector<std::string> getModFiles(int mod_id, bool include_directories = false) const;
450 std::function<void(Log::LogLevel, const std::string&)> log_ = [](Log::LogLevel a,
451 const std::string& b) {};
452
457 bool modPathExists(int mod_id) const;
463 bool checkModPathExistsAndMaybeLogError(int mod_id) const;
468 void removeManagedDirFile(const std::filesystem::path& directory) const;
469};
virtual std::vector< std::string > getModNames() const
Autonomous deployers override this tho provide names for their mods. Non Autonomous deployers return ...
Definition deployer.cpp:403
virtual int getDeployPriority() const
Returns the order in which the deploy function of different deployers should be called.
Definition deployer.cpp:882
const std::filesystem::path & destPath() const
Getter for path to deployment target directory.
Definition deployer.cpp:209
virtual void setDeployMode(DeployMode deploy_mode)
Sets the current DeployMode.
Definition deployer.cpp:393
DeployMode getDeployMode() const
Getter for the current DeployMode.
Definition deployer.cpp:388
void setLog(const std::function< void(Log::LogLevel, const std::string &)> &newLog)
Setter for log callback.
Definition deployer.cpp:708
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 overwr...
Definition deployer.cpp:748
void setDestPath(const std::filesystem::path &path)
Setter for path to deployment target directory.
Definition deployer.cpp:214
virtual void cleanup()
Removes all deployed mods from the target directory and deletes the file which stores the state of th...
Definition deployer.cpp:713
void setLoadorder(const std::vector< std::tuple< int, bool > > &loadorder)
Setter for the load order used for deployment.
Definition deployer.cpp:83
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.
Definition deployer.cpp:564
int current_profile_
The currently active profile.
Definition deployer.h:387
virtual void keepOrRevertFileModifications(const FileChangeChoices &changes_to_keep)
Currently only supports hard link deployment. For every given file: Moves the modified file into the ...
Definition deployer.cpp:787
virtual std::vector< std::vector< int > > getValidModActions() const
Returns a vector containing valid mod actions.
Definition deployer.cpp:922
void removeManagedDirFile(const std::filesystem::path &directory) const
Removes a legacy file that is no longer needed and may cause issues.
Definition deployer.cpp:932
std::filesystem::path source_path_
Path to the directory containing all mods which are to be deployed.
Definition deployer.h:375
bool is_autonomous_
Autonomous deployers manage their own mods and do not rely on ModdedApplication.
Definition deployer.h:398
bool auto_update_conflict_groups_
If true: Automatically update conflict groups when necessary.
Definition deployer.h:400
virtual std::vector< std::vector< int > > getConflictGroups() const
Getter for the conflict groups of the current profile.
Definition deployer.cpp:378
int getProfile() const
Getter for the active profile.
Definition deployer.cpp:275
bool checkModPathExistsAndMaybeLogError(int mod_id) const
Checks if the directory containing the given mod exists, if not logs an error.
Definition deployer.cpp:612
const std::string managed_dir_file_name_
Name of the file indicating that the directory is managed by a deployer.
Definition deployer.h:383
virtual bool removeMod(int mod_id)
Removes a mod from the load order.
Definition deployer.cpp:131
virtual void setModStatus(int mod_id, bool status)
Enables or disables the given mod in the load order.
Definition deployer.cpp:144
virtual void applyModAction(int action, int mod_id)
Applies the given mod action to the given mod.
Definition deployer.cpp:930
std::string getName() const
Getter for deployer name.
Definition deployer.cpp:35
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 a...
Definition deployer.cpp:743
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 duri...
Definition deployer.cpp:442
virtual void changeLoadorder(int from_index, int to_index)
Moves a mod from one position in the load order to another.
Definition deployer.cpp:101
virtual bool addMod(int mod_id, bool enabled=true, bool update_conflicts=true)
Appends a new mod to the load order.
Definition deployer.cpp:121
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 ...
Definition deployer.cpp:593
std::pair< int, std::string > verifyDirectories()
Checks if writing to the deployment directory is possible.
Definition deployer.cpp:280
std::string getType() const
Returns the type of this deployer, i.e. SIMPLEDEPLOYER.
Definition deployer.cpp:96
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.
Definition deployer.cpp:219
virtual void addProfile(int source=-1)
Adds a new profile and optionally copies it's load order from an existing profile.
Definition deployer.cpp:246
void updateConflictGroups(std::optional< ProgressNode * > progress_node={})
Updates conflict_groups_ for the current profile.
Definition deployer.cpp:621
std::string getDestPath() const
Getter for path to deployment target directory.
Definition deployer.cpp:25
virtual bool swapMod(int old_id, int new_id)
Replaces the given id in the load order with a new id.
Definition deployer.cpp:346
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 d...
Definition deployer.cpp:45
bool isAutonomous()
Getter for is_autonomous_.
Definition deployer.cpp:398
std::string type_
Type of this deployer, e.g. Simple Deployer.
Definition deployer.h:373
std::string name_
The name of this deployer.
Definition deployer.h:385
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.
Definition deployer.cpp:161
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.
Definition deployer.cpp:827
std::filesystem::path dest_path_
Path to the directory where all mods are deployed to.
Definition deployer.h:377
virtual void fixInvalidLinkDeployMode()
If using hard_link deploy mode and links cannot be created: Switch to sym links.
Definition deployer.cpp:852
const std::string backup_extension_
The file extension appended to backed up files.
Definition deployer.h:379
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 n...
Definition deployer.h:394
std::vector< std::vector< std::tuple< int, bool > > > loadorders_
One load order per profile consisting of tuples of mod ids and their enabled status.
Definition deployer.h:389
bool autoUpdateConflictGroups() const
Getter for auto_update_conflict_groups_.
Definition deployer.cpp:719
std::optional< bool > getModStatus(int mod_id)
Searches the load order for the given mod id and returns the corresponding mods activation status,...
Definition deployer.cpp:729
virtual bool idsAreSourceReferences() const
Returns whether or not this deployer type uses mod ids as references to source mods....
Definition deployer.cpp:912
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.
Definition deployer.cpp:917
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 depl...
Definition deployer.cpp:419
const std::string deployed_files_name_
The file name for a file in the target directory containing names of deployed files.
Definition deployer.h:381
virtual void removeProfile(int profile)
Removes a profile.
Definition deployer.cpp:260
DeployMode
Describes how files should be deployed to the target directory.
Definition deployer.h:27
@ sym_link
Create sym links for files.
Definition deployer.h:31
@ copy
Copy files.
Definition deployer.h:33
@ hard_link
Create hard links for files.
Definition deployer.h:29
void setName(const std::string &name)
Setter for deployer name.
Definition deployer.cpp:40
virtual int getNumMods() const
Returns the number of mods in the load order.
Definition deployer.cpp:204
virtual void setProfile(int profile)
Setter for the active profile.
Definition deployer.cpp:270
virtual void unDeploy(std::optional< ProgressNode * > progress_node={})
Removes all deployed mods from the target directory and restores backups.
Definition deployer.cpp:77
virtual bool hasMod(int mod_id) const
Checks if given mod id is part of the load order.
Definition deployer.cpp:153
std::string getSourcePath() const
Getter for the path to the deployer's source directory.
Definition deployer.cpp:30
virtual std::vector< std::vector< std::string > > getAutoTags()
Getter for auto tags. Only implemented in autonomous deployers.
Definition deployer.cpp:738
virtual void setConflictGroups(const std::vector< std::vector< int > > &newConflict_groups)
Setter for the conflict groups of the current profile.
Definition deployer.cpp:383
virtual void sortModsByConflicts(std::optional< ProgressNode * > progress_node={})
Sorts the load order by grouping mods which contain conflicting files.
Definition deployer.cpp:359
void setAutoUpdateConflictGroups(bool status)
Setter for auto_update_conflict_groups_.
Definition deployer.cpp:724
virtual bool supportsSorting() const
Returns whether or not this deployer type supports sorting mods.
Definition deployer.cpp:887
Deployer(const std::filesystem::path &source_path, const std::filesystem::path &dest_path, const std::string &name, DeployMode deploy_mode=hard_link)
Constructor.
Definition deployer.cpp:18
std::function< void(Log::LogLevel, const std::string &)> log_
Callback for logging.
Definition deployer.h:450
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.
Definition deployer.cpp:492
virtual bool supportsReordering() const
Returns whether or not this deployer type supports reordering mods.
Definition deployer.cpp:892
std::filesystem::path sourcePath() const
Getter for mod source path.
Definition deployer.cpp:408
virtual std::vector< std::tuple< int, bool > > getLoadorder() const
Getter for the current mod load order.
Definition deployer.cpp:88
virtual bool supportsFileBrowsing() const
Returns whether or not this deployer type supports browsing mod files.
Definition deployer.cpp:907
virtual bool supportsModConflicts() const
Returns whether or not this deployer type supports showing mod conflicts.
Definition deployer.cpp:897
DeployMode deploy_mode_
Determines how files should be deployed to the target directory.
Definition deployer.h:396
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.
Definition deployer.cpp:530
bool modPathExists(int mod_id) const
modPathExists Checks if the directory containing the given mod exists.
Definition deployer.cpp:607
virtual bool supportsFileConflicts() const
Returns whether or not this deployer type supports showing file conflicts.
Definition deployer.cpp:902
void setSourcePath(const std::filesystem::path &newSourcePath)
Setter for mod source path.
Definition deployer.cpp:413
Contains the ConflictInfo struct.
Contains the FileChangeChoices struct.
Header for the Log namespace.
char path[256]
Path to which to extract the file.
Definition lspakfilelistentry.h:1
LogLevel
Represents the importance of a log message.
Definition log.h:19
Header for the ProgressNode class.