fallout2-ce/src/file_find.cc

60 lines
1.1 KiB
C++
Raw Normal View History

2022-05-19 01:51:26 -07:00
#include "file_find.h"
#include <stddef.h>
2022-05-19 01:51:26 -07:00
// 0x4E6380
bool fileFindFirst(const char* path, DirectoryFileFindData* findData)
{
#if defined(_WIN32)
2022-05-19 01:51:26 -07:00
findData->hFind = FindFirstFileA(path, &(findData->ffd));
if (findData->hFind == INVALID_HANDLE_VALUE) {
return false;
}
#else
2022-05-19 01:51:26 -07:00
findData->dir = opendir(path);
if (findData->dir == NULL) {
return false;
}
findData->entry = readdir(findData->dir);
if (findData->entry == NULL) {
closedir(findData->dir);
return false;
}
#endif
return true;
}
// 0x4E63A8
bool fileFindNext(DirectoryFileFindData* findData)
{
#if defined(_WIN32)
2022-05-19 01:51:26 -07:00
if (!FindNextFileA(findData->hFind, &(findData->ffd))) {
return false;
}
#else
2022-05-19 01:51:26 -07:00
findData->entry = readdir(findData->dir);
if (findData->entry == NULL) {
closedir(findData->dir);
return false;
}
#endif
return true;
}
// 0x4E63CC
bool findFindClose(DirectoryFileFindData* findData)
{
#if defined(_MSC_VER)
FindClose(findData->hFind);
#else
2022-05-19 01:51:26 -07:00
if (closedir(findData->dir) != 0) {
return false;
}
#endif
return true;
}