mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-07 08:49:08 +00:00
Fix empty files & directories not being extracted
This commit is contained in:
@@ -50,7 +50,6 @@ Result getExtractedSize(const std::string &archivePath, const std::string &wante
|
|||||||
|
|
||||||
while(archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
while(archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
||||||
int size = archive_entry_size(entry);
|
int size = archive_entry_size(entry);
|
||||||
if (size > 0) { // Ignore folders.
|
|
||||||
std::smatch match;
|
std::smatch match;
|
||||||
std::string entryName(archive_entry_pathname(entry));
|
std::string entryName(archive_entry_pathname(entry));
|
||||||
if (std::regex_search(entryName, match, std::regex(wantedFile))) {
|
if (std::regex_search(entryName, match, std::regex(wantedFile))) {
|
||||||
@@ -58,7 +57,6 @@ Result getExtractedSize(const std::string &archivePath, const std::string &wante
|
|||||||
extractFilesCount++;
|
extractFilesCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
archive_read_close(a);
|
archive_read_close(a);
|
||||||
archive_read_free(a);
|
archive_read_free(a);
|
||||||
@@ -80,14 +78,13 @@ Result extractArchive(const std::string &archivePath, const std::string &wantedF
|
|||||||
}
|
}
|
||||||
|
|
||||||
while(archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
while(archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
||||||
if (archive_entry_size(entry) > 0) { // Ignore folders.
|
|
||||||
std::smatch match;
|
std::smatch match;
|
||||||
std::string entryName(archive_entry_pathname(entry));
|
std::string entryName(archive_entry_pathname(entry));
|
||||||
if (std::regex_search(entryName, match, std::regex(wantedFile))) {
|
if (std::regex_search(entryName, match, std::regex(wantedFile))) {
|
||||||
extractingFile = outputPath + match.suffix().str();
|
extractingFile = outputPath + match.suffix().str();
|
||||||
filesExtracted++;
|
filesExtracted++;
|
||||||
|
|
||||||
/* make directories. */
|
/* Make directories. */
|
||||||
for (char *slashpos = strchr(extractingFile.c_str() + 1, '/'); slashpos != NULL; slashpos = strchr(slashpos + 1, '/')) {
|
for (char *slashpos = strchr(extractingFile.c_str() + 1, '/'); slashpos != NULL; slashpos = strchr(slashpos + 1, '/')) {
|
||||||
char bak = *(slashpos);
|
char bak = *(slashpos);
|
||||||
*(slashpos) = '\0';
|
*(slashpos) = '\0';
|
||||||
@@ -97,6 +94,12 @@ Result extractArchive(const std::string &archivePath, const std::string &wantedF
|
|||||||
*(slashpos) = bak;
|
*(slashpos) = bak;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If directory then mkdir it and skip extraction. */
|
||||||
|
if (S_ISDIR(archive_entry_mode(entry))) {
|
||||||
|
mkdir(extractingFile.c_str(), 0777);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
uint sizeLeft = archive_entry_size(entry);
|
uint sizeLeft = archive_entry_size(entry);
|
||||||
|
|
||||||
FILE *file = fopen(extractingFile.c_str(), "wb");
|
FILE *file = fopen(extractingFile.c_str(), "wb");
|
||||||
@@ -148,7 +151,6 @@ Result extractArchive(const std::string &archivePath, const std::string &wantedF
|
|||||||
if (QueueSystem::CancelCallback) goto exit; // Cancel Extraction.
|
if (QueueSystem::CancelCallback) goto exit; // Cancel Extraction.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
archive_read_close(a);
|
archive_read_close(a);
|
||||||
|
|||||||
Reference in New Issue
Block a user