diff --git a/src/common/file_system.cpp b/src/common/file_system.cpp index 84079a303..d23e0fea5 100644 --- a/src/common/file_system.cpp +++ b/src/common/file_system.cpp @@ -4,6 +4,7 @@ #include "log.h" #include "string_util.h" #include +#include #include #ifdef __APPLE__ @@ -313,6 +314,33 @@ std::string_view GetFileTitleFromPath(const char* path) return std::string_view(path); } +std::vector GetRootDirectoryList() +{ + std::vector results; + +#ifdef WIN32 + char buf[256]; + if (GetLogicalDriveStringsA(sizeof(buf), buf) != 0) + { + const char* ptr = buf; + while (*ptr != '\0') + { + const std::size_t len = std::strlen(ptr); + results.emplace_back(ptr, len); + ptr += len + 1u; + } + } +#else + const char* home_path = std::getenv("HOME"); + if (home_path) + results.push_back(home_path); + + results.push_back("/"); +#endif + + return results; +} + void BuildPathRelativeToFile(char* Destination, u32 cbDestination, const char* CurrentFileName, const char* NewFileName, bool OSPath /* = true */, bool Canonicalize /* = true */) { diff --git a/src/common/file_system.h b/src/common/file_system.h index c3fd0f089..b8315ae55 100644 --- a/src/common/file_system.h +++ b/src/common/file_system.h @@ -154,6 +154,9 @@ std::string_view GetFileNameFromPath(const char* path); /// Returns the file title (less the extension and path) from a filename. std::string_view GetFileTitleFromPath(const char* path); +/// Returns a list of "root directories" (i.e. root/home directories on Linux, drive letters on Windows). +std::vector GetRootDirectoryList(); + // search for files bool FindFiles(const char* Path, const char* Pattern, u32 Flags, FindResultsArray* pResults);