diff options
| author | GuglioIsStupid <guglioisbusiness@gmail.com> | 2026-03-07 06:36:05 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-07 18:36:05 +0700 |
| commit | 38ce933fd5ec05673cbefae63f2bae74a1e0d53c (patch) | |
| tree | c0fe33a8603d72c4a1b34fb892bf3fd1f60ea7f3 /include | |
| parent | e754bad17e5770ccbcceb45c39f31d7e8bf6ff58 (diff) | |
voids request - Move the filesystem files to root/ as it will be used in both Minecraft.Client and Minecraft.World (#819)
* Move Filesystem to root/include/ as per devoiders request
* Filesystem -> lce_filesystem
Diffstat (limited to 'include')
| -rw-r--r-- | include/lce_filesystem/lce_filesystem.cpp | 73 | ||||
| -rw-r--r-- | include/lce_filesystem/lce_filesystem.h | 6 |
2 files changed, 79 insertions, 0 deletions
diff --git a/include/lce_filesystem/lce_filesystem.cpp b/include/lce_filesystem/lce_filesystem.cpp new file mode 100644 index 00000000..d0d4d600 --- /dev/null +++ b/include/lce_filesystem/lce_filesystem.cpp @@ -0,0 +1,73 @@ +#include "lce_filesystem.h" + +#ifdef _WINDOWS64 +#include <windows.h> +#endif // TODO: More os' filesystem handling for when the project moves away from only Windows + +#include <stdio.h> + +bool FileOrDirectoryExists(const char* path) +{ +#ifdef _WINDOWS64 + DWORD attribs = GetFileAttributesA(path); + return (attribs != INVALID_FILE_ATTRIBUTES); +#else + #error "FileOrDirectoryExists not implemented for this platform" + return false; +#endif +} + +bool FileExists(const char* path) +{ +#ifdef _WINDOWS64 + DWORD attribs = GetFileAttributesA(path); + return (attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY)); +#else + #error "FileExists not implemented for this platform" + return false; +#endif +} + +bool DirectoryExists(const char* path) +{ +#ifdef _WINDOWS64 + DWORD attribs = GetFileAttributesA(path); + return (attribs != INVALID_FILE_ATTRIBUTES && (attribs & FILE_ATTRIBUTE_DIRECTORY)); +#else + #error "DirectoryExists not implemented for this platform" + return false; +#endif +} + +bool GetFirstFileInDirectory(const char* directory, char* outFilePath, size_t outFilePathSize) +{ +#ifdef _WINDOWS64 + char searchPath[MAX_PATH]; + snprintf(searchPath, MAX_PATH, "%s\\*", directory); + + WIN32_FIND_DATAA findData; + HANDLE hFind = FindFirstFileA(searchPath, &findData); + + if (hFind == INVALID_HANDLE_VALUE) + { + return false; + } + + do + { + if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + // Found a file, copy its path to the output buffer + snprintf(outFilePath, outFilePathSize, "%s\\%s", directory, findData.cFileName); + FindClose(hFind); + return true; + } + } while (FindNextFileA(hFind, &findData) != 0); + + FindClose(hFind); + return false; // No files found in the directory +#else + #error "GetFirstFileInDirectory not implemented for this platform" + return false; +#endif +} diff --git a/include/lce_filesystem/lce_filesystem.h b/include/lce_filesystem/lce_filesystem.h new file mode 100644 index 00000000..11d1bf5b --- /dev/null +++ b/include/lce_filesystem/lce_filesystem.h @@ -0,0 +1,6 @@ +#pragma once + +bool FileOrDirectoryExists(const char* path); +bool FileExists(const char* path); +bool DirectoryExists(const char* path); +bool GetFirstFileInDirectory(const char* directory, char* outFilePath, size_t outFilePathSize); |
