Limo
A simple mod manager
Loading...
Searching...
No Matches
installer.h
Go to the documentation of this file.
1
5
6#pragma once
7
8#include "log.h"
9#include "progressnode.h"
10#include <filesystem>
11#include <functional>
12#include <map>
13#include <optional>
14#include <vector>
15
16
21{
22public:
24 enum Flag
25 {
26 preserve_case = 0,
27 lower_case = 1 << 0,
28 upper_case = 1 << 1,
29 preserve_directories = 1 << 2,
30 single_directory = 1 << 3
31 };
32
33 inline static const std::vector<std::vector<Flag>> OPTION_GROUPS{
34 { preserve_case, lower_case, upper_case },
35 { preserve_directories, single_directory }
36 };
37
38 inline static const std::map<Flag, std::string> OPTION_NAMES{
39 { preserve_case, "Preserve file names" },
40 { lower_case, "Convert to lower case" },
41 { upper_case, "Convert to upper case" },
42 { preserve_directories, "Preserve directories" },
43 { single_directory, "Root directory only" }
44 };
45
46 inline static const std::map<Flag, std::string> OPTION_DESCRIPTIONS{
47 { preserve_case, "Do not alter file names" },
48 { lower_case, "Convert file and directory names to lower case (FiLe -> file)" },
49 { upper_case, "Convert file and directory names to upper case (FiLe -> FILE)" },
50 { preserve_directories, "Do not alter directory structure" },
51 { single_directory, "Move files from all sub directories to the mods root directory" }
52 };
53
54 inline static const std::string SIMPLEINSTALLER{ "Simple Installer" };
59 inline static const std::string FOMODINSTALLER{ "Fomod Installer" };
63 inline static const std::vector<std::string> INSTALLER_TYPES{ SIMPLEINSTALLER, FOMODINSTALLER };
64
73 static void extract(const std::filesystem::path& source,
74 const std::filesystem::path& destination,
75 std::optional<ProgressNode*> progress_node = {});
87 static unsigned long install(
88 const std::filesystem::path& source,
89 const std::filesystem::path& destination,
90 int options,
91 const std::string& type = SIMPLEINSTALLER,
92 int root_level = 0,
93 const std::vector<std::pair<std::filesystem::path, std::filesystem::path>> fomod_files = {});
99 static void uninstall(const std::filesystem::path& mod_path,
100 const std::string& type = SIMPLEINSTALLER);
106 static std::vector<std::filesystem::path> getArchiveFileNames(const std::filesystem::path& path);
113 static std::tuple<int, std::string, std::string> detectInstallerSignature(
114 const std::filesystem::path& source);
120 static void cleanupFailedInstallation(const std::filesystem::path& staging_dir, int mod_id);
125 static void setIsAFlatpak(bool is_a_flatpak);
127 static inline std::function<void(Log::LogLevel, const std::string&)> log =
128 [](Log::LogLevel a, const std::string& b) {};
129
130private:
132 static inline std::string EXTRACT_TMP_DIR = "lmm_tmp_extract";
134 static inline std::string MOVE_EXTENSION = "tmpmove";
136 static inline bool is_a_flatpak_ = false;
137
142 static void throwCompressionError(struct archive* source);
149 static void copyArchive(struct archive* source, struct archive* dest);
150
158 static void extractWithProgress(const std::filesystem::path& source_path,
159 const std::filesystem::path& dest_path,
160 std::optional<ProgressNode*> progress_node = {});
168 static void extractRarArchive(const std::filesystem::path& source_path,
169 const std::filesystem::path& dest_path);
170};
Holds static functions to install and uninstall mods.
Definition installer.h:21
static void copyArchive(struct archive *source, struct archive *dest)
Copies data from given source archive to given destination archive. Throws CompressionError when an r...
Definition installer.cpp:294
static void cleanupFailedInstallation(const std::filesystem::path &staging_dir, int mod_id)
Deletes all temporary files created during a previous installation attempt.
Definition installer.cpp:263
static const std::string SIMPLEINSTALLER
Simply extracts files.
Definition installer.h:54
static std::vector< std::filesystem::path > getArchiveFileNames(const std::filesystem::path &path)
Recursively reads all file and directory names from given archive.
Definition installer.cpp:212
static const std::map< Flag, std::string > OPTION_NAMES
Maps installer flags to descriptive names.
Definition installer.h:38
static unsigned long install(const std::filesystem::path &source, const std::filesystem::path &destination, int options, const std::string &type=SIMPLEINSTALLER, int root_level=0, const std::vector< std::pair< std::filesystem::path, std::filesystem::path > > fomod_files={})
Extracts the archive, performs any actions specified by the installer type, then copies all files to ...
Definition installer.cpp:61
static void extractRarArchive(const std::filesystem::path &source_path, const std::filesystem::path &dest_path)
Libarchive sometime fails to extract certain rar archives when using the method implemented in extrac...
Definition installer.cpp:424
static std::string EXTRACT_TMP_DIR
Directory name used to temporary storage of files during installation.
Definition installer.h:132
static const std::string FOMODINSTALLER
Takes a vector of files created by fomod::FomodInstaller and moves them to their target.
Definition installer.h:59
static const std::vector< std::vector< Flag > > OPTION_GROUPS
Every vector represents an exclusive group of flags.
Definition installer.h:33
static std::function< void(Log::LogLevel, const std::string &)> log
Callback for logging.
Definition installer.h:127
Flag
Flags used for installation options.
Definition installer.h:25
static void setIsAFlatpak(bool is_a_flatpak)
Sets whether this application is running as a flatpak.
Definition installer.cpp:279
static const std::vector< std::string > INSTALLER_TYPES
Contains all available installer types.
Definition installer.h:63
static void extract(const std::filesystem::path &source, const std::filesystem::path &destination, std::optional< ProgressNode * > progress_node={})
Extracts the given archive to the given directory.
Definition installer.cpp:16
static void uninstall(const std::filesystem::path &mod_path, const std::string &type=SIMPLEINSTALLER)
Uninstalls the mod at given directory using the given installer type.
Definition installer.cpp:207
static std::tuple< int, std::string, std::string > detectInstallerSignature(const std::filesystem::path &source)
Identifies the appropriate installer type from given source archive or directory.
Definition installer.cpp:235
static const std::map< Flag, std::string > OPTION_DESCRIPTIONS
Maps installer flags to brief descriptions of what they do.
Definition installer.h:46
static void throwCompressionError(struct archive *source)
Throws a CompressionError containing the error message of given archive.
Definition installer.cpp:284
static std::string MOVE_EXTENSION
Extension used for temporary storage during file movement.
Definition installer.h:134
static bool is_a_flatpak_
If true: The application is running as a flatpak.
Definition installer.h:136
static void extractWithProgress(const std::filesystem::path &source_path, const std::filesystem::path &dest_path, std::optional< ProgressNode * > progress_node={})
Extracts the given archive to the given directory. Informs about extraction progress using the provid...
Definition installer.cpp:313
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.