diff --git a/doomsday/engine/portable/include/file.h b/doomsday/engine/portable/include/file.h index b65fe843fe..d2b40c7608 100644 --- a/doomsday/engine/portable/include/file.h +++ b/doomsday/engine/portable/include/file.h @@ -84,8 +84,14 @@ class File1 /// @return Name of this file. virtual ddstring_t const* name() const; - /// @return Absolute (i.e., resolved but possibly virtual/mapped) path to this file. - ddstring_t const* path() const; + /** + * Compose the absolute VFS path to this file. + * + * @param delimiter Delimit directory using this character. + * + * @return String containing the absolute path. + */ + virtual AutoStr* composePath(char delimiter = '/') const; /// @return @c true iff this file is contained by another. bool isContained() const; @@ -176,19 +182,6 @@ class File1 */ virtual int lumpCount() const { return 1; } - /** - * Compose the absolute VFS path to a lump contained by this file. - * - * @note Always returns a valid string object. If @a lumpIdx is not valid a - * zero-length string is returned. - * - * @param lumpIdx Logical index for the lump. - * @param delimiter Delimit directory separators using this character. - * - * @return String containing the absolute path. - */ - virtual AutoStr* composeLumpPath(int lumpIdx, char delimiter = '/'); - /** * Retrieve a lump contained by this file. * diff --git a/doomsday/engine/portable/include/fs_main.h b/doomsday/engine/portable/include/fs_main.h index 55146f060e..5eaae930ad 100644 --- a/doomsday/engine/portable/include/fs_main.h +++ b/doomsday/engine/portable/include/fs_main.h @@ -420,7 +420,7 @@ boolean F_IsValidLumpNum(lumpnum_t absoluteLumpNum); lumpnum_t F_LumpNumForName(char const* name); -ddstring_t const* F_LumpFilePath(lumpnum_t absoluteLumpNum); +AutoStr* F_ComposeLumpFilePath(lumpnum_t absoluteLumpNum); boolean F_LumpIsCustom(lumpnum_t absoluteLumpNum); @@ -437,7 +437,7 @@ void F_Close(struct filehandle_s* file); void F_Delete(struct filehandle_s* file); -Str const* F_Path(struct file1_s const* file); +AutoStr* F_ComposePath(struct file1_s const* file); void F_SetCustom(struct file1_s* file, boolean yes); diff --git a/doomsday/engine/portable/include/lumpfileadaptor.h b/doomsday/engine/portable/include/lumpfileadaptor.h index ba6bc9c20c..014a963119 100644 --- a/doomsday/engine/portable/include/lumpfileadaptor.h +++ b/doomsday/engine/portable/include/lumpfileadaptor.h @@ -67,6 +67,26 @@ class LumpFileAdaptor : public File1 throw de::Error("LumpFileAdaptor::name", "Unknown de::File1 type"); } + /** + * Compose the absolute VFS path for this file. + * + * @param delimiter Delimit directory using this character. + * + * @return String containing the absolute path. + */ + AutoStr* composePath(char delimiter = '/') + { + if(Wad* wad = dynamic_cast(&container())) + { + return wad->lump(info().lumpIdx).composePath(delimiter); + } + if(Zip* zip = dynamic_cast(&container())) + { + return zip->lump(info().lumpIdx).composePath(delimiter); + } + throw de::Error("LumpFileAdaptor::composePath", "Unknown de::File1 type"); + } + /** * Retrieve the directory node for this file. * @@ -85,19 +105,6 @@ class LumpFileAdaptor : public File1 throw de::Error("LumpFileAdaptor::directoryNode", "Unknown de::File1 type"); } - /** - * Compose the absolute VFS path to a lump contained by this file. - * - * @note Always returns a valid string object. If @a lumpIdx is not valid a - * zero-length string is returned. - * - * @param lumpIdx Logical index for the lump. - * @param delimiter Delimit directory separators using this character. - * - * @return String containing the absolute path. - */ - AutoStr* composeLumpPath(int lumpIdx, char delimiter = '/'); - /** * Read the data associated with lump @a lumpIdx into @a buffer. * diff --git a/doomsday/engine/portable/src/dam_main.c b/doomsday/engine/portable/src/dam_main.c index 26fede637a..d1c46ddfde 100644 --- a/doomsday/engine/portable/src/dam_main.c +++ b/doomsday/engine/portable/src/dam_main.c @@ -256,7 +256,7 @@ boolean DAM_AttemptMapLoad(const Uri* uri) if(0 > markerLump) return false; // Compose the cache directory path and ensure it exists. - cachedMapDir = DAM_ComposeCacheDir(Str_Text(F_LumpFilePath(markerLump))); + cachedMapDir = DAM_ComposeCacheDir(Str_Text(F_ComposeLumpFilePath(markerLump))); F_MakePath(Str_Text(cachedMapDir)); // Compose the full path to the cached map data file. diff --git a/doomsday/engine/portable/src/dd_wad.cpp b/doomsday/engine/portable/src/dd_wad.cpp index 3aab0566c3..c1010a0470 100644 --- a/doomsday/engine/portable/src/dd_wad.cpp +++ b/doomsday/engine/portable/src/dd_wad.cpp @@ -87,7 +87,7 @@ char const* W_LumpSourceFile(lumpnum_t absoluteLumpNum) { lumpnum_t lumpNum = absoluteLumpNum; de::File1 const& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum); - return Str_Text(lump.container().path()); + return Str_Text(lump.container().composePath()); } catch(LumpIndex::NotFoundError const&) { diff --git a/doomsday/engine/portable/src/def_main.cpp b/doomsday/engine/portable/src/def_main.cpp index 13a83f2228..f175008c62 100644 --- a/doomsday/engine/portable/src/def_main.cpp +++ b/doomsday/engine/portable/src/def_main.cpp @@ -778,7 +778,7 @@ void Def_ReadLumpDefs(void) if(!DED_ReadLump(&defs, lump.info().lumpIdx)) { - Con_Error("DD_ReadLumpDefs: Parse error when reading \"%s:DD_DEFNS\".\n", Str_Text(lump.container().path())); + Con_Error("DD_ReadLumpDefs: Parse error when reading \"%s:DD_DEFNS\".\n", Str_Text(lump.container().composePath())); } } diff --git a/doomsday/engine/portable/src/def_read.c b/doomsday/engine/portable/src/def_read.c index 18ab947e72..3aba759cae 100644 --- a/doomsday/engine/portable/src/def_read.c +++ b/doomsday/engine/portable/src/def_read.c @@ -2741,7 +2741,7 @@ int DED_ReadLump(ded_t* ded, lumpnum_t absoluteLumpNum) if(F_LumpLength(absoluteLumpNum) != 0) { uint8_t const* lumpPtr = F_CacheLump(file, lumpIdx); - DED_ReadData(ded, (char const*)lumpPtr, Str_Text(F_Path(file))); + DED_ReadData(ded, (char const*)lumpPtr, Str_Text(F_ComposePath(file))); F_UnlockLump(file, lumpIdx); } return true; diff --git a/doomsday/engine/portable/src/edit_map.c b/doomsday/engine/portable/src/edit_map.c index 2cc04516b0..24e3b9ba05 100644 --- a/doomsday/engine/portable/src/edit_map.c +++ b/doomsday/engine/portable/src/edit_map.c @@ -1724,7 +1724,7 @@ boolean MPE_End(void) { // Yes, write the cached map data file. lumpnum_t markerLumpNum = F_LumpNumForName(Str_Text(Uri_Path(gamemap->uri))); - AutoStr* cachedMapDir = DAM_ComposeCacheDir(Str_Text(F_LumpFilePath(markerLumpNum))); + AutoStr* cachedMapDir = DAM_ComposeCacheDir(Str_Text(F_ComposeLumpFilePath(markerLumpNum))); Str cachedMapPath; Str_InitStd(&cachedMapPath); diff --git a/doomsday/engine/portable/src/file.cpp b/doomsday/engine/portable/src/file.cpp index 932612834a..2d672707cb 100644 --- a/doomsday/engine/portable/src/file.cpp +++ b/doomsday/engine/portable/src/file.cpp @@ -61,7 +61,7 @@ bool File1::isContained() const File1& File1::container() const { - if(!container_) throw NotContainedError("File1::container", QString("%s is not contained").arg(Str_Text(path()))); + if(!container_) throw NotContainedError("File1::container", QString("%s is not contained").arg(Str_Text(composePath()))); return *container_; } @@ -70,9 +70,12 @@ de::FileHandle& File1::handle() return *handle_; } -ddstring_t const* File1::path() const +AutoStr* File1::composePath(char delimiter) const { - return &path_; + AutoStr* path = Str_Copy(AutoStr_NewStd(), &path_); + if(delimiter != '/') + throw de::Error("File1::composePath", "Non '/' delimiter not yet implemented"); + return path; } uint File1::loadOrderIndex() const @@ -113,11 +116,6 @@ ddstring_t const* File1::name() const return name_; } -AutoStr* File1::composeLumpPath(int /*lumpIdx*/, char /*delimiter*/) -{ - return AutoStr_NewStd(); -} - size_t File1::readLump(int /*lumpIdx*/, uint8_t* /*buffer*/, bool /*tryCache*/) { /// @todo writeme diff --git a/doomsday/engine/portable/src/filehandle.cpp b/doomsday/engine/portable/src/filehandle.cpp index 05694f4cee..fbde9433e6 100644 --- a/doomsday/engine/portable/src/filehandle.cpp +++ b/doomsday/engine/portable/src/filehandle.cpp @@ -125,47 +125,46 @@ FileHandle* FileHandleBuilder::fromFileLump(File1& container, int lumpIdx, bool { if(!container.isValidIndex(lumpIdx)) return 0; - de::FileHandle* file = new de::FileHandle(); + de::FileHandle* hndl = new de::FileHandle(); // Init and load in the lump data. - file->d->file = &container.lump(lumpIdx); - file->d->flags.open = true; + File1& file = container.lump(lumpIdx); + hndl->d->file = &file; + hndl->d->flags.open = true; if(!dontBuffer) { - FileInfo const& lumpInfo = container.lump(lumpIdx).info(); - file->d->size = lumpInfo.size; - file->d->pos = file->d->data = (uint8_t*) M_Malloc(file->d->size); - if(!file->d->data) + hndl->d->size = file.size(); + hndl->d->pos = hndl->d->data = (uint8_t*) M_Malloc(hndl->d->size); + if(!hndl->d->data) Con_Error("FileHandleBuilder::fromFileLump: Failed on allocation of %lu bytes for data buffer.", - (unsigned long) file->d->size); + (unsigned long) hndl->d->size); #if _DEBUG VERBOSE2( - AutoStr* path = container.composeLumpPath(lumpIdx); - Con_Printf("FileHandle [%p] buffering \"%s:%s\"...\n", (void*)file, - F_PrettyPath(Str_Text(container.path())), - F_PrettyPath(Str_Text(path))); + Con_Printf("FileHandle [%p] buffering \"%s:%s\"...\n", (void*)hndl, + F_PrettyPath(Str_Text(container.composePath())), + F_PrettyPath(Str_Text(file.composePath()))); ) #endif - container.readLump(lumpIdx, (uint8_t*)file->d->data, 0, lumpInfo.size); + container.readLump(lumpIdx, (uint8_t*)hndl->d->data, 0, file.size()); } - return file; + return hndl; } -FileHandle* FileHandleBuilder::fromFile(File1& af) +FileHandle* FileHandleBuilder::fromFile(File1& file) { - de::FileHandle* file = new de::FileHandle(); - file->d->file = ⁡ - file->d->flags.open = true; - file->d->flags.reference = true; - return file; + de::FileHandle* hndl = new de::FileHandle(); + hndl->d->file = &file; + hndl->d->flags.open = true; + hndl->d->flags.reference = true; + return hndl; } -FileHandle* FileHandleBuilder::fromNativeFile(FILE& hndl, size_t baseOffset) +FileHandle* FileHandleBuilder::fromNativeFile(FILE& file, size_t baseOffset) { - de::FileHandle* file = new de::FileHandle(); - file->d->flags.open = true; - file->d->hndl = &hndl; - file->d->baseOffset = baseOffset; - return file; + de::FileHandle* hndl = new de::FileHandle(); + hndl->d->flags.open = true; + hndl->d->hndl = &file; + hndl->d->baseOffset = baseOffset; + return hndl; } FileHandle* FileHandleBuilder::dup(de::FileHandle const& hndl) diff --git a/doomsday/engine/portable/src/fs_main.cpp b/doomsday/engine/portable/src/fs_main.cpp index f2d300e9cc..110ad2bcee 100644 --- a/doomsday/engine/portable/src/fs_main.cpp +++ b/doomsday/engine/portable/src/fs_main.cpp @@ -189,7 +189,7 @@ struct FS1::Instance FileHandle& hndl = *(loadedFiles[i]); if(!index || index->catalogues(hndl.file())) { - releaseFileId(Str_Text(hndl.file().path())); + releaseFileId(Str_Text(hndl.file().composePath())); self->deindex(hndl.file()); loadedFiles.removeAt(i); self->deleteFile(hndl); @@ -465,7 +465,7 @@ static FS1::FileList::iterator findListFileByPath(FS1::FileList& list, char cons for(i = list.begin(); i != list.end(); ++i) { de::File1& file = (*i)->file(); - if(!Str_CompareIgnoreCase(file.path(), Str_Text(path))) + if(!Str_CompareIgnoreCase(file.composePath(), Str_Text(path))) { break; // This is the node we are looking for. } @@ -532,7 +532,7 @@ bool FS1::unloadFile(char const* path, bool permitRequired, bool quiet) if(lumpNum >= 0) { // Yes; use the container's path instead. - Str_Copy(absolutePath, d->zipLumpIndex.lump(lumpNum).container().path()); + Str_Copy(absolutePath, d->zipLumpIndex.lump(lumpNum).container().composePath()); } for(AbstractResource* const* i = records; *i; i++) @@ -568,7 +568,7 @@ bool FS1::unloadFile(char const* path, bool permitRequired, bool quiet) } FileHandle& hndl = *(*found); - d->releaseFileId(Str_Text(hndl.file().path())); + d->releaseFileId(Str_Text(hndl.file().composePath())); deindex(hndl.file()); d->loadedFiles.erase(found); deleteFile(hndl); @@ -595,7 +595,7 @@ static void printFileList(FS1::FileList& list) { de::FileHandle* hndl = *i; de::File1& file = hndl->file(); - FileId fileId = FileId::fromPath(Str_Text(file.path())); + FileId fileId = FileId::fromPath(Str_Text(file.composePath())); LOG_MSG(" %c%d: %s - \"%s\" (handle: %p)") << (file.hasStartup()? '*' : ' ') << idx << fileId << fileId.path() << (void*)&hndl; @@ -624,7 +624,7 @@ FS1& FS1::unloadAllNonStartupFiles(int* retNumUnloaded) File1& file = hndl.file(); if(file.hasStartup()) continue; - if(unloadFile(Str_Text(file.path()), true/*allow unloading game resources*/, true/*quiet please*/)) + if(unloadFile(Str_Text(file.composePath()), true/*allow unloading game resources*/, true/*quiet please*/)) { numUnloaded += 1; } @@ -976,20 +976,22 @@ int FS1::findAllPaths(char const* rawSearchPattern, int flags, FS1::PathList& fo bool patternMatched; if(!(flags & SPF_NO_DESCEND)) { - filePath = lump.container().composeLumpPath(lump.info().lumpIdx); + filePath = lump.composePath(); patternMatched = F_MatchFileName(Str_Text(filePath), Str_Text(searchPattern)); } else { patternMatched = node.matchDirectory(PCF_MATCH_FULL, &patternMap); - if(patternMatched) - { - filePath = lump.container().composeLumpPath(lump.info().lumpIdx); - } } if(!patternMatched) continue; + // Not yet composed the path? + if(!filePath) + { + filePath = lump.composePath(); + } + found.push_back(PathListItem(Str_Text(filePath), node.type() == PT_BRANCH? A_SUBDIR : 0)); } @@ -1141,7 +1143,7 @@ de::FileHandle& FS1::openFile(char const* path, char const* mode, size_t baseOff de::FileHandle& FS1::openLump(de::File1& lump) { LumpFileAdaptor* adapt = new LumpFileAdaptor(*FileHandleBuilder::fromFileLump(lump.container(), lump.info().lumpIdx, false), - Str_Text(lump.container().composeLumpPath(lump.info().lumpIdx)), + Str_Text(lump.composePath()), lump.info(), &lump.container()); DENG_ASSERT(adapt); @@ -1167,7 +1169,7 @@ de::File1* FS1::addFile(char const* path, size_t baseOffset) // Load the file (a.k.a., index it). File1& file = hndl.file(); - VERBOSE( Con_Message("Loading \"%s\"...\n", F_PrettyPath(Str_Text(file.path()))) ) + VERBOSE( Con_Message("Loading \"%s\"...\n", F_PrettyPath(Str_Text(file.composePath()))) ) index(file); @@ -1475,7 +1477,7 @@ D_CMD(ListFiles) crc = (!file.hasCustom()? wad->calculateCRC() : 0); } - Con_Printf("\"%s\" (%i %s%s)", F_PrettyPath(Str_Text(file.path())), + Con_Printf("\"%s\" (%i %s%s)", F_PrettyPath(Str_Text(file.composePath())), fileCount, fileCount != 1 ? "files" : "file", (file.hasStartup()? ", startup" : "")); if(0 != crc) @@ -1709,11 +1711,10 @@ void F_Delete(struct filehandle_s* hndl) App_FileSystem()->deleteFile(*reinterpret_cast(hndl)); } -ddstring_t const* F_Path(struct file1_s const* file) +AutoStr* F_ComposePath(struct file1_s const* file) { - if(file) return reinterpret_cast(file)->path(); - static de::Str zeroLengthString; - return zeroLengthString; + if(file) return reinterpret_cast(file)->composePath(); + return AutoStr_NewStd(); } void F_SetCustom(struct file1_s* file, boolean yes) @@ -1776,18 +1777,16 @@ struct file1_s* F_FindFileForLumpNum(lumpnum_t absoluteLumpNum) return 0; } -ddstring_t const* F_LumpFilePath(lumpnum_t absoluteLumpNum) +AutoStr* F_ComposeLumpFilePath(lumpnum_t absoluteLumpNum) { try { lumpnum_t lumpNum = absoluteLumpNum; - de::File1 const& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum); - return lump.container().path(); + return App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum).container().composePath(); } catch(LumpIndex::NotFoundError const&) {} // Ignore this error. - static de::Str const zeroLengthString; - return zeroLengthString; + return AutoStr_NewStd(); } boolean F_LumpIsCustom(lumpnum_t absoluteLumpNum) @@ -1806,15 +1805,13 @@ boolean F_LumpIsCustom(lumpnum_t absoluteLumpNum) AutoStr* F_ComposeLumpPath2(struct file1_s* _file, int lumpIdx, char delimiter) { if(!_file) return AutoStr_NewStd(); - de::File1* file = reinterpret_cast(_file); - return file->composeLumpPath(lumpIdx, delimiter); + return reinterpret_cast(_file)->lump(lumpIdx).composePath(delimiter); } AutoStr* F_ComposeLumpPath(struct file1_s* _file, int lumpIdx) { if(!_file) return AutoStr_NewStd(); - de::File1* file = reinterpret_cast(_file); - return file->composeLumpPath(lumpIdx); + return reinterpret_cast(_file)->lump(lumpIdx).composePath(); } /** @@ -1841,35 +1838,33 @@ AutoStr* F_ComposeLumpPath(struct file1_s* _file, int lumpIdx) static ddstring_t* composeFilePathString(FS1::FileList& files, int flags = DEFAULT_PATHTOSTRINGFLAGS, char const* delimiter = " ") { - int maxLength, delimiterLength = (delimiter? (int)strlen(delimiter) : 0); - int n, pLength; - ddstring_t* str, buf; + int delimiterLength = (delimiter? (int)strlen(delimiter) : 0); + int pLength; char const* p, *ext; - Str_Init(&buf); - // Determine the maximum number of characters we'll need. - maxLength = 0; + int maxLength = 0; DENG2_FOR_EACH(i, files, FS1::FileList::const_iterator) { - ddstring_t const* path = (*i)->file().path(); + de::File1& file = (*i)->file(); if(!(flags & (PTSF_TRANSFORM_EXCLUDE_DIR|PTSF_TRANSFORM_EXCLUDE_EXT))) { // Caller wants the whole path plus name and extension (if present). - maxLength += Str_Length(path); + maxLength += Str_Length(file.composePath()); } else { if(flags & PTSF_TRANSFORM_EXCLUDE_DIR) { // Caller does not want the directory hierarchy. - F_FileNameAndExtension(&buf, Str_Text(path)); - p = Str_Text(&buf); - pLength = Str_Length(&buf); + ddstring_t const* name = file.name(); + p = Str_Text(name); + pLength = Str_Length(name); } else { + AutoStr* path = file.composePath(); p = Str_Text(path); pLength = Str_Length(path); } @@ -1901,12 +1896,11 @@ static ddstring_t* composeFilePathString(FS1::FileList& files, int flags = DEFAU maxLength += files.count() * delimiterLength; // Composite final string. - str = Str_New(); - Str_Reserve(str, maxLength); - n = 0; + ddstring_t* str = Str_Reserve(Str_NewStd(), maxLength); + int n = 0; DENG2_FOR_EACH(i, files, FS1::FileList::const_iterator) { - ddstring_t const* path = (*i)->file().path(); + de::File1& file = (*i)->file(); if(flags & PTSF_QUOTED) Str_AppendChar(str, '"'); @@ -1914,19 +1908,20 @@ static ddstring_t* composeFilePathString(FS1::FileList& files, int flags = DEFAU if(!(flags & (PTSF_TRANSFORM_EXCLUDE_DIR|PTSF_TRANSFORM_EXCLUDE_EXT))) { // Caller wants the whole path plus name and extension (if present). - Str_Append(str, Str_Text(path)); + Str_Append(str, Str_Text(file.composePath())); } else { if(flags & PTSF_TRANSFORM_EXCLUDE_DIR) { // Caller does not want the directory hierarchy. - F_FileNameAndExtension(&buf, Str_Text(path)); - p = Str_Text(&buf); - pLength = Str_Length(&buf); + ddstring_t const* name = file.name(); + p = Str_Text(name); + pLength = Str_Length(name); } else { + AutoStr* path = file.composePath(); p = Str_Text(path); pLength = Str_Length(path); } @@ -1961,20 +1956,12 @@ static ddstring_t* composeFilePathString(FS1::FileList& files, int flags = DEFAU Str_Append(str, delimiter); } - Str_Free(&buf); - return str; } static bool findCustomFilesPredicate(de::File1& file, void* /*parameters*/) { - if(file.hasCustom()) - { - ddstring_t const* path = file.path(); - if(stricmp(Str_Text(path) + Str_Length(path) - 3, "lmp")) - return true; // Include this. - } - return false; // Not this. + return file.hasCustom(); } /** diff --git a/doomsday/engine/portable/src/gl_texmanager.c b/doomsday/engine/portable/src/gl_texmanager.c index 442d9e3638..b444e4b47e 100644 --- a/doomsday/engine/portable/src/gl_texmanager.c +++ b/doomsday/engine/portable/src/gl_texmanager.c @@ -1501,7 +1501,7 @@ uint8_t* Image_LoadFromFile(image_t* img, FileHandle* file) GL_InitImage(img); - fileName = Str_Text(F_Path(FileHandle_File_const(file))); + fileName = Str_Text(F_ComposePath(FileHandle_File_const(file))); // Firstly try the expected format given the file name. hdlr = findHandlerFromFileName(fileName); @@ -2485,7 +2485,7 @@ static TexSource loadPatchLump(image_t* image, FileHandle* file, int tclass, int if(source == TEXS_NONE) { - Con_Message("Warning: Lump \"%s\" does not appear to be a valid Patch.\n", F_PrettyPath(Str_Text(F_Path(FileHandle_File(file))))); + Con_Message("Warning: Lump \"%s\" does not appear to be a valid Patch.\n", F_PrettyPath(Str_Text(F_ComposePath(FileHandle_File(file))))); return source; } } diff --git a/doomsday/engine/portable/src/lumpfileadaptor.cpp b/doomsday/engine/portable/src/lumpfileadaptor.cpp index 41931c74ed..ffc6c65c44 100644 --- a/doomsday/engine/portable/src/lumpfileadaptor.cpp +++ b/doomsday/engine/portable/src/lumpfileadaptor.cpp @@ -33,12 +33,6 @@ LumpFileAdaptor::LumpFileAdaptor(FileHandle& hndl, char const* path, LumpFileAdaptor::~LumpFileAdaptor() {} -AutoStr* LumpFileAdaptor::composeLumpPath(int /*lumpIdx*/, char delimiter) -{ - // Lump files are special cases for this *is* the lump. - return container().composeLumpPath(info().lumpIdx, delimiter); -} - size_t LumpFileAdaptor::readLump(int /*lumpIdx*/, uint8_t* buffer, bool tryCache) { // Lump files are special cases for this *is* the lump. diff --git a/doomsday/engine/portable/src/lumpindex.cpp b/doomsday/engine/portable/src/lumpindex.cpp index 7b5880aa5f..47fb8ec0c3 100644 --- a/doomsday/engine/portable/src/lumpindex.cpp +++ b/doomsday/engine/portable/src/lumpindex.cpp @@ -172,7 +172,7 @@ struct LumpIndex::Instance sortInfo.lump = lump; sortInfo.origIndex = i; - sortInfo.path = lump->container().composeLumpPath(lump->info().lumpIdx, '/' /*delimiter is irrelevant*/); + sortInfo.path = lump->composePath(); } qsort(sortInfos, numRecords, sizeof(*sortInfos), lumpSorter); @@ -427,8 +427,8 @@ void LumpIndex::print(LumpIndex const& index) { File1 const& lump = **i; Con_Printf("%0*i - \"%s:%s\" (size: %lu bytes%s)\n", numIndexDigits, idx++, - F_PrettyPath(Str_Text(lump.container().path())), - F_PrettyPath(Str_Text(lump.container().composeLumpPath(lump.info().lumpIdx))), + F_PrettyPath(Str_Text(lump.container().composePath())), + F_PrettyPath(Str_Text(lump.composePath())), (unsigned long) lump.info().size, (lump.info().isCompressed()? " compressed" : "")); } diff --git a/doomsday/engine/portable/src/p_data.cpp b/doomsday/engine/portable/src/p_data.cpp index 74a407d923..bb88b368fd 100644 --- a/doomsday/engine/portable/src/p_data.cpp +++ b/doomsday/engine/portable/src/p_data.cpp @@ -81,7 +81,7 @@ char const* P_GenerateUniqueMapId(char const* mapID) de::File1 const& lump = App_FileSystem()->nameIndexForLump(lumpNum).lump(lumpNum); AutoStr* fileName = AutoStr_NewStd(); - F_FileName(fileName, Str_Text(lump.container().path())); + F_FileName(fileName, Str_Text(lump.container().name())); qsnprintf(uid, 255, "%s|%s|%s|%s", mapID, Str_Text(fileName), (!lump.container().hasCustom()? "iwad" : "pwad"), Str_Text(&reinterpret_cast(App_CurrentGame())->identityKey())); diff --git a/doomsday/engine/portable/src/s_wav.c b/doomsday/engine/portable/src/s_wav.c index 22ee121388..45f18a5719 100644 --- a/doomsday/engine/portable/src/s_wav.c +++ b/doomsday/engine/portable/src/s_wav.c @@ -195,7 +195,7 @@ void* WAV_Load(const char* filename, int* bits, int* rate, int* samples) // Read in the whole thing. size = FileHandle_Length(file); - DEBUG_Message(("WAV_Load: Loading from %s (size %i, fpos %i)\n", Str_Text(F_Path(FileHandle_File_const(file))), + DEBUG_Message(("WAV_Load: Loading from %s (size %i, fpos %i)\n", Str_Text(F_ComposePath(FileHandle_File_const(file))), (int)size, (int)FileHandle_Tell(file))); data = (uint8_t*)malloc(size); diff --git a/doomsday/engine/portable/src/wad.cpp b/doomsday/engine/portable/src/wad.cpp index eede684d0c..28a8888b65 100644 --- a/doomsday/engine/portable/src/wad.cpp +++ b/doomsday/engine/portable/src/wad.cpp @@ -68,6 +68,18 @@ class WadFile : public File1 return directoryNode().pathFragment(); } + /** + * Compose the absolute VFS path to this file. + * + * @param delimiter Delimit directory using this character. + * + * @return String containing the absolute path. + */ + AutoStr* composePath(char delimiter = '/') const + { + return dynamic_cast(container()).composeLumpPath(info_.lumpIdx, delimiter); + } + /** * Retrieve the directory node for this file. * @@ -417,10 +429,10 @@ uint8_t const* Wad::cacheLump(int lumpIdx) if(!isValidIndex(lumpIdx)) throw NotFoundError("Wad::cacheLump", invalidIndexMessage(lumpIdx, lastIndex())); - File1 const& file = lump(lumpIdx); + WadFile const& file = reinterpret_cast(lump(lumpIdx)); LOG_TRACE("\"%s:%s\" (%lu bytes%s)") - << F_PrettyPath(Str_Text(path())) - << F_PrettyPath(Str_Text(composeLumpPath(lumpIdx, '/'))) + << F_PrettyPath(Str_Text(composePath())) + << F_PrettyPath(Str_Text(file.composePath())) << (unsigned long) file.info().size << (file.info().isCompressed()? ", compressed" : ""); @@ -446,7 +458,7 @@ Wad& Wad::unlockLump(int lumpIdx) { LOG_AS("Wad::unlockLump"); LOG_TRACE("\"%s:%s\"") - << F_PrettyPath(Str_Text(path())) << F_PrettyPath(Str_Text(composeLumpPath(lumpIdx, '/'))); + << F_PrettyPath(Str_Text(composePath())) << F_PrettyPath(Str_Text(lump(lumpIdx).composePath())); if(isValidIndex(lumpIdx)) { @@ -481,8 +493,8 @@ size_t Wad::readLump(int lumpIdx, uint8_t* buffer, size_t startOffset, WadFile const& file = reinterpret_cast(lump(lumpIdx)); LOG_TRACE("\"%s:%s\" (%lu bytes%s) [%lu +%lu]") - << F_PrettyPath(Str_Text(path())) - << F_PrettyPath(Str_Text(composeLumpPath(lumpIdx, '/'))) + << F_PrettyPath(Str_Text(composePath())) + << F_PrettyPath(Str_Text(file.composePath())) << (unsigned long) file.size() << (file.isCompressed()? ", compressed" : "") << (unsigned long) startOffset diff --git a/doomsday/engine/portable/src/zip.cpp b/doomsday/engine/portable/src/zip.cpp index 0868814d12..ff6d70714e 100644 --- a/doomsday/engine/portable/src/zip.cpp +++ b/doomsday/engine/portable/src/zip.cpp @@ -151,6 +151,18 @@ class ZipFile : public File1 return directoryNode().pathFragment(); } + /** + * Compose the absolute VFS path to this file. + * + * @param delimiter Delimit directory using this character. + * + * @return String containing the absolute path. + */ + AutoStr* composePath(char delimiter = '/') const + { + return dynamic_cast(container()).composeLumpPath(info_.lumpIdx, delimiter); + } + /** * Retrieve the directory node for this file. * @@ -306,7 +318,7 @@ struct Zip::Instance // Scan the end of the file for the central directory end record. if(!locateCentralDirectory()) - throw FormatError("Zip::readLumpDirectory", QString("Central directory in %1 not found").arg(Str_Text(self->path()))); + throw FormatError("Zip::readLumpDirectory", QString("Central directory in %1 not found").arg(Str_Text(self->composePath()))); // Read the central directory end record. centralend_t summary; @@ -314,7 +326,7 @@ struct Zip::Instance // Does the summary say something we don't like? if(summary.diskEntryCount != summary.totalEntryCount) - throw FormatError("Zip::readLumpDirectory", QString("Multipart zip file \"%1\" not supported").arg(Str_Text(self->path()))); + throw FormatError("Zip::readLumpDirectory", QString("Multipart zip file \"%1\" not supported").arg(Str_Text(self->composePath()))); // We'll load the file directory using one continous read into a temporary // local buffer before we process it into our runtime representation. @@ -373,14 +385,14 @@ struct Zip::Instance { if(pass != 0) continue; LOG_WARNING("Zip %s:'%s' uses an unsupported compression algorithm, ignoring.") - << Str_Text(self->path()) << Str_Text(&entryPath); + << Str_Text(self->composePath()) << Str_Text(&entryPath); } if(USHORT(header->flags) & ZFH_ENCRYPTED) { if(pass != 0) continue; LOG_WARNING("Zip %s:'%s' is encrypted.\n Encryption is not supported, ignoring.") - << Str_Text(self->path()) << Str_Text(&entryPath); + << Str_Text(self->composePath()) << Str_Text(&entryPath); } if(pass == 0) @@ -586,10 +598,10 @@ uint8_t const* Zip::cacheLump(int lumpIdx) if(!isValidIndex(lumpIdx)) throw NotFoundError("Zip::cacheLump", invalidIndexMessage(lumpIdx, lastIndex())); - File1& file = lump(lumpIdx); + ZipFile& file = reinterpret_cast(lump(lumpIdx)); LOG_TRACE("\"%s:%s\" (%lu bytes%s)") - << F_PrettyPath(Str_Text(path())) - << F_PrettyPath(Str_Text(composeLumpPath(lumpIdx, '/'))) + << F_PrettyPath(Str_Text(composePath())) + << F_PrettyPath(Str_Text(file.composePath())) << (unsigned long) file.info().size << (file.info().isCompressed()? ", compressed" : ""); @@ -615,7 +627,7 @@ Zip& Zip::unlockLump(int lumpIdx) { LOG_AS("Zip::unlockLump"); LOG_TRACE("\"%s:%s\"") - << F_PrettyPath(Str_Text(path())) << F_PrettyPath(Str_Text(composeLumpPath(lumpIdx, '/'))); + << F_PrettyPath(Str_Text(composePath())) << F_PrettyPath(Str_Text(lump(lumpIdx).composePath())); if(isValidIndex(lumpIdx)) { @@ -650,8 +662,8 @@ size_t Zip::readLump(int lumpIdx, uint8_t* buffer, size_t startOffset, ZipFile const& file = reinterpret_cast(lump(lumpIdx)); LOG_TRACE("\"%s:%s\" (%lu bytes%s) [%lu +%lu]") - << F_PrettyPath(Str_Text(path())) - << F_PrettyPath(Str_Text(composeLumpPath(lumpIdx, '/'))) + << F_PrettyPath(Str_Text(composePath())) + << F_PrettyPath(Str_Text(file.composePath())) << (unsigned long) file.size() << (file.isCompressed()? ", compressed" : "") << (unsigned long) startOffset