game_launcher 1.1.0
Modern Linux game launcher with Steam / Proton / Wine integration
Loading...
Searching...
No Matches
ArchiveExtractService Class Reference

Provides archive extraction using system tools. More...

#include <archive_extract_service.h>

Public Types

using ProgressCallback = std::function<void(int percent, const std::string& currentFile)>

Static Public Member Functions

static ArchiveType detectType (const std::string &filePath)
 Detect archive type from file.
static ExtractResult extract (const ExtractRequest &request, const ProgressCallback &progressCallback=nullptr)
 Extract an archive.
static void extractAsync (const ExtractRequest &request, const std::function< void(const ExtractResult &)> &onComplete, const ProgressCallback &onProgress=nullptr)
 Extract an archive asynchronously.
static ArchiveInfo getInfo (const std::string &archivePath)
 Get archive information without extracting.
static std::string getInstallCommand (const std::string &toolName)
 Get installation command for a tool.
static std::string getToolName (ArchiveType type)
 Get the command-line tool used for a type.
static std::string getTypeName (ArchiveType type)
 Get human-readable name for archive type.
static bool isSupported (ArchiveType type)
 Check if extraction for a type is supported.
static bool isToolInstalled (const std::string &toolName)
 Check if a tool is installed.
static std::vector< std::string > listContents (const std::string &archivePath)
 List archive contents without extracting.

Detailed Description

Provides archive extraction using system tools.

Uses external command-line tools for extraction:

  • tar: .tar, .tar.gz, .tar.bz2, .tar.xz, .tar.zst
  • unzip: .zip
  • 7z: .7z, .rar, and many other formats
  • innoextract: InnoSetup .exe installers
  • cabextract: .cab files

Falls back gracefully if tools are not installed.

Definition at line 105 of file archive_extract_service.h.

Member Typedef Documentation

◆ ProgressCallback

using ArchiveExtractService::ProgressCallback = std::function<void(int percent, const std::string& currentFile)>

Definition at line 108 of file archive_extract_service.h.

Member Function Documentation

◆ detectType()

ArchiveType ArchiveExtractService::detectType ( const std::string & filePath)
static

Detect archive type from file.

Parameters
filePathPath to the archive
Returns
Detected archive type

Definition at line 188 of file archive_extract_service.cpp.

References Unknown.

Referenced by extract(), getInfo(), and listContents().

◆ extract()

ExtractResult ArchiveExtractService::extract ( const ExtractRequest & request,
const ProgressCallback & progressCallback = nullptr )
static

Extract an archive.

Parameters
requestExtraction configuration
progressCallbackCalled with extraction progress (if available)
Returns
Result of the extraction

Definition at line 50 of file archive_extract_service.cpp.

References ExtractRequest::archivePath, Bzip2, Cab, ExtractRequest::destinationDir, ExtractResult::destinationDir, detectType(), Logger::error(), ExtractResult::errorMessage, getInstallCommand(), getToolName(), getTypeName(), Gzip, Logger::info(), InnoSetup, isSupported(), NSIS, Rar, SevenZip, Tar, TarBz2, TarGz, TarXz, TarZst, ExtractRequest::type, Unknown, Xz, and Zip.

Referenced by extractAsync().

◆ extractAsync()

void ArchiveExtractService::extractAsync ( const ExtractRequest & request,
const std::function< void(const ExtractResult &)> & onComplete,
const ProgressCallback & onProgress = nullptr )
static

Extract an archive asynchronously.

Parameters
requestExtraction configuration
onCompleteCalled when extraction finishes
onProgressCalled with extraction progress

Definition at line 169 of file archive_extract_service.cpp.

References extract().

◆ getInfo()

ArchiveInfo ArchiveExtractService::getInfo ( const std::string & archivePath)
static

Get archive information without extracting.

Parameters
archivePathPath to the archive
Returns
Archive information

Definition at line 427 of file archive_extract_service.cpp.

References ArchiveInfo::compressedSize, ArchiveInfo::contents, detectType(), ArchiveInfo::fileCount, getTypeName(), listContents(), ArchiveInfo::type, and ArchiveInfo::typeName.

◆ getInstallCommand()

std::string ArchiveExtractService::getInstallCommand ( const std::string & toolName)
static

Get installation command for a tool.

Parameters
toolNameTool name
Returns
Package manager command to install (or empty if unknown)

Definition at line 631 of file archive_extract_service.cpp.

Referenced by extract().

◆ getToolName()

std::string ArchiveExtractService::getToolName ( ArchiveType type)
static

Get the command-line tool used for a type.

Parameters
typeArchive type
Returns
Tool name (e.g., "tar", "unzip", "7z")

Definition at line 587 of file archive_extract_service.cpp.

References Bzip2, Cab, Exe, Gzip, InnoSetup, NSIS, Rar, SevenZip, Tar, TarBz2, TarGz, TarXz, TarZst, Xz, and Zip.

Referenced by extract(), and isSupported().

◆ getTypeName()

std::string ArchiveExtractService::getTypeName ( ArchiveType type)
static

Get human-readable name for archive type.

Parameters
typeArchive type enum
Returns
Type name string

Definition at line 384 of file archive_extract_service.cpp.

References Bzip2, Cab, Exe, Gzip, InnoSetup, NSIS, Rar, SevenZip, Tar, TarBz2, TarGz, TarXz, TarZst, Xz, and Zip.

Referenced by extract(), and getInfo().

◆ isSupported()

bool ArchiveExtractService::isSupported ( ArchiveType type)
static

Check if extraction for a type is supported.

Parameters
typeArchive type
Returns
True if the required tool is installed

Definition at line 500 of file archive_extract_service.cpp.

References getToolName(), and isToolInstalled().

Referenced by extract().

◆ isToolInstalled()

bool ArchiveExtractService::isToolInstalled ( const std::string & toolName)
static

Check if a tool is installed.

Parameters
toolNameTool name (e.g., "7z", "innoextract")
Returns
True if tool is available in PATH

Definition at line 619 of file archive_extract_service.cpp.

References ShellUtils::escapeArg().

Referenced by isSupported().

◆ listContents()

std::vector< std::string > ArchiveExtractService::listContents ( const std::string & archivePath)
static

List archive contents without extracting.

Parameters
archivePathPath to the archive
Returns
List of file paths in the archive

Definition at line 445 of file archive_extract_service.cpp.

References Cab, detectType(), ShellUtils::escapeArg(), InnoSetup, Rar, SevenZip, Tar, TarBz2, TarGz, TarXz, TarZst, and Zip.

Referenced by getInfo().


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