From 327b9ad4985a1939826746c98b44957dd4ca59ce Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Thu, 2 Apr 2020 02:59:52 +0200 Subject: Add cc4group.extractSingleRename --- src/cc4group.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src/cc4group.c') diff --git a/src/cc4group.c b/src/cc4group.c index 92dd784..c3454f8 100644 --- a/src/cc4group.c +++ b/src/cc4group.c @@ -1783,7 +1783,7 @@ static bool cc4group_extractEntry(CC4Group* const this, const C4GroupEntryData* return success; } -static bool cc4group_extractChildren(CC4Group* const this, const C4GroupEntryData* const root, const char* const targetPath) +static bool cc4group_extractChildren(CC4Group* const this, const C4GroupEntryData* const root, const char* const targetPath, bool const rename) { assert(root); @@ -1797,11 +1797,14 @@ static bool cc4group_extractChildren(CC4Group* const this, const C4GroupEntryDat } strcpy(tmpPath, targetPath); - if(*targetPath != '\0') + if(!rename) { - strcat(tmpPath, "/"); + if(*targetPath != '\0') + { + strcat(tmpPath, "/"); + } + strcat(tmpPath, root->core.FileName); } - strcat(tmpPath, root->core.FileName); bool success = true; @@ -1823,7 +1826,7 @@ static bool cc4group_extractChildren(CC4Group* const this, const C4GroupEntryDat ForeachGroupEntry(children) { - if(!cc4group_extractChildren(this, &entry->value, tmpPath)) + if(!cc4group_extractChildren(this, &entry->value, tmpPath, false)) { success = false; goto ret; @@ -1854,7 +1857,7 @@ static bool cc4group_extractAll(CC4Group* const this, const char* const targetPa { assert(this); - return cc4group_extractChildren(this, &this->root, targetPath); + return cc4group_extractChildren(this, &this->root, targetPath, false); } @@ -2017,7 +2020,21 @@ static bool cc4group_extractSingle(CC4Group* const this, const char* const entry return false; } - return cc4group_extractChildren(this, entry, targetPath); + return cc4group_extractChildren(this, entry, targetPath, false); +} + +static bool cc4group_extractSingleRename(CC4Group* const this, const char* const entryPath, const char* const targetPath) +{ + assert(this); + assert(targetPath); + + const C4GroupEntryData* entry = cc4group_getFileOrDirectoryByPath(this, entryPath, true, NULL); + if(entry == NULL) + { + return false; + } + + return cc4group_extractChildren(this, entry, targetPath, true); } static void* cc4group_mmappedFileManagementStart(void* const data, size_t const size, void* const arg) @@ -3327,6 +3344,7 @@ CC4Group_API cc4group = { .extractAll = cc4group_extractAll, .extractSingle = cc4group_extractSingle, + .extractSingleRename = cc4group_extractSingleRename, .getEntryInfo = cc4group_getEntryInfo, -- cgit v1.2.3-54-g00ecf