2022-05-19 01:51:26 -07:00
|
|
|
#include "file_find.h"
|
|
|
|
|
2022-05-28 04:01:52 -07:00
|
|
|
#include <stddef.h>
|
2022-06-18 00:58:15 -07:00
|
|
|
#include <string.h>
|
2022-05-28 04:01:52 -07:00
|
|
|
|
2022-09-15 02:38:23 -07:00
|
|
|
#include <fpattern.h>
|
|
|
|
|
2022-05-19 01:51:26 -07:00
|
|
|
// 0x4E6380
|
|
|
|
bool fileFindFirst(const char* path, DirectoryFileFindData* findData)
|
|
|
|
{
|
2022-05-28 04:01:52 -07:00
|
|
|
#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;
|
|
|
|
}
|
2022-05-28 04:01:52 -07:00
|
|
|
#else
|
2022-06-18 00:58:15 -07:00
|
|
|
strcpy(findData->path, path);
|
|
|
|
|
|
|
|
char drive[COMPAT_MAX_DRIVE];
|
|
|
|
char dir[COMPAT_MAX_DIR];
|
|
|
|
compat_splitpath(path, drive, dir, NULL, NULL);
|
|
|
|
|
|
|
|
char basePath[COMPAT_MAX_PATH];
|
|
|
|
compat_makepath(basePath, drive, dir, NULL, NULL);
|
|
|
|
|
|
|
|
findData->dir = opendir(basePath);
|
2022-05-19 01:51:26 -07:00
|
|
|
if (findData->dir == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
findData->entry = readdir(findData->dir);
|
2022-06-18 00:58:15 -07:00
|
|
|
while (findData->entry != NULL) {
|
|
|
|
char entryPath[COMPAT_MAX_PATH];
|
|
|
|
compat_makepath(entryPath, drive, dir, fileFindGetName(findData), NULL);
|
|
|
|
if (fpattern_match(findData->path, entryPath)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
findData->entry = readdir(findData->dir);
|
|
|
|
}
|
|
|
|
|
2022-05-19 01:51:26 -07:00
|
|
|
if (findData->entry == NULL) {
|
|
|
|
closedir(findData->dir);
|
2022-06-18 00:58:15 -07:00
|
|
|
findData->dir = NULL;
|
2022-05-19 01:51:26 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E63A8
|
|
|
|
bool fileFindNext(DirectoryFileFindData* findData)
|
|
|
|
{
|
2022-05-28 04:01:52 -07:00
|
|
|
#if defined(_WIN32)
|
2022-05-19 01:51:26 -07:00
|
|
|
if (!FindNextFileA(findData->hFind, &(findData->ffd))) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-05-28 04:01:52 -07:00
|
|
|
#else
|
2022-06-18 00:58:15 -07:00
|
|
|
char drive[COMPAT_MAX_DRIVE];
|
|
|
|
char dir[COMPAT_MAX_DIR];
|
|
|
|
compat_splitpath(findData->path, drive, dir, NULL, NULL);
|
|
|
|
|
2022-05-19 01:51:26 -07:00
|
|
|
findData->entry = readdir(findData->dir);
|
2022-06-18 00:58:15 -07:00
|
|
|
while (findData->entry != NULL) {
|
|
|
|
char entryPath[COMPAT_MAX_PATH];
|
|
|
|
compat_makepath(entryPath, drive, dir, fileFindGetName(findData), NULL);
|
|
|
|
if (fpattern_match(findData->path, entryPath)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
findData->entry = readdir(findData->dir);
|
|
|
|
}
|
|
|
|
|
2022-05-19 01:51:26 -07:00
|
|
|
if (findData->entry == NULL) {
|
|
|
|
closedir(findData->dir);
|
2022-06-18 00:58:15 -07:00
|
|
|
findData->dir = NULL;
|
2022-05-19 01:51:26 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 0x4E63CC
|
|
|
|
bool findFindClose(DirectoryFileFindData* findData)
|
|
|
|
{
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
FindClose(findData->hFind);
|
2022-05-28 04:01:52 -07:00
|
|
|
#else
|
2022-06-18 00:58:15 -07:00
|
|
|
if (findData->dir != NULL) {
|
|
|
|
if (closedir(findData->dir) != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-05-19 01:51:26 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|