QcContentPackLoader Class
Reads content packs from disk (or Qt resources) into a registry. More...
| Header: | #include <common/content/loader/QcContentPackLoader.h> |
Static Public Members
| QStringList | contentFiles(const QString &directory) |
| const char *const | handbookLanguageSuffix |
| bool | isValidPackId(const QString &id) |
| QcResult<QcLoadedPack> | load(const QString &directory, QcContentRegistry ®istry) |
| const qint64 | maxContentFileBytes |
| qint64 | measure(const QString &directory) |
| QVersionNumber | parseVersion(const QString &text) |
| QcResult<QcContentPackInfo> | readManifest(const QString &directory) |
| QcResult<QByteArray> | readPackFile(const QString &path) |
Detailed Description
This is the only place that touches pack files; pack data never gets file-system access of its own.
Member Function Documentation
[static] QStringList QcContentPackLoader::contentFiles(const QString &directory)
Returns the content files load() reads from the pack in directory besides pack.json (the content folders' *.json, textures/*.png, the settings files in worldgen/, weather.json and held.json) that exist, sorted; hidden files and symbolic links are not among them.
[static] bool QcContentPackLoader::isValidPackId(const QString &id)
Returns whether id is a valid pack id: lower-case letters, digits, '_', '-', '.', starting with a letter or digit, at most 64 characters, no "..".
[static] QcResult<QcLoadedPack> QcContentPackLoader::load(const QString &directory, QcContentRegistry ®istry)
Loads the content folders of the pack in directory (shapes/, parts/, materials/, blocks/, items/, recipes/, smelting/, sounds/, textures/, lang/, handbook/, structures/, worldgen/, ...) into registry and returns the pack. Invalid entries are skipped and reported in the warnings; the pack itself only fails when the manifest is unusable. It does not add the pack reference to the registry.
[static] qint64 QcContentPackLoader::measure(const QString &directory)
Returns the bytes that load() would read from the pack in directory, counting every file as at least 256 bytes and at most maxContentFileBytes + 1, so a pack can be rejected before anything is read (hard links make small packs read large).
[static] QVersionNumber QcContentPackLoader::parseVersion(const QString &text)
Returns text as a dotted version, normalized ("1.0.0" == "1"); null when the text is not a plain version (trailing text such as "1.0beta" included).
[static] QcResult<QcContentPackInfo> QcContentPackLoader::readManifest(const QString &directory)
Returns the manifest pack.json in directory, or an error when it cannot be read, its id or version is invalid, a text is too long, or a dependency entry is invalid.
[static] QcResult<QByteArray> QcContentPackLoader::readPackFile(const QString &path)
Returns the bytes of the pack file at path: only regular files (no links, devices or pipes) up to maxContentFileBytes; an error otherwise or when it cannot be opened.
Member Variable Documentation
const char *const QcContentPackLoader::handbookLanguageSuffix
lang/<language><suffix>.json adds to <language> (handbook texts kept apart from names).
const qint64 QcContentPackLoader::maxContentFileBytes
Largest file a pack may contain.