Limo
A simple mod manager
Loading...
Searching...
No Matches
fomodinstaller.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "installstep.h"
9#include <algorithm>
10#include <filesystem>
11#include <pugixml.hpp>
12#include <ranges>
13#include <vector>
14
15
20namespace fomod
21{
26{
27public:
29 FomodInstaller() = default;
30
36 void init(const std::filesystem::path& config_file,
37 const std::filesystem::path& target_path = "",
38 const std::string& app_version = "");
44 std::optional<InstallStep> step(const std::vector<std::vector<bool>>& selection = {});
50 std::optional<std::pair<std::vector<std::vector<bool>>, InstallStep>> stepBack();
56 bool hasNextStep(const std::vector<std::vector<bool>>& selection) const;
62 std::vector<std::pair<std::filesystem::path, std::filesystem::path>> getInstallationFiles(
63 const std::vector<std::vector<bool>>& selection = {});
68 bool hasPreviousStep() const;
73 bool hasNoSteps() const;
79 static std::pair<std::string, std::string> getMetaData(const std::filesystem::path& path);
80
81private:
83 pugi::xml_document config_file_;
85 pugi::xml_node config_;
87 std::filesystem::path target_path_;
89 std::vector<File> files_;
91 std::vector<InstallStep> steps_;
93 int cur_step_ = -1;
95 std::map<std::string, std::string> flags_;
97 std::filesystem::path mod_base_path_;
99 std::vector<std::vector<std::vector<bool>>> prev_selections_;
101 std::function<bool(std::string)> version_eval_fun_ = [](auto s) { return true; };
103 std::function<bool(std::string)> fomm_eval_fun_ = [](auto s) { return true; };
104
111 void parseFileList(const pugi::xml_node& file_list,
112 std::vector<File>& target_vector,
113 bool warn_missing = true);
118 void parseInstallSteps(const pugi::xml_node& steps);
124 PluginGroup::Type parseGroupType(const std::string& type);
126 void parseInstallList();
132 void initPlugin(const pugi::xml_node& xml_node, Plugin& plugin);
138 PluginType parsePluginType(const std::string& type);
143 void updateState(const std::vector<std::vector<bool>>& selection);
150 static std::pair<std::string, std::string> getFomodPath(
151 const std::filesystem::path& source,
152 const std::string& file_name = "ModuleConfig.xml");
158 template<typename T>
159 void sortVector(std::vector<T>& source, std::string order)
160 {
161 if(order == "Explicit")
162 return;
163 else if(order == "Descending")
164 std::ranges::sort(source, [](auto a, auto b) { return a.name > b.name; });
165 else
166 std::ranges::sort(source, [](auto a, auto b) { return a.name < b.name; });
167 }
168};
169}
PluginGroup::Type parseGroupType(const std::string &type)
Determines group type from given string.
Definition fomodinstaller.cpp:229
bool hasNoSteps() const
Checks if installation has not steps.
Definition fomodinstaller.cpp:132
int cur_step_
Current installation step.
Definition fomodinstaller.h:93
void updateState(const std::vector< std::vector< bool > > &selection)
Updates flags_ and files_ with selection.
Definition fomodinstaller.cpp:324
pugi::xml_document config_file_
Source fomod config file.
Definition fomodinstaller.h:83
bool hasNextStep(const std::vector< std::vector< bool > > &selection) const
Checks if there is at least one more valid installation step.
Definition fomodinstaller.cpp:99
bool hasPreviousStep() const
Checks if there is a previous installation step.
Definition fomodinstaller.cpp:161
std::vector< std::vector< std::vector< bool > > > prev_selections_
Previous selections made during installation process.
Definition fomodinstaller.h:99
void parseFileList(const pugi::xml_node &file_list, std::vector< File > &target_vector, bool warn_missing=true)
Extracts all files from given file list node and appends them to given vector.
Definition fomodinstaller.cpp:166
PluginType parsePluginType(const std::string &type)
Determines plugin type from given string.
Definition fomodinstaller.cpp:311
FomodInstaller()=default
Default constructor.
std::filesystem::path target_path_
Path used to check for file dependencies.
Definition fomodinstaller.h:87
void init(const std::filesystem::path &config_file, const std::filesystem::path &target_path="", const std::string &app_version="")
Initializes the installer.
Definition fomodinstaller.cpp:14
std::vector< InstallStep > steps_
Steps performed during installation.
Definition fomodinstaller.h:91
void initPlugin(const pugi::xml_node &xml_node, Plugin &plugin)
Initializes given plugin plugin from fomod node.
Definition fomodinstaller.cpp:271
std::vector< File > files_
Contains all files extracted from the config file.
Definition fomodinstaller.h:89
std::function< bool(std::string)> version_eval_fun_
Used to evaluate game version conditions.
Definition fomodinstaller.h:101
static std::pair< std::string, std::string > getMetaData(const std::filesystem::path &path)
Extracts mod name and version from a fomod info file in path/fomod/info.xml.
Definition fomodinstaller.cpp:137
std::map< std::string, std::string > flags_
Maps flags to their value.
Definition fomodinstaller.h:95
pugi::xml_node config_
Root node of the config file.
Definition fomodinstaller.h:85
void sortVector(std::vector< T > &source, std::string order)
Sorts given vector according to given ordering type.
Definition fomodinstaller.h:159
void parseInstallList()
Updates files_ according to the fomod files conditionalFileInstalls node.
Definition fomodinstaller.cpp:242
std::filesystem::path mod_base_path_
Base path of the mod to be installed.
Definition fomodinstaller.h:97
std::function< bool(std::string)> fomm_eval_fun_
Used to evaluate fomm version conditions.
Definition fomodinstaller.h:103
std::vector< std::pair< std::filesystem::path, std::filesystem::path > > getInstallationFiles(const std::vector< std::vector< bool > > &selection={})
Returns all files to be installed with current selection.
Definition fomodinstaller.cpp:145
std::optional< InstallStep > step(const std::vector< std::vector< bool > > &selection={})
Advances installation process by one step.
Definition fomodinstaller.cpp:47
void parseInstallSteps(const pugi::xml_node &steps)
Extracts all install steps from given node and stores them in steps_.
Definition fomodinstaller.cpp:201
static std::pair< std::string, std::string > getFomodPath(const std::filesystem::path &source, const std::string &file_name="ModuleConfig.xml")
Tries to find fomod/file_name in the given path.
Definition fomodinstaller.cpp:358
std::optional< std::pair< std::vector< std::vector< bool > >, InstallStep > > stepBack()
Returns a pair of the previous installation step and the selections made at that step.
Definition fomodinstaller.cpp:68
Header for the InstallStep struct.
char path[256]
Path to which to extract the file.
Definition lspakfilelistentry.h:1
The fomod namespace contains classes used for parsing a FOMOD xml file and for creating an installer.
Definition dependency.h:22
PluginType
Describes how a plugin is presented.
Definition plugintype.h:20
A step during installation.
Definition installstep.h:21
Type
Describes restriction on how plugins in a group can be selected.
Definition plugingroup.h:24
Represents one selectable option during installation.
Definition plugin.h:24