18#include <QStandardPaths>
85 template<
auto f,
typename... Args>
89 bool has_thrown =
false;
92 (this->
apps_[app_id].*f)(std::forward<Args>(args)...);
94 catch(Json::RuntimeError& error)
97 message = error.what();
101 catch(Json::LogicError& error)
105 message = error.what();
112 message = error.what();
116 catch(std::ios_base::failure& error)
119 message = error.what();
126 message = error.what();
130 catch(std::runtime_error& error)
133 message = error.what();
137 catch(std::invalid_argument& error)
140 message = error.what();
147 message =
"An unexpected error occured!";
149 throw std::runtime_error(
"An unexpected error occured!");
153 emit
sendError(
"Error", message.c_str());
166 template<
typename Func,
typename Obj,
typename... Args>
168 -> std::optional<
decltype((obj.*f)(std::forward<Args>(args)...))>
170 decltype((obj.*f)(std::forward<Args>(args)...)) ret_value;
172 bool has_thrown =
false;
175 ret_value = (obj.*f)(std::forward<Args>(args)...);
177 catch(Json::RuntimeError& error)
180 message = error.what();
184 catch(Json::LogicError& error)
188 message = error.what();
195 message = error.what();
199 catch(std::ios_base::failure& error)
202 message = error.what();
209 message = error.what();
213 catch(std::runtime_error& error)
216 message = error.what();
220 catch(std::invalid_argument& error)
223 message = error.what();
230 message =
"An unexpected error occured!";
232 throw std::runtime_error(
"An unexpected error occured!");
237 emit
sendError(
"Error", message.c_str());
244 std::vector<ModdedApplication>
apps_;
290 std::filesystem::path staging_dir,
291 std::filesystem::path dest_dir,
292 const std::string& error_message);
394 QString extracted_path,
395 QString local_source,
396 QString remote_source,
484 void deployModsFor(
int app_id, std::vector<int> deployer_ids);
513 void uninstallMods(
int app_id, std::vector<int> mod_ids, std::string installer_type);
522 void changeLoadorder(
int app_id,
int deployer,
int from_idx,
int to_idx);
547 void setModStatus(
int app_id,
int deployer,
int mod_id,
bool status);
593 void changeModName(
int app_id,
int mod_id, QString new_name);
602 void getFileConflicts(
int app_id,
int deployer,
int mod_id,
bool show_disabled);
706 void createGroup(
int app_id,
int first_mod_id,
int second_mod_id);
743 QString remote_source,
758 QString default_backup,
759 QString first_backup);
776 void addBackup(
int app_id,
int target_id, QString name,
int source);
783 void removeBackup(
int app_id,
int target_id,
int backup_id);
806 void setBackupName(
int app_id,
int target_id,
int backup_id, QString name);
823 void overwriteBackup(
int app_id,
int target_id,
int source_backup,
int dest_backup);
862 void addTagsToMods(
int app_id, QStringList tag_names,
const std::vector<int>& mod_ids);
869 void removeTagsFromMods(
int app_id, QStringList tag_names,
const std::vector<int>& mod_ids);
876 void setTagsForMods(
int app_id, QStringList tag_names,
const std::vector<int>& mod_ids);
882 void editManualTags(
int app_id, std::vector<EditManualTagAction> actions);
888 void editAutoTags(
int app_id, std::vector<EditAutoTagAction> actions);
907 void editModSources(
int app_id,
int mod_id, QString local_source, QString remote_source);
930 void downloadModFile(
int app_id,
int mod_id,
int nexus_file_id, QString mod_url);
1001 void applyModAction(
int app_id,
int deployer,
int action,
int mod_id);
Header for the nexus::Api class.
void addManualTag(int app_id, QString tag_name)
Adds a new tag with the given name to the given ModdedApplication. Fails if a tag by that name alread...
Definition applicationmanager.cpp:731
void extractArchive(int app_id, int mod_id, QString source, QString target, QString remote_source, QString version, QString name)
Extracts the given archive to the given location.
Definition applicationmanager.cpp:628
virtual ~ApplicationManager()
Decreases the static number of instances counter.
Definition applicationmanager.cpp:23
void sendLogMessage(Log::LogLevel log_level, const std::string &message)
Sends a log message to the logging window.
Definition applicationmanager.cpp:33
void getModConflicts(int app_id, int deployer, int mod_id)
Checks for conflicts with other mods for one Deployer of one application. Two mods are conflicting if...
Definition applicationmanager.cpp:529
bool throw_exceptions_
If true: Do not catch exceptions.
Definition applicationmanager.h:246
void getExternalChanges(int app_id, int deployer, bool deploy)
Checks if files deployed by the given app by the given deployer have been externally overwritten.
Definition applicationmanager.cpp:925
void setBackupName(int app_id, int target_id, int backup_id, QString name)
Changes the name of the given backup for the given target for the given ModdedApplication.
Definition applicationmanager.cpp:694
void setActiveBackup(int app_id, int target_id, int backup_id)
Changes the currently active backup for the given target for the given ModdedApplication.
Definition applicationmanager.cpp:681
void addModToIgnoreList(int app_id, int deployer, int mod_id)
Adds the given mod to the ignore list of the given ReverseDeployer.
Definition applicationmanager.cpp:977
void removeBackupTarget(int app_id, int target_id)
Removes the given backup target from the given ModdedApplication by deleting all relevant backups and...
Definition applicationmanager.cpp:660
void deployMods(int app_id)
Deploys mods using all Deployer objects of one application.
Definition applicationmanager.cpp:299
void changeLoadorder(int app_id, int deployer, int from_idx, int to_idx)
Moves a mod from one position in the load order to another for given Deployer for given application.
Definition applicationmanager.cpp:374
void keepOrRevertFileModifications(int app_id, int deployer, const FileChangeChoices &changes_to_keep, bool deploy)
Keeps or reverts external changes for one app for one deployer. For every given file: Moves the modif...
Definition applicationmanager.cpp:940
void scrollLists()
Used to synchronize scrolling in lists with the event queue.
void installMod(int app_id, AddModInfo info)
Installs a new mod for one application using the given Installer type.
Definition applicationmanager.cpp:353
void modInstallationComplete(bool success)
Signals mod installation has been completed.
auto handleExceptions(Func &&f, Obj &&obj, Args &&... args) -> std::optional< decltype((obj.*f)(std::forward< Args >(args)...))>
Wrapper for class member functions. Catches specific exception types and sends an error message to th...
Definition applicationmanager.h:167
void addModToGroup(int app_id, int mod_id, int group)
Adds a mod to an existing group of an application.
Definition applicationmanager.cpp:582
void editApplication(EditApplicationInfo info, int app_id)
Edits an application and optionally moves all of it's mods to a new directory.
Definition applicationmanager.cpp:507
void addDeployer(int app_id, EditDeployerInfo info)
Adds a new Deployer of given type to given application.
Definition applicationmanager.cpp:403
void sortModsByConflicts(int app_id, int deployer)
Sorts the load order by grouping mods which contain conflicting files.
Definition applicationmanager.cpp:621
void addProfile(int app_id, EditProfileInfo info)
Adds a new profile to one application and optionally copies it's load order from an existing profile.
Definition applicationmanager.cpp:547
void updateSettings()
Updates the settings file with the current state of this object.
Definition applicationmanager.cpp:71
void getApplicationNames(bool is_new)
Emits sendApplicationNames.
Definition applicationmanager.cpp:455
void removeManualTag(int app_id, QString tag_name)
Removes the tag with the given name, if it exists, from the given ModdedApplication.
Definition applicationmanager.cpp:737
static int number_of_instances_
Counter for the number of instances of this class.
Definition applicationmanager.h:306
void removeProfile(int app_id, int profile)
Removes a profile from an application.
Definition applicationmanager.cpp:553
void sendProfileNames(QStringList names, bool is_new)
Sends a list of all profile names for one application.
void checkModsForUpdates(int app_id, const std::vector< int > &mod_ids)
Checks for available updates for the given mod for the given app.
Definition applicationmanager.cpp:911
void editDeployer(EditDeployerInfo info, int app_id, int deployer)
Used to set type, name and target directory for one deployer of one application.
Definition applicationmanager.cpp:523
void logMessage(Log::LogLevel log_level, QString message)
Sends a log message to the logging window.
void removeModFromGroup(int app_id, int mod_id)
Removes a mod from it's group for one application.
Definition applicationmanager.cpp:590
void getFileConflicts(int app_id, int deployer, int mod_id, bool show_disabled)
Checks for file conflicts of given mod with all other mods in the load order for one Deployer of one ...
Definition applicationmanager.cpp:473
void sendDeployerNames(QStringList names, bool is_new)
Sends the names of all deployers.
void uninstallGroupMembers(int app_id, const std::vector< int > &mod_ids)
Uninstalls all mods which are inactive group members of any group which contains any of the given mod...
Definition applicationmanager.cpp:724
void removeApplication(int app_id, bool cleanup)
Removes an application and optionally deletes all installed mods and the settings file in the applica...
Definition applicationmanager.cpp:289
void changeActiveGroupMember(int app_id, int group, int mod_id)
Changes the active member of given group of an application to given mod.
Definition applicationmanager.cpp:606
void enableExceptions(bool enabled)
Enable or disable throwing exceptions.
Definition applicationmanager.cpp:66
void updateProgress(float progress)
Informs about the progress in the current task.
void checkForModUpdates(int app_id)
Checks for available mod updates on NexusMods.
Definition applicationmanager.cpp:904
void getNexusPage(int app_id, int mod_id)
Fetches data for the given mod from NexusMods.
Definition applicationmanager.cpp:826
void createGroup(int app_id, int first_mod_id, int second_mod_id)
Creates a new group containing the two given mods for one application. A group is a set of mods where...
Definition applicationmanager.cpp:598
void downloadModFile(int app_id, int mod_id, int nexus_file_id, QString mod_url)
Downloads the file with the given id for the given mod url from nexusmods.
Definition applicationmanager.cpp:874
void changeModName(int app_id, int mod_id, QString new_name)
Setter for a mod name.
Definition applicationmanager.cpp:467
bool handleExceptions(int app_id, Args &&... args)
Wrapper for member functions of ModdedApplication. Calls the function specified in the template for t...
Definition applicationmanager.h:86
void reapplyAutoTags(int app_id)
Reapplies all auto tags for all mods for the given ModdedApplication.
Definition applicationmanager.cpp:802
void init()
If a JSON file with settings already exists for this user: Restores the internal state from that file...
Definition applicationmanager.cpp:28
bool appIndexIsValid(int app_id, bool show_error=true)
Checks if given app_id is part of apps_ and optionally emits an error signal.
Definition applicationmanager.cpp:158
void extractionComplete(int app_id, int mod_id, bool success, QString extracted_path, QString local_source, QString remote_source, QString version, QString name)
Emitted after archive extraction is complete.
void setBackupTargetName(int app_id, int target_id, QString name)
Changes the name of the given backup target for the given ModdedApplication.
Definition applicationmanager.cpp:701
void getBackupTargets(int app_id)
Returns a vector containing information about all managed backup targets of given ModdedApplication....
Definition applicationmanager.cpp:688
void addBackup(int app_id, int target_id, QString name, int source)
Adds a new backup for the given target for the given ModdedApplication by copying the currently activ...
Definition applicationmanager.cpp:667
void addTagsToMods(int app_id, QStringList tag_names, const std::vector< int > &mod_ids)
Adds the given tag to all given mods for the given ModdedApplication.
Definition applicationmanager.cpp:750
void sendModInfo(std::vector< ModInfo > mod_info)
Sends ModInfo for one application.
void addTool(int app_id, Tool tool)
Adds a new tool to given application.
Definition applicationmanager.cpp:495
void unDeployMods(int app_id)
Undeploys mods using all Deployer objects of one application.
Definition applicationmanager.cpp:339
void downloadMod(int app_id, QString nxm_url)
Downloads a mod from nexusmods using the given nxm_url.
Definition applicationmanager.cpp:837
void sendFileConflicts(std::vector< ConflictInfo > conflicts)
Sends file conflicts for one mod for one deployer of one application.
void getProfileNames(int app_id, bool is_new)
Creates a vector containing the names of all profiles of one application. Emits sendProfileNames.
Definition applicationmanager.cpp:559
void completedOperations(QString message="")
Emitted after potentially slow operations, e.g. installing a mod, are completed.
void applyModAction(int app_id, int deployer, int action, int mod_id)
Applies the given mod action to the given mod.
Definition applicationmanager.cpp:983
void onScrollLists()
Used to synchronize scrolling in lists with the event queue.
Definition applicationmanager.cpp:719
void overwriteBackup(int app_id, int target_id, int source_backup, int dest_backup)
Deletes all files in the dest backup and replaces them with the files from the source backup for the ...
Definition applicationmanager.cpp:708
void sendLoadorder(std::vector< std::tuple< int, bool > > loadorder)
Sends the load order for one deployer of one application.
void sendNexusPage(int app_id, int mod_id, nexus::Page page)
Sends NexusMods data for a specific mod.
void getDeployerNames(int app_id, bool is_new)
Creates a vector containing the names of all Deployer objects for one application....
Definition applicationmanager.cpp:416
void getDeployerInfo(int app_id, int deployer)
Creates DeployerInfo for one Deployer for one application. Emits sendDeployerInfo.
Definition applicationmanager.cpp:441
void sendUpdateProgress(float progress)
Informs about the progress in the current task by emitting updateProgress.
Definition applicationmanager.cpp:219
void removeModFromDeployer(int app_id, int deployer, int mod_id)
Removes a mod from the load order for given Deployer for given application.
Definition applicationmanager.cpp:389
void exportAppConfiguration(int app_id, std::vector< int > deployers, QStringList auto_tags)
Exports configurations for the given deployers and the given auto tags to a json file....
Definition applicationmanager.cpp:958
void editTool(int app_id, int tool_id, Tool new_tool)
Used to replace an existing to with a now one for a application.
Definition applicationmanager.cpp:576
void sendExternalChangesInfo(int app_id, ExternalChangesInfo info, int num_deployers, bool deploy)
Sends data about externally modified files for one app for one deployer.
void downloadComplete(int app_id, int mod_id, QString file_path, QString mod_url)
Signals successful completion of a mod download.
void sendError(QString title, QString message)
Sends an error message.
ApplicationManager(QObject *parent=nullptr)
Constructor. Only one instance of this class is support at a time.
Definition applicationmanager.cpp:14
void setTagsForMods(int app_id, QStringList tag_names, const std::vector< int > &mod_ids)
Sets the tags for all given mods to the given tags for the given ModdedApplication.
Definition applicationmanager.cpp:776
void removeBackup(int app_id, int target_id, int backup_id)
Deletes the given backup for given target for given ModdedApplication.
Definition applicationmanager.cpp:674
void removeTool(int app_id, int tool_id)
Removes a tool from given application.
Definition applicationmanager.cpp:501
void deployModsFor(int app_id, std::vector< int > deployer_ids)
Deploys mods for given deployers and given application.
Definition applicationmanager.cpp:315
void removeDeployer(int app_id, int deployer, bool cleanup)
Removes a Deployer from an application.
Definition applicationmanager.cpp:410
void editManualTags(int app_id, std::vector< EditManualTagAction > actions)
Performes the given tag editing actions for the given ModdedApplication.
Definition applicationmanager.cpp:789
std::vector< ModdedApplication > apps_
Contains every ModdedApplication handled by this object.
Definition applicationmanager.h:244
void sendModConflicts(std::unordered_set< int > conflicts)
Sends mod conflicts for one mod for one deployer of one application.
void updateAutoTags(int app_id, std::vector< int > mod_ids)
Reapplies all auto tags to the given mods for the given ModdedApplication.
Definition applicationmanager.cpp:809
void unDeployModsFor(int app_id, std::vector< int > deployer_ids)
Undeploys mods for given deployers and given application.
Definition applicationmanager.cpp:346
int getNumApplications() const
Returns the number of managed \ModdedApplication "applications".
Definition applicationmanager.cpp:54
void handleParseError(std::string path, std::string message)
Emits an error message indicating a parsing error using sendError.
Definition applicationmanager.cpp:209
void updateState()
Updates the internal state of this object to the state stored in the settings file.
Definition applicationmanager.cpp:83
void handleAddDeployerError(int code, std::filesystem::path staging_dir, std::filesystem::path dest_dir, const std::string &error_message)
If the code indicates an error: Create an error message and emit it using sendError.
Definition applicationmanager.cpp:187
void changeModVersion(int app_id, int mod_id, QString new_version)
Sets the given mod's version to the given new version for one application.
Definition applicationmanager.cpp:614
void addApplication(EditApplicationInfo info)
Adds a new application.
Definition applicationmanager.cpp:229
void addBackupTarget(int app_id, QString path, QString name, QString default_backup, QString first_backup)
Adds a new target file or directory to be managed by the BackupManager of given ModdedApplication.
Definition applicationmanager.cpp:643
void getModInfo(int app_id)
Creates a vector containing information about all installed mods, stored in ModInfo objects for one a...
Definition applicationmanager.cpp:427
void sendDeployerInfo(DeployerInfo depl_info)
Sends DeployerInfo for one deployer of one application.
void suppressUpdateNotification(int app_id, const std::vector< int > &mod_ids)
Temporarily disables update notifications for the given mods.
Definition applicationmanager.cpp:918
void removeTagsFromMods(int app_id, QStringList tag_names, const std::vector< int > &mod_ids)
Removes the given tag from the given mods for the given ModdedApplication.
Definition applicationmanager.cpp:763
void sendApplicationNames(QStringList names, QStringList icon_paths, bool is_new)
Sends a list containing all application names.
void setModStatus(int app_id, int deployer, int mod_id, bool status)
Enables or disables the given mod in the load order for given Deployer for given application.
Definition applicationmanager.cpp:397
void editModSources(int app_id, int mod_id, QString local_source, QString remote_source)
Sets a mods local and remote source to the given values for the given ModdedApplication.
Definition applicationmanager.cpp:816
void handleAddAppError(int code, std::filesystem::path staging_dir)
If the code indicates an error: Create an error message and emit it using sendError.
Definition applicationmanager.cpp:176
int getNumProfiles(int app_id) const
Returns the number of profiles for one application.
Definition applicationmanager.cpp:59
bool deployerIndexIsValid(int app_id, int deployer, bool show_error=true)
Checks if given deployer id is valid for given app and optionally emits an error signal.
Definition applicationmanager.cpp:167
void sendBackupTargets(std::vector< BackupTarget > targets)
Sends a vector containing info about all backup targets managed by given ModdedApplication.
void editProfile(int app_id, int profile, EditProfileInfo info)
Used to set the name of a profile for one application.
Definition applicationmanager.cpp:570
void changeManualTagName(int app_id, QString old_name, QString new_name)
Changes the name of the given tag to the given new name for the given ModdedApplication....
Definition applicationmanager.cpp:743
void updateIgnoredFiles(int app_id, int deployer)
Updates the file ignore list for ReverseDeployers.
Definition applicationmanager.cpp:970
void downloadFailed()
Signals a failed download.
void setProfile(int app_id, int profile)
Sets the currently active profile for given application.
Definition applicationmanager.cpp:541
void updateModDeployers(int app_id, std::vector< int > mod_ids, std::vector< bool >)
Updates which deployer should manage given mods.
Definition applicationmanager.cpp:380
std::string toString() const
Generates a string which contains the ids and names of every application as well as their profiles.
Definition applicationmanager.cpp:38
void externalChangesHandled(int app_id, int deployer, int num_deployers, bool deploy)
Signals that external changes to files for given app for given deployer have been handled.
void uninstallMods(int app_id, std::vector< int > mod_ids, std::string installer_type)
Uninstalls the given mods for one application, this includes deleting all installed files.
Definition applicationmanager.cpp:365
void sendAppInfo(AppInfo app_info)
Sends AppInfo for one application.
void getAppInfo(int app_id)
Creates AppInfo for given application. Emits sendAppInfo.
Definition applicationmanager.cpp:485
void editAutoTags(int app_id, std::vector< EditAutoTagAction > actions)
Performes the given tag editing actions for the given ModdedApplication.
Definition applicationmanager.cpp:795
Exception used for errors during archive extraction.
Definition compressionerror.h:13
Exception indicating an error while parsing a JSON file.
Definition parseerror.h:15
Contains the CompressionError class.
Contains the EditApplicationInfo struct.
Header for the EditAutoTagAction class.
Header for the EditManualTagAction class.
Header for the Log namespace.
char path[256]
Path to which to extract the file.
Definition lspakfilelistentry.h:1
Header for the ModdedApplication class.
LogLevel
Represents the importance of a log message.
Definition log.h:19
Contains the ParseError class.
Stores data needed to install a new mod.
Definition addmodinfo.h:17
Stores information about a ModdedApplication.
Definition appinfo.h:20
Stores a deployer's installed mods and load order.
Definition deployerinfo.h:17
Stores data needed to either create a new or edit an existing application.
Definition editapplicationinfo.h:19
Stores data needed to either create a new or edit an existing deployer.
Definition editdeployerinfo.h:17
Stores data needed to either create a new or edit an existing profile of a application.
Definition editprofileinfo.h:16
Contains data regarding externally modified files for one deployer.
Definition externalchangesinfo.h:18
Contains data regarding which external file changes to keep.
Definition filechangechoices.h:16
Contains all data for a mod available through the NexusMods api.
Definition api.h:23