From 8398eb16b8996df7093960bb0a5d7fc65b8229d4 Mon Sep 17 00:00:00 2001 From: GuglioIsStupid Date: Thu, 5 Mar 2026 19:48:12 -0500 Subject: Miniaudio Implementation (+stb_vorbis) (#624) * Miniaudio Implementation * Do not link miles + remove miles lib --- Minecraft.Client/Common/Filesystem/Filesystem.cpp | 74 +++++++++++++++++++++++ Minecraft.Client/Common/Filesystem/Filesystem.h | 6 ++ 2 files changed, 80 insertions(+) create mode 100644 Minecraft.Client/Common/Filesystem/Filesystem.cpp create mode 100644 Minecraft.Client/Common/Filesystem/Filesystem.h (limited to 'Minecraft.Client/Common/Filesystem') 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 +#endif // TODO: More os' filesystem handling for when the project moves away from only Windows + +#include + +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/Minecraft.Client/Common/Filesystem/Filesystem.h b/Minecraft.Client/Common/Filesystem/Filesystem.h new file mode 100644 index 00000000..11d1bf5b --- /dev/null +++ b/Minecraft.Client/Common/Filesystem/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); -- cgit v1.2.3