Skip to content

Commit

Permalink
Refactor|FS1: Further streamlined the public interface of FS1
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Oct 18, 2012
1 parent 19b0ddb commit a2d96e3
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 127 deletions.
12 changes: 12 additions & 0 deletions doomsday/engine/portable/include/file.h
Expand Up @@ -48,6 +48,7 @@ typedef enum {

#ifdef __cplusplus

#include <de/Error>
#include <de/str.h>
#include "filehandle.h"
#include "fileinfo.h"
Expand Down Expand Up @@ -187,6 +188,17 @@ class File1
*/
virtual int lumpCount() { return 1; }

/**
* Retrieve the name of a lump contained by this file.
*
* @param lumpIdx Logical index for the lump in this file's directory.
*
* @return Name for this lump.
*
* @throws de::Error If @a lumpIdx is not valid.
*/
virtual ddstring_t const* lumpName(int lumpIdx);

/**
* Retrieve the directory node for a lump contained by this file.
*
Expand Down
37 changes: 3 additions & 34 deletions doomsday/engine/portable/include/fs_main.h
Expand Up @@ -180,60 +180,29 @@ namespace de

lumpnum_t lumpNumForName(char const* name, bool silent = true);

/**
* Given a logical @a lumpnum retrieve the associated file object.
*
* @post The active LumpIndex may have changed!
*
* @param absoluteLumpNum Logical lumpnum associated to the file being looked up.
* @return Name of the specified lump.
*
* @throws NotFoundError If the requested file could not be found.
*/
ddstring_t const* lumpName(lumpnum_t absoluteLumpNum);

/**
* Given a logical @a lumpnum retrieve the associated file object.
*
* @post The active LumpIndex may have changed!
*
* @param absoluteLumpNum Logical lumpnum associated to the file being looked up.
* @param lumpIdx If not @c NULL the translated lumpnum within the owning
* file object is written here.
*
* @return Found file object.
*
* @throws NotFoundError If the requested file could not be found.
*/
File1& lumpFile(lumpnum_t absoluteLumpNum, int* lumpIdx = 0);

/**
* Retrieve the FileInfo metadata record for a lump in the Wad lump index.
*
* @post The active LumpIndex may have changed!
*
* @param absoluteLumpNum Logical lumpnum associated to the file being looked up.
* @param lumpIdx If not @c NULL the translated lumpnum within the owning
* file object is written here.
*
* @return Metadata record for the lump.
*
* @throws NotFoundError If the requested file could not be found.
*/
FileInfo const& lumpInfo(lumpnum_t absoluteLumpNum, int* lumpIdx = 0);
FileInfo const& lumpInfo(lumpnum_t absoluteLumpNum);

/**
* Retrieve the FileInfo metadata record for a lump in the Zip lump index.
*
* @param path Path to search for (made absolute if necessary).
* @param lumpIdx If not @c NULL the translated lumpnum within the owning
* file object is written here.
*
* @return Metadata record for the lump.
*
* @throws NotFoundError If the requested file could not be found.
*/
FileInfo const& zipFileInfo(char const* path, int* lumpIdx = 0);
FileInfo const& zipFileInfo(char const* path);

/**
* Opens the given file (will be translated) for reading.
Expand Down Expand Up @@ -433,7 +402,7 @@ boolean F_IsValidLumpNum(lumpnum_t absoluteLumpNum);

lumpnum_t F_LumpNumForName(char const* name);

ddstring_t const* F_LumpFileAdaptorPath(lumpnum_t absoluteLumpNum);
ddstring_t const* F_LumpFilePath(lumpnum_t absoluteLumpNum);

boolean F_LumpIsCustom(lumpnum_t absoluteLumpNum);

Expand Down
11 changes: 10 additions & 1 deletion doomsday/engine/portable/include/lumpfileadaptor.h
Expand Up @@ -51,14 +51,23 @@ class LumpFileAdaptor : public File1
~LumpFileAdaptor();

/**
* Retrieve the directory node for a lump contained by this file.
* Retrieve the directory node for this lump in the container file.
*
* @param lumpIdx Ignored. Required argument.
*
* @return Directory node for this lump.
*/
PathDirectoryNode const& lumpDirectoryNode(int lumpIdx);

/**
* Retrieve the name of this lump.
*
* @param lumpIdx Ignored. Required argument.
*
* @return Name for this lump.
*/
ddstring_t const* lumpName(int lumpIdx);

/**
* Compose the absolute VFS path to a lump contained by this file.
*
Expand Down
11 changes: 11 additions & 0 deletions doomsday/engine/portable/include/wad.h
Expand Up @@ -77,6 +77,17 @@ class Wad : public File1
*/
PathDirectoryNode& lumpDirectoryNode(int lumpIdx);

/**
* Retrieve the name of a lump contained by this file.
*
* @param lumpIdx Logical index for the lump in this file's directory.
*
* @return Name for this lump.
*
* @throws NotFoundError If @a lumpIdx is not valid.
*/
ddstring_t const* lumpName(int lumpIdx);

/**
* Compose the absolute VFS path to a lump contained by this file.
*
Expand Down
11 changes: 11 additions & 0 deletions doomsday/engine/portable/include/zip.h
Expand Up @@ -79,6 +79,17 @@ class Zip : public File1
*/
PathDirectoryNode& lumpDirectoryNode(int lumpIdx);

/**
* Retrieve the name of a lump contained by this file.
*
* @param lumpIdx Logical index for the lump in this file's directory.
*
* @return Name for this lump.
*
* @throws NotFoundError If @a lumpIdx is not valid.
*/
ddstring_t const* lumpName(int lumpIdx);

/**
* Compose the absolute VFS path to a lump contained by this file.
*
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/dam_main.c
Expand Up @@ -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_LumpFileAdaptorPath(markerLump)));
cachedMapDir = DAM_ComposeCacheDir(Str_Text(F_LumpFilePath(markerLump)));
F_MakePath(Str_Text(cachedMapDir));

// Compose the full path to the cached map data file.
Expand Down
42 changes: 27 additions & 15 deletions doomsday/engine/portable/src/dd_wad.cpp
Expand Up @@ -55,7 +55,10 @@ char const* W_LumpName(lumpnum_t absoluteLumpNum)
{
try
{
return Str_Text(App_FileSystem()->lumpName(absoluteLumpNum));
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
return Str_Text(file.lumpName(info.lumpIdx));
}
catch(FS1::NotFoundError const&)
{
Expand All @@ -81,7 +84,9 @@ char const* W_LumpSourceFile(lumpnum_t absoluteLumpNum)
{
try
{
de::File1& file = App_FileSystem()->lumpFile(absoluteLumpNum);
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
return Str_Text(file.path());
}
catch(FS1::NotFoundError const&)
Expand All @@ -95,7 +100,10 @@ boolean W_LumpIsCustom(lumpnum_t absoluteLumpNum)
{
try
{
return App_FileSystem()->lumpFile(absoluteLumpNum).hasCustom();
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
return file.hasCustom();
}
catch(FS1::NotFoundError const&)
{
Expand Down Expand Up @@ -138,9 +146,10 @@ size_t W_ReadLump(lumpnum_t absoluteLumpNum, uint8_t* buffer)
{
try
{
int lumpIdx;
de::File1& file = App_FileSystem()->lumpFile(absoluteLumpNum, &lumpIdx);
return file.readLump(lumpIdx, buffer, 0, App_FileSystem()->lumpInfo(absoluteLumpNum).size);
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
return file.readLump(info.lumpIdx, buffer, 0, info.size);
}
catch(FS1::NotFoundError const&)
{
Expand All @@ -153,9 +162,10 @@ size_t W_ReadLumpSection(lumpnum_t absoluteLumpNum, uint8_t* buffer, size_t star
{
try
{
int lumpIdx;
de::File1& file = App_FileSystem()->lumpFile(absoluteLumpNum, &lumpIdx);
return file.readLump(lumpIdx, buffer, startOffset, length);
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
return file.readLump(info.lumpIdx, buffer, startOffset, length);
}
catch(FS1::NotFoundError const&)
{
Expand All @@ -168,9 +178,10 @@ uint8_t const* W_CacheLump(lumpnum_t absoluteLumpNum)
{
try
{
int lumpIdx;
de::File1& file = App_FileSystem()->lumpFile(absoluteLumpNum, &lumpIdx);
return file.cacheLump(lumpIdx);
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
return file.cacheLump(info.lumpIdx);
}
catch(FS1::NotFoundError const&)
{
Expand All @@ -183,9 +194,10 @@ void W_UnlockLump(lumpnum_t absoluteLumpNum)
{
try
{
int lumpIdx;
de::File1& file = App_FileSystem()->lumpFile(absoluteLumpNum, &lumpIdx);
file.unlockLump(lumpIdx);
FileInfo const& info = App_FileSystem()->lumpInfo(absoluteLumpNum);
DENG_ASSERT(info.container);
de::File1& file = *info.container;
file.unlockLump(info.lumpIdx);
}
catch(FS1::NotFoundError const&)
{
Expand Down
8 changes: 6 additions & 2 deletions doomsday/engine/portable/src/def_main.cpp
Expand Up @@ -771,12 +771,16 @@ void Def_ReadLumpDefs(void)
int const numLumps = App_FileSystem()->lumpCount();
for(int i = 0; i < numLumps; ++i)
{
if(strnicmp(Str_Text(App_FileSystem()->lumpName(i)), "DD_DEFNS", 8)) continue;
de::FileInfo const& info = App_FileSystem()->lumpInfo(i);
DENG_ASSERT(info.container);
de::File1& container = *info.container;

if(strnicmp(Str_Text(container.lumpName(info.lumpIdx)), "DD_DEFNS", 8)) continue;

numProcessedLumps++;
if(!DED_ReadLump(&defs, i))
{
Con_Error("DD_ReadLumpDefs: Parse error when reading \"%s:DD_DEFNS\".\n", Str_Text(App_FileSystem()->lumpFile(i).path()));
Con_Error("DD_ReadLumpDefs: Parse error when reading \"%s:DD_DEFNS\".\n", Str_Text(container.path()));
}
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/edit_map.c
Expand Up @@ -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_LumpFileAdaptorPath(markerLumpNum)));
AutoStr* cachedMapDir = DAM_ComposeCacheDir(Str_Text(F_LumpFilePath(markerLumpNum)));
Str cachedMapPath;

Str_InitStd(&cachedMapPath);
Expand Down
6 changes: 6 additions & 0 deletions doomsday/engine/portable/src/file.cpp
Expand Up @@ -117,6 +117,12 @@ PathDirectoryNode const& File1::lumpDirectoryNode(int /*lumpIdx*/)
throw de::Error("File1::lumpDirectoryNode", "Not yet implemented");
}

ddstring_t const* File1::lumpName(int /*lumpIdx*/)
{
/// @todo writeme
throw de::Error("File1::lumpName", "Not yet implemented");
}

AutoStr* File1::composeLumpPath(int /*lumpIdx*/, char /*delimiter*/)
{
return AutoStr_NewStd();
Expand Down

0 comments on commit a2d96e3

Please sign in to comment.