Skip to content

Commit

Permalink
Fixed: When attempting to locate files in the virtual file system, re…
Browse files Browse the repository at this point in the history
…lative search paths would be resolved using the working directory as the base. This is correct for real files and those transformed using a DD_DIREC lump. However when querying the Zip archive paths should be relative to the base directory.
  • Loading branch information
danij-deng committed Feb 8, 2011
1 parent 3d6116a commit 7696622
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
15 changes: 10 additions & 5 deletions doomsday/engine/portable/src/dd_zip.c
Expand Up @@ -685,18 +685,18 @@ int Zip_Iterate(int (*callback) (const ddstring_t*, void*))

zipindex_t Zip_Find(const char* searchPath)
{
assert(searchPath);
assert(searchPath && searchPath[0]);
{
zipindex_t begin, end, mid;
filename_t fullPath;
ddstring_t fullPath;
int relation;

if(numZipFiles == 0)
return 0; // None registered yet.

// Convert to an absolute path.
strncpy(fullPath, searchPath, FILENAME_T_MAXLEN);
Dir_MakeAbsolute(fullPath, FILENAME_T_MAXLEN);
Str_Init(&fullPath); Str_Set(&fullPath, searchPath);
F_PrependBasePath(&fullPath, &fullPath);

// Init the search.
begin = 0;
Expand All @@ -707,17 +707,21 @@ zipindex_t Zip_Find(const char* searchPath)
mid = (begin + end) / 2;

// How does this compare?
relation = strnicmp(fullPath, Str_Text(&zipFiles[mid].name), FILENAME_T_MAXLEN);
relation = Str_CompareIgnoreCase(&fullPath, Str_Text(&zipFiles[mid].name));
if(!relation)
{ // Got it! We return a 1-based index.
Str_Free(&fullPath);
return mid + 1;
}
if(relation < 0)
{ // What we are searching must be in the first half.
if(mid > 0)
end = mid - 1;
else
{
Str_Free(&fullPath);
return 0; // Not found.
}
}
else
{ // Then it must be in the second half.
Expand All @@ -726,6 +730,7 @@ zipindex_t Zip_Find(const char* searchPath)
}

// It wasn't found.
Str_Free(&fullPath);
return 0;
}
}
Expand Down
11 changes: 7 additions & 4 deletions doomsday/engine/portable/src/sys_filein.c
Expand Up @@ -784,16 +784,17 @@ DFILE* F_Open(const char* path, const char* mode)

// Make it a full path.
M_TranslatePath(trans, path, FILENAME_T_MAXLEN);
_fullpath(full, trans, 255);

if(!strchr(mode, 'f')) // Doesn't need to be a real file?
{
// First check the Zip directory.
{ zipindex_t foundZip;
if((foundZip = Zip_Find(full)) != 0)
if((foundZip = Zip_Find(trans)) != 0)
return F_OpenZip(foundZip, dontBuffer);
}

_fullpath(full, trans, 255);

// Check through the dir/WAD direcs.
{ int i;
for(i = 0; Str_Length(&lumpDirectory[i].path) != 0; ++i)
Expand All @@ -803,11 +804,13 @@ DFILE* F_Open(const char* path, const char* mode)
return F_OpenLump(rec->lumpName, dontBuffer);
}}
}

if(strchr(mode, 'w'))
else if(strchr(mode, 'w'))
{
return NULL; // Must be in a WAD...
}

// Try to open as a real file, then.
_fullpath(full, trans, 255);
return F_OpenFile(full, mode);
}

Expand Down
6 changes: 2 additions & 4 deletions doomsday/engine/portable/src/sys_reslocator.c
Expand Up @@ -218,19 +218,17 @@ static boolean tryFindResource2(resourceclass_t rclass, const ddstring_t* search
ddstring_t* foundPath, resourcenamespace_t* rnamespace)
{
assert(inited && searchPath && !Str_IsEmpty(searchPath));

// Is there a namespace we should use?
if(rnamespace && ResourceNamespace_Find2(rnamespace, searchPath, foundPath))
{
if(foundPath)
F_PrependBasePath(foundPath, foundPath);
return true;
}

if(F_Access(Str_Text(searchPath)))
if(0 != F_Access(Str_Text(searchPath)))
{
if(foundPath)
Str_Copy(foundPath, searchPath);
F_PrependBasePath(foundPath, searchPath);
return true;
}
return false;
Expand Down

0 comments on commit 7696622

Please sign in to comment.