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

Holds static functions to install and uninstall mods. More...

#include <installer.h>

Public Types

enum  Flag {
  preserve_case = 0 , lower_case = 1 << 0 , upper_case = 1 << 1 , preserve_directories = 1 << 2 ,
  single_directory = 1 << 3
}
 Flags used for installation options.
 

Static Public Member Functions

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.
 
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 given destination.
 
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.
 
static std::vector< std::filesystem::path > getArchiveFileNames (const std::filesystem::path &path)
 Recursively reads all file and directory names from given archive.
 
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.
 
static void cleanupFailedInstallation (const std::filesystem::path &staging_dir, int mod_id)
 Deletes all temporary files created during a previous installation attempt.
 
static void setIsAFlatpak (bool is_a_flatpak)
 Sets whether this application is running as a flatpak.
 

Static Public Attributes

static const std::vector< std::vector< Flag > > OPTION_GROUPS
 Every vector represents an exclusive group of flags.
 
static const std::map< Flag, std::string > OPTION_NAMES
 Maps installer flags to descriptive names.
 
static const std::map< Flag, std::string > OPTION_DESCRIPTIONS
 Maps installer flags to brief descriptions of what they do.
 
static const std::string SIMPLEINSTALLER { "Simple Installer" }
 Simply extracts files.
 
static const std::string FOMODINSTALLER { "Fomod Installer" }
 Takes a vector of files created by fomod::FomodInstaller and moves them to their target.
 
static const std::vector< std::string > INSTALLER_TYPES { SIMPLEINSTALLER, FOMODINSTALLER }
 Contains all available installer types.
 
static std::function< void(Log::LogLevel, const std::string &)> log
 Callback for logging.
 

Static Private Member Functions

static void throwCompressionError (struct archive *source)
 Throws a CompressionError containing the error message of given archive.
 
static void copyArchive (struct archive *source, struct archive *dest)
 Copies data from given source archive to given destination archive. Throws CompressionError when an reading or writing fails.
 
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 provided node.
 
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 extractWithProgress. This function uses libunrar instead of libarchive to extract a given rar archive.
 

Static Private Attributes

static std::string EXTRACT_TMP_DIR = "lmm_tmp_extract"
 Directory name used to temporary storage of files during installation.
 
static std::string MOVE_EXTENSION = "tmpmove"
 Extension used for temporary storage during file movement.
 
static bool is_a_flatpak_ = false
 If true: The application is running as a flatpak.
 

Detailed Description

Holds static functions to install and uninstall mods.

Member Function Documentation

◆ cleanupFailedInstallation()

void Installer::cleanupFailedInstallation ( const std::filesystem::path & staging_dir,
int mod_id )
static

Deletes all temporary files created during a previous installation attempt.

Parameters
staging_dirDirectory containing temporary files.
mod_idId of the mod whose installation failed.

◆ copyArchive()

void Installer::copyArchive ( struct archive * source,
struct archive * dest )
staticprivate

Copies data from given source archive to given destination archive. Throws CompressionError when an reading or writing fails.

Parameters
sourceSource archive.
destDestination archive.

◆ detectInstallerSignature()

std::tuple< int, std::string, std::string > Installer::detectInstallerSignature ( const std::filesystem::path & source)
static

Identifies the appropriate installer type from given source archive or directory.

Parameters
sourcePath to mod source.
Returns
Required root level and type of the installer.

◆ extract()

void Installer::extract ( const std::filesystem::path & source,
const std::filesystem::path & destination,
std::optional< ProgressNode * > progress_node = {} )
static

Extracts the given archive to the given directory.

Parameters
sourcePath to the archive.
destinationDestination directory for extraction.
progress_nodeUsed to inform about extraction progress.
Returns
Int indicating success(0), a filesystem error(-2) or an error during extraction(-1).

◆ extractRarArchive()

void Installer::extractRarArchive ( const std::filesystem::path & source_path,
const std::filesystem::path & dest_path )
staticprivate

Libarchive sometime fails to extract certain rar archives when using the method implemented in extractWithProgress. This function uses libunrar instead of libarchive to extract a given rar archive.

Parameters
source_pathPath to the archive.
dest_pathDestination directory for extraction.

◆ extractWithProgress()

void Installer::extractWithProgress ( const std::filesystem::path & source_path,
const std::filesystem::path & dest_path,
std::optional< ProgressNode * > progress_node = {} )
staticprivate

Extracts the given archive to the given directory. Informs about extraction progress using the provided node.

Parameters
source_pathPath to the archive.
dest_pathDestination directory for extraction.
progress_nodeUsed to inform about extraction progress.

◆ getArchiveFileNames()

std::vector< sfs::path > Installer::getArchiveFileNames ( const std::filesystem::path & path)
static

Recursively reads all file and directory names from given archive.

Parameters
pathPath to given archive.
Returns
Vector of paths within the archive.

◆ install()

unsigned long Installer::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 = {} )
static

Extracts the archive, performs any actions specified by the installer type, then copies all files to given destination.

Parameters
pathPath to the archive.
destinationDestination directory for the installation.
optionsSum of installation flags
installerInstaller type to use.
root_levelIf > 0: Ignore all mod files and path components with depth < root_level.
Returns
The total file size of the installed mod on disk.

◆ setIsAFlatpak()

void Installer::setIsAFlatpak ( bool is_a_flatpak)
static

Sets whether this application is running as a flatpak.

Parameters
is_a_flatpakIf true: The application is running as a flatpak.

◆ throwCompressionError()

void Installer::throwCompressionError ( struct archive * source)
staticprivate

Throws a CompressionError containing the error message of given archive.

Parameters
sourceArchive containing the error message.

◆ uninstall()

void Installer::uninstall ( const std::filesystem::path & mod_path,
const std::string & type = SIMPLEINSTALLER )
static

Uninstalls the mod at given directory using the given installer type.

Parameters
pathPath to the mod.
installerInstaller type to use.

Member Data Documentation

◆ log

std::function<void(Log::LogLevel, const std::string&)> Installer::log
inlinestatic
Initial value:
=
[](Log::LogLevel a, const std::string& b) {}
LogLevel
Represents the importance of a log message.
Definition log.h:19

Callback for logging.

◆ OPTION_DESCRIPTIONS

const std::map<Flag, std::string> Installer::OPTION_DESCRIPTIONS
inlinestatic
Initial value:
{
{ preserve_case, "Do not alter file names" },
{ lower_case, "Convert file and directory names to lower case (FiLe -> file)" },
{ upper_case, "Convert file and directory names to upper case (FiLe -> FILE)" },
{ preserve_directories, "Do not alter directory structure" },
{ single_directory, "Move files from all sub directories to the mods root directory" }
}

Maps installer flags to brief descriptions of what they do.

◆ OPTION_GROUPS

const std::vector<std::vector<Flag> > Installer::OPTION_GROUPS
inlinestatic
Initial value:
{
{ preserve_case, lower_case, upper_case },
{ preserve_directories, single_directory }
}

Every vector represents an exclusive group of flags.

◆ OPTION_NAMES

const std::map<Flag, std::string> Installer::OPTION_NAMES
inlinestatic
Initial value:
{
{ preserve_case, "Preserve file names" },
{ lower_case, "Convert to lower case" },
{ upper_case, "Convert to upper case" },
{ preserve_directories, "Preserve directories" },
{ single_directory, "Root directory only" }
}

Maps installer flags to descriptive names.


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