mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-26 06:45:37 +03:00
Fix open_dir not working properly when called recursively (#467)
This commit is contained in:
parent
ac3e2f48d1
commit
a69a015189
@ -744,9 +744,15 @@ enum FileType
|
|||||||
|
|
||||||
struct DirectoryHandle
|
struct DirectoryHandle
|
||||||
{
|
{
|
||||||
DirectoryHandle(void* handle_, bool valvefs_) : handle(handle_), valvefs(valvefs_) {}
|
DirectoryHandle(CDirectory *handle_) : handle(handle_), valvefs(false) {}
|
||||||
|
DirectoryHandle(FileFindHandle_t handle_) : handle_vfs(handle_), valvefs(true) {}
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
CDirectory* handle;
|
||||||
|
FileFindHandle_t handle_vfs;
|
||||||
|
};
|
||||||
|
|
||||||
void* handle;
|
|
||||||
bool valvefs;
|
bool valvefs;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -768,7 +774,7 @@ static cell AMX_NATIVE_CALL amx_open_dir(AMX *amx, cell *params)
|
|||||||
const char* wildcardedPath = g_LibSys.PathFormat("%s%s*", path, (path[length - 1] != '/' && path[length - 1] != '\\') ? "/" : "");
|
const char* wildcardedPath = g_LibSys.PathFormat("%s%s*", path, (path[length - 1] != '/' && path[length - 1] != '\\') ? "/" : "");
|
||||||
const char* pathID = get_amxstring_null(amx, params[6], 1, length);
|
const char* pathID = get_amxstring_null(amx, params[6], 1, length);
|
||||||
|
|
||||||
static FileFindHandle_t handle;
|
FileFindHandle_t handle;
|
||||||
const char* pFirst = g_FileSystem->FindFirst(wildcardedPath, &handle, pathID);
|
const char* pFirst = g_FileSystem->FindFirst(wildcardedPath, &handle, pathID);
|
||||||
|
|
||||||
if (!pFirst)
|
if (!pFirst)
|
||||||
@ -781,7 +787,7 @@ static cell AMX_NATIVE_CALL amx_open_dir(AMX *amx, cell *params)
|
|||||||
|
|
||||||
*fileType = g_FileSystem->FindIsDirectory(handle) ? FileType_Directory : FileType_File;
|
*fileType = g_FileSystem->FindIsDirectory(handle) ? FileType_Directory : FileType_File;
|
||||||
|
|
||||||
return reinterpret_cast<cell>(new DirectoryHandle(reinterpret_cast<void*>(&handle), true));
|
return reinterpret_cast<cell>(new DirectoryHandle(handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
CDirectory* dir = g_LibSys.OpenDirectory(build_pathname("%s", path));
|
CDirectory* dir = g_LibSys.OpenDirectory(build_pathname("%s", path));
|
||||||
@ -800,7 +806,7 @@ static cell AMX_NATIVE_CALL amx_open_dir(AMX *amx, cell *params)
|
|||||||
const char* entry = dir->GetEntryName();
|
const char* entry = dir->GetEntryName();
|
||||||
set_amxstring_utf8(amx, params[2], entry, strlen(entry), params[3]);
|
set_amxstring_utf8(amx, params[2], entry, strlen(entry), params[3]);
|
||||||
|
|
||||||
return reinterpret_cast<cell>(new DirectoryHandle(reinterpret_cast<void*>(dir), false));
|
return reinterpret_cast<cell>(new DirectoryHandle(dir));
|
||||||
}
|
}
|
||||||
|
|
||||||
// native close_dir(dirh);
|
// native close_dir(dirh);
|
||||||
@ -815,8 +821,8 @@ static cell AMX_NATIVE_CALL amx_close_dir(AMX *amx, cell *params)
|
|||||||
|
|
||||||
if (p->valvefs)
|
if (p->valvefs)
|
||||||
{
|
{
|
||||||
FileFindHandle_t* handle = reinterpret_cast<FileFindHandle_t*>(p->handle);
|
FileFindHandle_t handle = p->handle_vfs;
|
||||||
g_FileSystem->FindClose(*handle);
|
g_FileSystem->FindClose(handle);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -841,14 +847,9 @@ static cell AMX_NATIVE_CALL amx_get_dir(AMX *amx, cell *params)
|
|||||||
|
|
||||||
if (p->valvefs)
|
if (p->valvefs)
|
||||||
{
|
{
|
||||||
FileFindHandle_t* handle = reinterpret_cast<FileFindHandle_t*>(p->handle);
|
FileFindHandle_t handle = p->handle_vfs;
|
||||||
|
|
||||||
if (!handle)
|
const char* entry = g_FileSystem->FindNext(handle);
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* entry = g_FileSystem->FindNext(*handle);
|
|
||||||
|
|
||||||
if (!entry)
|
if (!entry)
|
||||||
{
|
{
|
||||||
@ -858,14 +859,14 @@ static cell AMX_NATIVE_CALL amx_get_dir(AMX *amx, cell *params)
|
|||||||
if (numParams >= 4)
|
if (numParams >= 4)
|
||||||
{
|
{
|
||||||
cell* fileType = get_amxaddr(amx, params[4]);
|
cell* fileType = get_amxaddr(amx, params[4]);
|
||||||
*fileType = g_FileSystem->FindIsDirectory(*handle) ? FileType_Directory : FileType_File;
|
*fileType = g_FileSystem->FindIsDirectory(handle) ? FileType_Directory : FileType_File;
|
||||||
}
|
}
|
||||||
|
|
||||||
set_amxstring_utf8(amx, params[2], entry, strlen(entry), params[3]);
|
set_amxstring_utf8(amx, params[2], entry, strlen(entry), params[3]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CDirectory* handle = reinterpret_cast<CDirectory*>(p->handle);
|
CDirectory* handle = p->handle;
|
||||||
|
|
||||||
if (!handle)
|
if (!handle)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user