diff options
| author | Markus Mittendrein <git@maxmitti.tk> | 2018-08-15 22:46:40 +0200 |
|---|---|---|
| committer | Markus Mittendrein <git@maxmitti.tk> | 2018-08-15 23:15:15 +0200 |
| commit | 0d1ae015fef8e15442dafa61b9c8d929ce467969 (patch) | |
| tree | a8d56fd12f5c5366e1f6fa3ecc20c78c0202f747 /src/cc4group.h | |
| parent | e04f662a42c75cb202684e7254d3b7600e6e1756 (diff) | |
| download | cc4group-0d1ae015fef8e15442dafa61b9c8d929ce467969.tar.gz cc4group-0d1ae015fef8e15442dafa61b9c8d929ce467969.zip | |
Refactor code into a library and implement basic file management methods
Diffstat (limited to 'src/cc4group.h')
| -rw-r--r-- | src/cc4group.h | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/cc4group.h b/src/cc4group.h new file mode 100644 index 0000000..ef3a55d --- /dev/null +++ b/src/cc4group.h @@ -0,0 +1,97 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#define this this_ +#define new new_ +#define delete delete_ +#endif + +#include <stddef.h> +#include <stdint.h> +#include <stdbool.h> + +typedef struct { + const char* fileName; + int32_t modified; + const char* author; + size_t size; + size_t totalSize; + bool executable; + bool directory; + bool official; +} CC4Group_EntryInfo; + +typedef struct CC4Group_t CC4Group; + +typedef void(*CC4Group_CleanupFunc)(void* data); +typedef struct { + CC4Group_CleanupFunc func; + void* data; +} CC4Group_CleanupJob; +typedef void* (*CC4Group_TmpMemoryStrategy)(CC4Group* const this, const size_t size, CC4Group_CleanupJob* cleanupJob); + +typedef struct { + CC4Group* (*new)(void); + bool (*create)(CC4Group* const this); + void (*delete)(CC4Group* const this); + + // only open an existing group on a frehsly created group object + bool (*openExisting)(CC4Group* const this, const char* const path); + + bool (*save)(CC4Group* const this, const char* const path); + bool (*saveOverwrite)(CC4Group* const this, const char* const path); + + // extraction to disk + bool (*extractAll)(CC4Group* const this, const char* const targetPath); + bool (*extractSingle)(CC4Group* const this, const char* const entryPath, const char* const targetPath); + + // the group owns the data pointed to. the pointer is valid until the group destructor is called + bool (*getEntryData)(const CC4Group* const this, const char* const entryPath, const void** const data, size_t* const size); + + // the returned error message pointer is valid until the next call to getErrorMessage is issued or the group is destructed + const char* (*getErrorMessage)(CC4Group* const this); + + int32_t (*getErrorCode)(const CC4Group* const this); + + const char* (*getErrorMethod)(const CC4Group* const this); + const char* (*getErrorCauser)(const CC4Group* const this); + + struct { + CC4Group_TmpMemoryStrategy Memory; + CC4Group_TmpMemoryStrategy File; + CC4Group_TmpMemoryStrategy Auto; + } const TmpMemoryStrategies; + + void (*setTmpMemoryStrategy)(const CC4Group_TmpMemoryStrategy strategy); + + // group metadata handling + bool (*setMaker)(CC4Group* const this, const char* const maker, const char* const path, bool const recursive); + bool (*setCreation)(CC4Group* const this, int32_t const creation, const char* const path, bool const recursive); + bool (*setOfficial)(CC4Group* const this, bool const official, const char* const path, bool const recursive); + bool (*setExecutable)(CC4Group* const this, bool const executable, const char* const path); + + bool (*getEntryInfo)(CC4Group* const this, const char* const path, CC4Group_EntryInfo* const info); + bool (*getEntryInfos)(CC4Group* const this, const char* const path, CC4Group_EntryInfo** const infos, size_t* const size); + + // modifying the group + bool (*deleteEntry)(CC4Group* const this, const char* const path, bool const recursive); + bool (*renameEntry)(CC4Group* const this, const char* const oldPath, const char* const newPath); + bool (*createDirectory)(CC4Group* const this, const char* const path); + + // ownership of the data is taken by the group + bool (*createFile)(CC4Group* const this, const char* const path, void* const data, size_t const size); + // ownership of the data is taken by the group + bool (*setEntryData)(const CC4Group* const this, const char* const entryPath, void* const data, size_t const size); +} const CC4Group_API; + +#ifndef CC4GROUP_DYNAMIC_LOAD +extern CC4Group_API cc4group; +#endif + +#ifdef __cplusplus +} +#undef this +#undef new +#undef delete +#endif |
