diff options
| author | qwasdrizzel <145519042+qwasdrizzel@users.noreply.github.com> | 2026-03-05 22:18:36 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-05 22:18:36 -0600 |
| commit | cffe636e359441e1c667784d40bd71d111c281de (patch) | |
| tree | 11144e082d516ba05a66aa3564875f5879a45f7c /Minecraft.Client/Common/Filesystem/Filesystem.cpp | |
| parent | d1eb09a4b97f38476a538f7a7de06a0a620a1a65 (diff) | |
| parent | 5cbdf27b46e4ac23e441489c524b1f1aba88c269 (diff) | |
Merge branch 'smartcmd:main' into main
Diffstat (limited to 'Minecraft.Client/Common/Filesystem/Filesystem.cpp')
| -rw-r--r-- | Minecraft.Client/Common/Filesystem/Filesystem.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/Minecraft.Client/Common/Filesystem/Filesystem.cpp b/Minecraft.Client/Common/Filesystem/Filesystem.cpp new file mode 100644 index 00000000..0d225cb5 --- /dev/null +++ b/Minecraft.Client/Common/Filesystem/Filesystem.cpp @@ -0,0 +1,74 @@ +#include "stdafx.h" +#include "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 +} |
