ZRef<ZStreamerRPos> ZAssetRep_FS::OpenRPos() { if (fData) return new StreamerMemory(this, fData, fDataSize); if (fComps.empty()) return fSpec.OpenRPos(); string leaf = fComps.back(); if (leaf == "!binary" || leaf == "!string" || leaf == "!stringtable") { ZFileSpec branchSpec = fSpec.Trail(ZTrail(fComps.begin(), fComps.end() - 1)); if (branchSpec.IsFile()) { // And the branch is a file, so we pretend that our specially named leaf exists. return branchSpec.OpenRPos(); } } return fSpec.Trail(ZTrail(fComps.begin(), fComps.end())).OpenRPos(); }
ZRef<ZAssetRep> ZAssetRep_FS::ResolvePath(const char* iPath) { const char* pathStart = iPath; if (pathStart == nullptr || pathStart[0] == 0) { // An empty path means us. return this; } vector<string> newComps; if (pathStart[0] == '|') { // A | prefix means we want our root, which is fSpec with an empty component vector. ++pathStart; } else { newComps = fComps; } const char* iter = pathStart; for (;;) { switch (*iter) { case 0: case '^': case '|': { if (iter > pathStart) newComps.push_back(string(pathStart, iter - pathStart)); pathStart = iter + 1; if (*iter == '^') { if (newComps.empty()) { // We're trying to get the parent of the root, // which is an illegal asset reference. return ZRef<ZAssetRep>(); } newComps.pop_back(); } } } if (*iter == 0) break; ++iter; } if (newComps.empty()) { if (fSpec.Exists()) return new ZAssetRep_FS(fSpec); return ZRef<ZAssetRep>(); } ZFileSpec branchSpec = fSpec.Trail(ZTrail(newComps.begin(), newComps.end() - 1)); if (!branchSpec.Exists()) { // The branch doesn't exist, so neither can the full path. return ZRef<ZAssetRep>(); } // We know the branch exists. string leaf = newComps.back(); if (leaf == "!binary" || leaf == "!string" || leaf == "!stringtable") { // We've got a leaf with a special name. if (branchSpec.IsFile()) { // And the branch is a file, so we pretend that our specially named leaf exists. return new ZAssetRep_FS(fSpec, newComps); } } if (fSpec.Trail(ZTrail(newComps.begin(), newComps.end())).Exists()) { // Our spec plus the new components is an extant entity. return new ZAssetRep_FS(fSpec, newComps); } return ZRef<ZAssetRep>(); }