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

Provides file download functionality with progress tracking. More...

#include <file_download_service.h>

Public Types

using CompletionCallback = std::function<void(const DownloadResult&)>
using ProgressCallback = std::function<void(const DownloadProgress&)>

Static Public Member Functions

static std::string calculateChecksum (const std::string &filePath, const std::string &type)
 Calculate file checksum.
static void cancel ()
 Cancel the current download operation.
static DownloadResult download (const DownloadRequest &request, const ProgressCallback &progressCallback=nullptr)
 Download a file with optional progress tracking.
static void downloadAsync (const DownloadRequest &request, const CompletionCallback &onComplete, const ProgressCallback &onProgress=nullptr)
 Download a file asynchronously.
static std::vector< DownloadResult > downloadBatch (const std::vector< DownloadRequest > &requests, ProgressCallback progressCallback=nullptr)
 Download multiple files sequentially.
static void downloadBatchAsync (const std::vector< DownloadRequest > &requests, const std::function< void(std::vector< DownloadResult >)> &onComplete, const ProgressCallback &onProgress=nullptr)
 Download multiple files asynchronously.
static uint64_t getRemoteFileSize (const std::string &url)
 Get file size from URL without downloading.
static bool isDownloading ()
 Check if a download is currently in progress.
static bool isUrlAccessible (const std::string &url)
 Check if URL is accessible.
static bool verifyChecksum (const std::string &filePath, const std::string &expected, const std::string &type)
 Verify file checksum.

Detailed Description

Provides file download functionality with progress tracking.

Uses curl command-line for downloads, following the existing pattern in the codebase. Supports progress callbacks, resume, and checksums.

Definition at line 77 of file file_download_service.h.

Member Typedef Documentation

◆ CompletionCallback

using FileDownloadService::CompletionCallback = std::function<void(const DownloadResult&)>

Definition at line 81 of file file_download_service.h.

◆ ProgressCallback

using FileDownloadService::ProgressCallback = std::function<void(const DownloadProgress&)>

Definition at line 80 of file file_download_service.h.

Member Function Documentation

◆ calculateChecksum()

std::string FileDownloadService::calculateChecksum ( const std::string & filePath,
const std::string & type )
static

Calculate file checksum.

Parameters
filePathPath to the file
typeChecksum type: "md5" or "sha256"
Returns
Checksum string (lowercase hex) or empty on error

Definition at line 565 of file file_download_service.cpp.

References Logger::error(), and ShellUtils::escapeArg().

Referenced by verifyChecksum().

◆ cancel()

void FileDownloadService::cancel ( )
static

Cancel the current download operation.

Definition at line 530 of file file_download_service.cpp.

References Logger::info().

Referenced by InstallationExecutor::cancel().

◆ download()

◆ downloadAsync()

void FileDownloadService::downloadAsync ( const DownloadRequest & request,
const CompletionCallback & onComplete,
const ProgressCallback & onProgress = nullptr )
static

Download a file asynchronously.

Parameters
requestDownload configuration
onCompleteCalled when download finishes
onProgressCalled periodically with progress updates

Definition at line 493 of file file_download_service.cpp.

References download().

◆ downloadBatch()

std::vector< DownloadResult > FileDownloadService::downloadBatch ( const std::vector< DownloadRequest > & requests,
ProgressCallback progressCallback = nullptr )
static

Download multiple files sequentially.

Parameters
requestsList of download requests
progressCallbackCalled with aggregate progress
Returns
Vector of results (one per request)

Definition at line 427 of file file_download_service.cpp.

References DownloadProgress::bytesDownloaded, DownloadResult::bytesDownloaded, download(), DownloadResult::errorMessage, getRemoteFileSize(), DownloadProgress::percentComplete, DownloadProgress::statusMessage, DownloadResult::success, and DownloadProgress::totalBytes.

Referenced by downloadBatchAsync().

◆ downloadBatchAsync()

void FileDownloadService::downloadBatchAsync ( const std::vector< DownloadRequest > & requests,
const std::function< void(std::vector< DownloadResult >)> & onComplete,
const ProgressCallback & onProgress = nullptr )
static

Download multiple files asynchronously.

Parameters
requestsList of download requests
onCompleteCalled when all downloads finish
onProgressCalled with aggregate progress

Definition at line 509 of file file_download_service.cpp.

References downloadBatch().

◆ getRemoteFileSize()

uint64_t FileDownloadService::getRemoteFileSize ( const std::string & url)
static

Get file size from URL without downloading.

Parameters
urlURL to check
Returns
File size in bytes, or 0 if unknown

Definition at line 625 of file file_download_service.cpp.

References ShellUtils::escapeArg().

Referenced by downloadBatch().

◆ isDownloading()

bool FileDownloadService::isDownloading ( )
static

Check if a download is currently in progress.

Definition at line 536 of file file_download_service.cpp.

◆ isUrlAccessible()

bool FileDownloadService::isUrlAccessible ( const std::string & url)
static

Check if URL is accessible.

Parameters
urlURL to check
Returns
True if URL returns 200 OK

Definition at line 664 of file file_download_service.cpp.

References ShellUtils::escapeArg().

◆ verifyChecksum()

bool FileDownloadService::verifyChecksum ( const std::string & filePath,
const std::string & expected,
const std::string & type )
static

Verify file checksum.

Parameters
filePathPath to the file
expectedExpected checksum value
typeChecksum type: "md5" or "sha256"
Returns
True if checksum matches

Definition at line 545 of file file_download_service.cpp.

References calculateChecksum().

Referenced by download().


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