diff options
Diffstat (limited to 'src/cc4group.c')
| -rw-r--r-- | src/cc4group.c | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/src/cc4group.c b/src/cc4group.c index c1c434a..1fc0584 100644 --- a/src/cc4group.c +++ b/src/cc4group.c @@ -81,6 +81,9 @@ LIST_AUTO(C4GroupEntryData, GroupEntryList) LIST_AUTO(CC4Group_CleanupJob, CleanUpJobList) #define ForeachCleanupJob(list) LIST_FOREACH(CleanUpJobList, list, job) +LIST_AUTO(const CC4Group*, GroupList); +#define ForeachGroup(list) LIST_FOREACH(GroupList, list, group) + typedef char* (*ErrorFormatter)(int32_t const code, const char* const method, const char* const causer, void* const data); typedef struct { @@ -125,6 +128,8 @@ struct CC4Group_t { bool lazy; const char* path; + const char* name; + const char* pathInParent; bool subRooted; }; @@ -1065,6 +1070,8 @@ static bool cc4group_setSubRoot(CC4Group* const this, const char* const subPath) this->realRoot = this->root; this->root = *subRoot; this->subRooted = true; + this->pathInParent = strdup(subPath); + this->name = strdup(subRoot->core.FileName); } return true; @@ -1205,6 +1212,8 @@ static void cc4group_init(CC4Group* const this) this->parent = NULL; this->lazy = true; this->path = NULL; + this->name = NULL; + this->pathInParent = NULL; this->subRooted = false; this->uncompressedData = NULL; @@ -1715,6 +1724,7 @@ static bool cc4group_openExisting(CC4Group* const this, const char* const path) } this->path = cc4group_absolutePath(path); + this->name = cc4group_basename(path); if(cc4group_isDirectory(path)) { @@ -1760,6 +1770,16 @@ static void cc4group_delete(CC4Group* const this) free((void*)this->path); } + if(this->name != NULL) + { + free((void*)this->name); + } + + if(this->pathInParent != NULL) + { + free((void*)this->pathInParent); + } + free(this); } @@ -3281,6 +3301,8 @@ static CC4Group* cc4group_openAsChild(CC4Group* const this, const char* const pa } child->parent = this; + child->name = strdup(entry->core.FileName); + child->pathInParent = strdup(path); ++this->referenceCounter; @@ -3294,6 +3316,52 @@ static bool cc4group_isChild(const CC4Group* const this) return this->parent != NULL; } +static const char* cc4group_getName(const CC4Group* const this) +{ + return this->name; +} + +static char* cc4group_getFullName(const CC4Group* const this) +{ + if(!this->parent && !this->subRooted) + { + return strdup(this->path); + } + + GroupList* groups = GroupListNew(); + + size_t len = 0; + const CC4Group* child = this; + while(child->parent) + { + GroupListPrepend(groups, child); + len += strlen(child->pathInParent) + 1; + child = child->parent; + } + + if(!child->path) + { + GroupListDestroy(groups); + return NULL; + } + len += strlen(child->path) + 1; + + char* result = malloc(sizeof(char) * len); + if(result == NULL) + { + return NULL; + } + strcpy(result, child->path); + + ForeachGroup(groups) + { + strcat(result, "/"); + strcat(result, group->value->pathInParent); + } + + return result; +} + static void* cc4group_memoryManagementTakeStart(void* const data, size_t const size, void* const arg) { (void)size; @@ -3442,5 +3510,8 @@ CC4Group_API cc4group = { .openAsChild = cc4group_openAsChild, - .isChild = cc4group_isChild + .isChild = cc4group_isChild, + + .getName = cc4group_getName, + .getFullName = cc4group_getFullName }; |
