Skip to content

Commit

Permalink
Rewrite t-extract implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
oblivioncth committed Nov 6, 2023
1 parent ecc6258 commit f6e8c7a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions app/src/task/t-extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ TExtractError TExtract::extractZipSubFolderContentToDir(QString zipFilePath, QSt
QuaZip zipFile(zipFilePath);

// Form subfolder string to match zip content scheme
if(subFolder.isEmpty())
subFolder = '/';

if(subFolder != '/')
if(!subFolder.isEmpty())
{
// Remove leading '/' if present
if(subFolder.front() == '/')
Expand All @@ -81,13 +78,17 @@ TExtractError TExtract::extractZipSubFolderContentToDir(QString zipFilePath, QSt
QuaZipFile currentArchiveFile(&zipFile);
QDir currentDirOnDisk(dir);

// Ensure root destination folder is present
if(!currentDirOnDisk.mkpath(u"."_s))
return TExtractError(zipName, TExtractError::MakePath);

// Extract all files in sub-folder
for(bool atEnd = !zipFile.goToFirstFile(); !atEnd; atEnd = !zipFile.goToNextFile())
{
QString fileName = zipFile.getCurrentFileName();

// Only consider files in specified sub-folder
if(fileName.startsWith(subFolder))
if(subFolder.isEmpty() || fileName.startsWith(subFolder))
{
// Determine path on disk
QString pathWithinFolder = fileName.mid(subFolder.size());
Expand Down
2 changes: 1 addition & 1 deletion app/src/task/t-extract.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class TExtract : public Task
private:
// Data
QString mPackPath;
QString mPathInPack; // NOTE: '/' for root, only supports directories currently.
QString mPathInPack; // NOTE: empty string for root, only supports directories currently.
QString mDestinationPath;

//-Constructor----------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit f6e8c7a

Please sign in to comment.