diff options
| author | qwasdrizzel <145519042+qwasdrizzel@users.noreply.github.com> | 2026-03-16 21:44:26 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-16 21:44:26 -0500 |
| commit | ce739f6045ec72127491286ea3f3f21e537c1b55 (patch) | |
| tree | f33bd42a47c1b4a7b2153a7fb77127ee3b407db9 /include/lce_filesystem/lce_filesystem.cpp | |
| parent | 255a18fe8e9b57377975f82e2b227afe2a12eda0 (diff) | |
| parent | 5a59f5d146b43811dde6a5a0245ee9875d7b5cd1 (diff) | |
Merge branch 'smartcmd:main' into main
Diffstat (limited to 'include/lce_filesystem/lce_filesystem.cpp')
| -rw-r--r-- | include/lce_filesystem/lce_filesystem.cpp | 74 |
1 files changed, 74 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..e4dac0a0 --- /dev/null +++ b/include/lce_filesystem/lce_filesystem.cpp @@ -0,0 +1,74 @@ +#include "stdafx.h" +#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 +} |
