Common/FileSystem: Add a helper to get root directory list
This commit is contained in:
parent
7a48bcc585
commit
5875b738dc
|
@ -4,6 +4,7 @@
|
|||
#include "log.h"
|
||||
#include "string_util.h"
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
@ -313,6 +314,33 @@ std::string_view GetFileTitleFromPath(const char* path)
|
|||
return std::string_view(path);
|
||||
}
|
||||
|
||||
std::vector<std::string> GetRootDirectoryList()
|
||||
{
|
||||
std::vector<std::string> 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 */)
|
||||
{
|
||||
|
|
|
@ -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<std::string> GetRootDirectoryList();
|
||||
|
||||
// search for files
|
||||
bool FindFiles(const char* Path, const char* Pattern, u32 Flags, FindResultsArray* pResults);
|
||||
|
||||
|
|
Loading…
Reference in New Issue