Skip to content

Commit

Permalink
Merge pull request #169 from alliedmodders/vfsdir-fixes
Browse files Browse the repository at this point in the history
Fixes for OpenDirectory with use_valve_fs (r=asherkin).
  • Loading branch information
psychonic committed Nov 8, 2014
2 parents 0d24804 + 9021b23 commit b7c4faf
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions core/logic/smn_filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class FSHelper

struct ValveDirectory
{
FileFindHandle_t hndl;
FileFindHandle_t hndl = -1;
char szFirstPath[PLATFORM_MAX_PATH];
bool bHandledFirstPath;
};
Expand Down Expand Up @@ -271,13 +271,18 @@ static cell_t sm_OpenDirectory(IPluginContext *pContext, const cell_t *params)
return 0;
}

if (!path[0])
{
return pContext->ThrowNativeError("Invalid file path");
}

Handle_t handle = 0;

if (params[0] >= 2 && params[2])
{
size_t len = strlen(path);
char wildcardedPath[PLATFORM_MAX_PATH];
snprintf(wildcardedPath, sizeof(wildcardedPath), "%s*", path);
ValveDirectory *valveDir = new ValveDirectory;
snprintf(wildcardedPath, sizeof(wildcardedPath), "%s%s*", path, (path[len-1] != '/' && path[len-1] != '\\') ? "/" : "");

char *pathID;
if ((err=pContext->LocalToStringNULL(params[3], &pathID)) != SP_ERROR_NONE)
Expand All @@ -286,15 +291,18 @@ static cell_t sm_OpenDirectory(IPluginContext *pContext, const cell_t *params)
return 0;
}

ValveDirectory *valveDir = new ValveDirectory;

const char *pFirst = smcore.filesystem->FindFirstEx(wildcardedPath, pathID, &valveDir->hndl);
if (pFirst)
if (!pFirst)
{
valveDir->bHandledFirstPath = false;
strncpy(valveDir->szFirstPath, pFirst, sizeof(valveDir->szFirstPath));
delete valveDir;
return 0;
}
else
{
valveDir->bHandledFirstPath = true;
valveDir->bHandledFirstPath = false;
strncpy(valveDir->szFirstPath, pFirst, sizeof(valveDir->szFirstPath));
}

handle = handlesys->CreateHandle(g_ValveDirType, valveDir, pContext->GetIdentity(), g_pCoreIdent, NULL);
Expand Down

0 comments on commit b7c4faf

Please sign in to comment.