Converted tooling to C.

This commit is contained in:
2021-11-07 23:34:05 -08:00
parent a2a839cbac
commit a6bae07e38
18 changed files with 637 additions and 394 deletions

View File

@ -55,4 +55,67 @@ void assetReadString(FILE *file, char *buffer) {
length = ftell(file);// Get our current position (the end)
fseek(file, 0, SEEK_SET);// Reset the seek
fread(buffer, 1, length, file);// Read all the bytes
}
void fileGetDirectory(char *file, char* buffer) {
char *c, *p;
int32_t i;
p = strrchr(file, FILE_PATH_SEP);
c = file;
i = 0;
do {
buffer[i++] = *c;
} while(++c < p);
buffer[i] = '\0';
}
bool fileListChildren(
char *directory,
char *buffer,
int32_t *count,
uint8_t *types,
char **children
) {
#if defined(_MSC_VER)
WIN32_FIND_DATA fdFile;
HANDLE hFind = NULL;
char sPath[2048];
int32_t i;
// Append wildcard
sprintf(sPath, "%s\\*.*", directory);
// Scan first
if((hFind = FindFirstFile(sPath, &fdFile)) == INVALID_HANDLE_VALUE) {
printf("Path not found: [%s]\n", directory);
return false;
}
// Iterate
i = 0;
do {
if(
strcmp(fdFile.cFileName, ".") == 0 ||
strcmp(fdFile.cFileName, "..") == 0
) continue;
// Get Full path.
sprintf(sPath, "%s\\%s", directory, fdFile.cFileName);
//Is the entity a File or Folder?
if(fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
types[i] = FILE_CHILD_TYPE_DIR;
} else {
types[i] = FILE_CHILD_TYPE_FILE;
}
children[i] = buffer + (i * FILE_CHILD_NAME_MAX);
strcpy(children[i], fdFile.cFileName);
i++;
} while(FindNextFile(hFind, &fdFile));
*count = i;
return true;
#else
#endif
}