2017-02-24 20:26:38 +01:00
|
|
|
#include "ppsspp_config.h"
|
|
|
|
|
|
2021-07-19 10:42:44 +02:00
|
|
|
#if PPSSPP_PLATFORM(WINDOWS)
|
2012-03-24 23:39:19 +01:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2024-12-08 12:12:02 +01:00
|
|
|
#include "Common/CommonWindows.h"
|
2012-12-01 10:35:55 +01:00
|
|
|
#include <direct.h>
|
2022-07-06 22:59:47 +01:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
|
|
|
|
#include <fileapifromapp.h>
|
2023-04-30 08:54:54 +04:00
|
|
|
#include <UWP/UWPHelpers/StorageManager.h>
|
2022-07-06 22:59:47 +01:00
|
|
|
#endif
|
2012-03-24 23:39:19 +01:00
|
|
|
#else
|
2020-03-03 22:53:03 -08:00
|
|
|
#include <strings.h>
|
2012-03-24 23:39:19 +01:00
|
|
|
#include <dirent.h>
|
|
|
|
|
#include <unistd.h>
|
2012-12-13 14:39:44 +10:00
|
|
|
#include <errno.h>
|
2012-03-24 23:39:19 +01:00
|
|
|
#endif
|
2012-11-08 03:29:35 +10:00
|
|
|
#include <cstring>
|
2012-03-24 23:39:19 +01:00
|
|
|
#include <string>
|
2012-10-31 13:34:27 +01:00
|
|
|
#include <set>
|
2012-11-01 09:45:27 +01:00
|
|
|
#include <algorithm>
|
2013-07-04 10:37:16 +02:00
|
|
|
#include <cstdio>
|
2012-10-31 13:34:27 +01:00
|
|
|
#include <sys/stat.h>
|
2012-10-31 20:42:43 +01:00
|
|
|
#include <ctype.h>
|
2012-10-31 13:34:27 +01:00
|
|
|
|
2020-10-01 13:05:04 +02:00
|
|
|
#include "Common/Data/Encoding/Utf8.h"
|
2020-09-29 12:19:22 +02:00
|
|
|
#include "Common/StringUtils.h"
|
2021-02-28 13:46:08 +01:00
|
|
|
#include "Common/Net/URL.h"
|
2020-10-04 20:48:47 +02:00
|
|
|
#include "Common/File/DirListing.h"
|
2021-04-25 20:38:22 +02:00
|
|
|
#include "Common/File/FileUtil.h"
|
2021-06-05 19:29:23 +02:00
|
|
|
#include "Common/File/AndroidStorage.h"
|
2024-11-27 15:14:03 +01:00
|
|
|
#include "Common/TimeUtil.h"
|
|
|
|
|
#include "Common/Log.h"
|
2020-09-29 12:19:22 +02:00
|
|
|
|
2015-05-25 17:11:33 +00:00
|
|
|
#if !defined(__linux__) && !defined(_WIN32) && !defined(__QNX__)
|
2012-11-18 21:36:07 -03:00
|
|
|
#define stat64 stat
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-03-03 22:53:03 -08:00
|
|
|
#ifdef HAVE_LIBNX
|
|
|
|
|
// Far from optimal, but I guess it works...
|
|
|
|
|
#define fseeko fseek
|
|
|
|
|
#define ftello ftell
|
|
|
|
|
#define fileno
|
|
|
|
|
#endif // HAVE_LIBNX
|
|
|
|
|
|
2024-11-27 15:14:03 +01:00
|
|
|
// NOTE: There's another one in FileUtil.cpp.
|
2024-11-29 16:00:34 +01:00
|
|
|
#ifdef _WIN32
|
2024-11-27 15:14:03 +01:00
|
|
|
constexpr bool SIMULATE_SLOW_IO = false;
|
2024-11-29 16:00:34 +01:00
|
|
|
#else
|
|
|
|
|
constexpr bool SIMULATE_SLOW_IO = false;
|
|
|
|
|
#endif
|
|
|
|
|
constexpr bool LOG_IO = false;
|
2024-11-27 15:14:03 +01:00
|
|
|
|
2021-04-25 20:38:22 +02:00
|
|
|
namespace File {
|
2012-12-01 10:35:55 +01:00
|
|
|
|
2021-07-19 10:31:48 +02:00
|
|
|
#if PPSSPP_PLATFORM(WINDOWS)
|
|
|
|
|
static uint64_t FiletimeToStatTime(FILETIME ft) {
|
|
|
|
|
const int windowsTickResolution = 10000000;
|
|
|
|
|
const int64_t secToUnixEpoch = 11644473600LL;
|
|
|
|
|
int64_t ticks = ((uint64_t)ft.dwHighDateTime << 32) | ft.dwLowDateTime;
|
|
|
|
|
return (int64_t)(ticks / windowsTickResolution - secToUnixEpoch);
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
bool GetFileInfo(const Path &path, FileInfo * fileInfo) {
|
2024-11-29 16:00:34 +01:00
|
|
|
if (LOG_IO) {
|
2024-11-30 02:43:33 +01:00
|
|
|
INFO_LOG(Log::System, "GetFileInfo %s", path.ToVisualString().c_str());
|
2024-11-29 16:00:34 +01:00
|
|
|
}
|
|
|
|
|
if (SIMULATE_SLOW_IO) {
|
2024-11-27 15:14:03 +01:00
|
|
|
sleep_ms(300, "slow-io-sim");
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
switch (path.Type()) {
|
|
|
|
|
case PathType::NATIVE:
|
|
|
|
|
break; // OK
|
2021-06-05 14:19:37 +02:00
|
|
|
case PathType::CONTENT_URI:
|
|
|
|
|
return Android_GetFileInfo(path.ToString(), fileInfo);
|
2021-05-06 01:31:38 +02:00
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-01 10:35:55 +01:00
|
|
|
// TODO: Expand relative paths?
|
2021-05-09 15:25:12 +02:00
|
|
|
fileInfo->fullName = path;
|
2012-12-01 10:35:55 +01:00
|
|
|
|
2021-07-19 10:31:48 +02:00
|
|
|
#if PPSSPP_PLATFORM(WINDOWS)
|
2013-04-13 21:22:03 +02:00
|
|
|
WIN32_FILE_ATTRIBUTE_DATA attrs;
|
2022-07-06 22:59:47 +01:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
|
|
|
|
if (!GetFileAttributesExFromAppW(path.ToWString().c_str(), GetFileExInfoStandard, &attrs)) {
|
|
|
|
|
#else
|
2021-05-06 01:31:38 +02:00
|
|
|
if (!GetFileAttributesExW(path.ToWString().c_str(), GetFileExInfoStandard, &attrs)) {
|
2022-07-06 22:59:47 +01:00
|
|
|
#endif
|
2013-04-21 23:13:07 +08:00
|
|
|
fileInfo->size = 0;
|
|
|
|
|
fileInfo->isDirectory = false;
|
2013-06-08 17:43:27 +02:00
|
|
|
fileInfo->exists = false;
|
2013-04-21 23:13:07 +08:00
|
|
|
return false;
|
2013-02-26 23:07:30 +01:00
|
|
|
}
|
2013-04-21 23:13:07 +08:00
|
|
|
fileInfo->size = (uint64_t)attrs.nFileSizeLow | ((uint64_t)attrs.nFileSizeHigh << 32);
|
2013-04-13 21:22:03 +02:00
|
|
|
fileInfo->isDirectory = (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
|
|
|
|
fileInfo->isWritable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
|
2013-06-08 17:43:27 +02:00
|
|
|
fileInfo->exists = true;
|
2021-04-25 20:52:29 +02:00
|
|
|
fileInfo->atime = FiletimeToStatTime(attrs.ftLastAccessTime);
|
|
|
|
|
fileInfo->mtime = FiletimeToStatTime(attrs.ftLastWriteTime);
|
|
|
|
|
fileInfo->ctime = FiletimeToStatTime(attrs.ftCreationTime);
|
|
|
|
|
if (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
|
|
|
|
|
fileInfo->access = 0444; // Read
|
|
|
|
|
} else {
|
|
|
|
|
fileInfo->access = 0666; // Read/Write
|
|
|
|
|
}
|
|
|
|
|
if (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
|
|
|
|
fileInfo->access |= 0111; // Execute
|
|
|
|
|
}
|
2012-10-30 16:23:08 +01:00
|
|
|
#else
|
2012-10-28 11:37:10 +01:00
|
|
|
|
2017-08-18 11:53:47 +03:00
|
|
|
#if (defined __ANDROID__) && (__ANDROID_API__ < 21)
|
2017-07-03 16:16:25 +02:00
|
|
|
struct stat file_info;
|
2021-05-06 01:31:38 +02:00
|
|
|
int result = stat(path.c_str(), &file_info);
|
2017-07-03 16:16:25 +02:00
|
|
|
#else
|
|
|
|
|
struct stat64 file_info;
|
2021-05-06 01:31:38 +02:00
|
|
|
int result = stat64(path.c_str(), &file_info);
|
2017-07-03 16:16:25 +02:00
|
|
|
#endif
|
2012-10-28 11:37:10 +01:00
|
|
|
if (result < 0) {
|
2013-06-08 17:43:27 +02:00
|
|
|
fileInfo->exists = false;
|
2012-10-28 11:37:10 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-01 10:35:55 +01:00
|
|
|
fileInfo->isDirectory = S_ISDIR(file_info.st_mode);
|
|
|
|
|
fileInfo->isWritable = false;
|
2013-02-26 23:07:30 +01:00
|
|
|
fileInfo->size = file_info.st_size;
|
2013-06-08 17:43:27 +02:00
|
|
|
fileInfo->exists = true;
|
2021-04-25 20:52:29 +02:00
|
|
|
fileInfo->atime = file_info.st_atime;
|
|
|
|
|
fileInfo->mtime = file_info.st_mtime;
|
|
|
|
|
fileInfo->ctime = file_info.st_ctime;
|
|
|
|
|
fileInfo->access = file_info.st_mode & 0x1ff;
|
2012-12-01 10:35:55 +01:00
|
|
|
// HACK: approximation
|
|
|
|
|
if (file_info.st_mode & 0200)
|
|
|
|
|
fileInfo->isWritable = true;
|
2012-10-30 16:23:08 +01:00
|
|
|
#endif
|
2012-12-01 10:35:55 +01:00
|
|
|
return true;
|
2012-10-28 11:37:10 +01:00
|
|
|
}
|
|
|
|
|
|
2021-05-06 01:31:38 +02:00
|
|
|
bool GetModifTime(const Path &filename, tm & return_time) {
|
2021-04-25 20:52:29 +02:00
|
|
|
memset(&return_time, 0, sizeof(return_time));
|
|
|
|
|
FileInfo info;
|
2021-05-06 01:31:38 +02:00
|
|
|
if (GetFileInfo(filename, &info)) {
|
2021-04-25 20:52:29 +02:00
|
|
|
time_t t = info.mtime;
|
|
|
|
|
localtime_r((time_t*)&t, &return_time);
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
2012-10-31 13:34:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-04 20:48:47 +02:00
|
|
|
bool FileInfo::operator <(const FileInfo & other) const {
|
2013-07-04 10:37:16 +02:00
|
|
|
if (isDirectory && !other.isDirectory)
|
|
|
|
|
return true;
|
|
|
|
|
else if (!isDirectory && other.isDirectory)
|
|
|
|
|
return false;
|
|
|
|
|
if (strcasecmp(name.c_str(), other.name.c_str()) < 0)
|
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-29 10:39:30 +01:00
|
|
|
std::vector<File::FileInfo> ApplyFilter(std::vector<File::FileInfo> files, const char *extensionFilter, std::string_view prefix) {
|
2021-05-16 00:38:12 +02:00
|
|
|
std::set<std::string> filters;
|
2024-11-29 10:39:30 +01:00
|
|
|
if (extensionFilter) {
|
2021-05-16 00:38:12 +02:00
|
|
|
std::string tmp;
|
2024-11-29 10:39:30 +01:00
|
|
|
while (*extensionFilter) {
|
|
|
|
|
if (*extensionFilter == ':') {
|
2022-09-30 12:35:28 +03:00
|
|
|
filters.emplace("." + tmp);
|
2021-05-16 00:38:12 +02:00
|
|
|
tmp.clear();
|
|
|
|
|
} else {
|
2024-11-29 10:39:30 +01:00
|
|
|
tmp.push_back(*extensionFilter);
|
2021-05-16 00:38:12 +02:00
|
|
|
}
|
2024-11-29 10:39:30 +01:00
|
|
|
extensionFilter++;
|
2021-05-16 00:38:12 +02:00
|
|
|
}
|
|
|
|
|
if (!tmp.empty())
|
2022-09-30 12:35:28 +03:00
|
|
|
filters.emplace("." + tmp);
|
2021-05-16 00:38:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto pred = [&](const File::FileInfo &info) {
|
2024-11-30 02:43:33 +01:00
|
|
|
// WARNING: Keep in mind that if we return true here, the files is REMOVED from the list.
|
|
|
|
|
// It's not retain_if.
|
|
|
|
|
if (!startsWith(info.name, prefix)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-11-29 10:39:30 +01:00
|
|
|
if (info.isDirectory || !extensionFilter)
|
2021-05-16 00:38:12 +02:00
|
|
|
return false;
|
|
|
|
|
std::string ext = info.fullName.GetFileExtension();
|
|
|
|
|
return filters.find(ext) == filters.end();
|
|
|
|
|
};
|
|
|
|
|
files.erase(std::remove_if(files.begin(), files.end(), pred), files.end());
|
|
|
|
|
return files;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-29 10:39:30 +01:00
|
|
|
bool GetFilesInDir(const Path &directory, std::vector<FileInfo> *files, const char *filter, int flags, std::string_view prefix) {
|
2024-11-29 16:00:34 +01:00
|
|
|
if (LOG_IO) {
|
2024-11-30 02:43:33 +01:00
|
|
|
INFO_LOG(Log::System, "GetFilesInDir '%s' (ext %s, prefix %.*s)", directory.ToVisualString().c_str(), filter, (int)prefix.size(), prefix.data());
|
2024-11-29 16:00:34 +01:00
|
|
|
}
|
|
|
|
|
if (SIMULATE_SLOW_IO) {
|
2024-11-27 15:14:03 +01:00
|
|
|
sleep_ms(300, "slow-io-sim");
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-16 00:38:12 +02:00
|
|
|
if (directory.Type() == PathType::CONTENT_URI) {
|
2022-10-09 11:37:19 -07:00
|
|
|
bool exists = false;
|
2024-11-29 10:39:30 +01:00
|
|
|
// TODO: Move prefix filtering over to the Java side for more speed.
|
|
|
|
|
std::vector<File::FileInfo> fileList = Android_ListContentUri(directory.ToString(), std::string(prefix), &exists);
|
2024-11-30 02:43:33 +01:00
|
|
|
int beforeFilter = (int)fileList.size();
|
|
|
|
|
*files = ApplyFilter(fileList, filter, prefix);
|
2021-07-12 15:08:27 +02:00
|
|
|
std::sort(files->begin(), files->end());
|
2024-11-30 02:43:33 +01:00
|
|
|
DEBUG_LOG(Log::System, "GetFilesInDir: Found %d entries (%d before filter)", (int)files->size(), beforeFilter);
|
2022-10-09 11:37:19 -07:00
|
|
|
return exists;
|
2021-05-16 00:38:12 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-19 10:31:48 +02:00
|
|
|
std::set<std::string> filters;
|
|
|
|
|
if (filter) {
|
|
|
|
|
std::string tmp;
|
|
|
|
|
while (*filter) {
|
|
|
|
|
if (*filter == ':') {
|
2023-09-22 10:09:10 +02:00
|
|
|
filters.insert(tmp);
|
2021-07-19 10:31:48 +02:00
|
|
|
tmp.clear();
|
|
|
|
|
} else {
|
|
|
|
|
tmp.push_back(*filter);
|
|
|
|
|
}
|
|
|
|
|
filter++;
|
|
|
|
|
}
|
|
|
|
|
if (!tmp.empty())
|
2023-09-22 10:09:10 +02:00
|
|
|
filters.insert(tmp);
|
2021-07-19 10:31:48 +02:00
|
|
|
}
|
|
|
|
|
|
2021-07-10 11:47:03 +02:00
|
|
|
#if PPSSPP_PLATFORM(WINDOWS)
|
|
|
|
|
if (directory.IsRoot()) {
|
|
|
|
|
// Special path that means root of file system.
|
2024-11-29 10:39:30 +01:00
|
|
|
// This does not respect prefix filtering.
|
2021-07-10 11:47:03 +02:00
|
|
|
std::vector<std::string> drives = File::GetWindowsDrives();
|
|
|
|
|
for (auto drive = drives.begin(); drive != drives.end(); ++drive) {
|
|
|
|
|
if (*drive == "A:/" || *drive == "B:/")
|
|
|
|
|
continue;
|
|
|
|
|
File::FileInfo fake;
|
|
|
|
|
fake.fullName = Path(*drive);
|
|
|
|
|
fake.name = *drive;
|
|
|
|
|
fake.isDirectory = true;
|
|
|
|
|
fake.exists = true;
|
|
|
|
|
fake.size = 0;
|
|
|
|
|
fake.isWritable = false;
|
|
|
|
|
files->push_back(fake);
|
|
|
|
|
}
|
|
|
|
|
return files->size();
|
|
|
|
|
}
|
2012-10-31 13:23:16 +01:00
|
|
|
// Find the first file in the directory.
|
|
|
|
|
WIN32_FIND_DATA ffd;
|
2024-01-12 12:34:47 +01:00
|
|
|
std::wstring wpath = directory.ToWString();
|
|
|
|
|
wpath += L"\\*";
|
2022-07-06 22:59:47 +01:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
2024-01-12 12:34:47 +01:00
|
|
|
HANDLE hFind = FindFirstFileExFromAppW(wpath.c_str(), FindExInfoStandard, &ffd, FindExSearchNameMatch, NULL, 0);
|
2022-07-06 22:59:47 +01:00
|
|
|
#else
|
2024-01-12 12:34:47 +01:00
|
|
|
HANDLE hFind = FindFirstFileEx(wpath.c_str(), FindExInfoStandard, &ffd, FindExSearchNameMatch, NULL, 0);
|
2022-07-06 22:59:47 +01:00
|
|
|
#endif
|
2012-10-31 13:23:16 +01:00
|
|
|
if (hFind == INVALID_HANDLE_VALUE) {
|
2023-05-02 00:09:22 +04:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
2023-04-30 08:54:54 +04:00
|
|
|
// This step just to avoid empty results by adding fake folders
|
2023-05-02 00:09:22 +04:00
|
|
|
// it will help also to navigate back between selected folder
|
|
|
|
|
// we must ignore this function for any request other than UI navigation
|
|
|
|
|
if (GetFakeFolders(directory, files, filter, filters))
|
2023-04-28 23:22:17 +04:00
|
|
|
return true;
|
|
|
|
|
#endif
|
2022-10-09 09:33:39 -07:00
|
|
|
return false;
|
2012-10-31 13:23:16 +01:00
|
|
|
}
|
2021-07-19 10:31:48 +02:00
|
|
|
do {
|
2013-08-26 18:59:08 +02:00
|
|
|
const std::string virtualName = ConvertWStringToUTF8(ffd.cFileName);
|
2012-10-31 13:23:16 +01:00
|
|
|
// check for "." and ".."
|
2021-07-19 10:31:48 +02:00
|
|
|
if (!(flags & GETFILES_GET_NAVIGATION_ENTRIES) && (virtualName == "." || virtualName == ".."))
|
2012-10-31 13:23:16 +01:00
|
|
|
continue;
|
2015-11-15 22:36:13 -08:00
|
|
|
// Remove dotfiles (optional with flag.)
|
2021-07-19 10:31:48 +02:00
|
|
|
if (!(flags & GETFILES_GETHIDDEN)) {
|
2019-06-27 10:37:49 +02:00
|
|
|
if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2012-10-31 13:34:27 +01:00
|
|
|
|
2024-11-29 10:39:30 +01:00
|
|
|
if (!startsWith(virtualName, prefix)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-30 02:43:33 +01:00
|
|
|
if (LOG_IO) {
|
|
|
|
|
// INFO_LOG(Log::System, "GetFilesInDir item %s", virtualName.c_str());
|
2024-11-29 11:13:53 +01:00
|
|
|
}
|
|
|
|
|
|
2012-10-31 13:23:16 +01:00
|
|
|
FileInfo info;
|
|
|
|
|
info.name = virtualName;
|
2021-05-09 15:25:12 +02:00
|
|
|
info.fullName = directory / virtualName;
|
2012-11-27 16:38:24 +01:00
|
|
|
info.exists = true;
|
2021-07-19 10:31:48 +02:00
|
|
|
info.size = ((uint64_t)ffd.nFileSizeHigh << 32) | ffd.nFileSizeLow;
|
|
|
|
|
info.isDirectory = (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
|
|
|
|
info.isWritable = (ffd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
|
|
|
|
|
info.atime = FiletimeToStatTime(ffd.ftLastAccessTime);
|
|
|
|
|
info.mtime = FiletimeToStatTime(ffd.ftLastWriteTime);
|
|
|
|
|
info.ctime = FiletimeToStatTime(ffd.ftCreationTime);
|
2022-07-13 23:40:38 -07:00
|
|
|
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
|
|
|
|
|
info.access = 0444; // Read
|
|
|
|
|
} else {
|
|
|
|
|
info.access = 0666; // Read/Write
|
|
|
|
|
}
|
|
|
|
|
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
|
|
|
|
info.access |= 0111; // Execute
|
|
|
|
|
}
|
2012-10-31 13:34:27 +01:00
|
|
|
if (!info.isDirectory) {
|
2021-05-14 22:48:04 -07:00
|
|
|
std::string ext = info.fullName.GetFileExtension();
|
2021-05-10 21:28:51 -07:00
|
|
|
if (!ext.empty()) {
|
|
|
|
|
ext = ext.substr(1); // Remove the dot.
|
|
|
|
|
if (filter && filters.find(ext) == filters.end()) {
|
2012-10-31 13:34:27 +01:00
|
|
|
continue;
|
2021-05-10 21:28:51 -07:00
|
|
|
}
|
2012-10-31 13:34:27 +01:00
|
|
|
}
|
|
|
|
|
}
|
2021-07-19 10:31:48 +02:00
|
|
|
files->push_back(info);
|
2012-10-31 13:23:16 +01:00
|
|
|
} while (FindNextFile(hFind, &ffd) != 0);
|
|
|
|
|
FindClose(hFind);
|
2012-03-24 23:39:19 +01:00
|
|
|
#else
|
2021-07-19 10:31:48 +02:00
|
|
|
struct dirent *result = NULL;
|
|
|
|
|
DIR *dirp = opendir(directory.c_str());
|
|
|
|
|
if (!dirp)
|
2022-10-09 09:33:39 -07:00
|
|
|
return false;
|
2021-07-19 10:31:48 +02:00
|
|
|
while ((result = readdir(dirp))) {
|
|
|
|
|
const std::string virtualName(result->d_name);
|
|
|
|
|
// check for "." and ".."
|
|
|
|
|
if (!(flags & GETFILES_GET_NAVIGATION_ENTRIES) && (virtualName == "." || virtualName == ".."))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Remove dotfiles (optional with flag.)
|
|
|
|
|
if (!(flags & GETFILES_GETHIDDEN)) {
|
|
|
|
|
if (virtualName[0] == '.')
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-29 10:39:30 +01:00
|
|
|
if (!startsWith(virtualName, prefix)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-19 10:31:48 +02:00
|
|
|
// Let's just reuse GetFileInfo. We're calling stat anyway to get isDirectory information.
|
|
|
|
|
Path fullName = directory / virtualName;
|
|
|
|
|
|
|
|
|
|
FileInfo info;
|
2021-07-19 20:43:10 +02:00
|
|
|
info.name = virtualName;
|
2021-07-19 10:31:48 +02:00
|
|
|
if (!GetFileInfo(fullName, &info)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!info.isDirectory) {
|
|
|
|
|
std::string ext = info.fullName.GetFileExtension();
|
|
|
|
|
if (!ext.empty()) {
|
|
|
|
|
ext = ext.substr(1); // Remove the dot.
|
|
|
|
|
if (filter && filters.find(ext) == filters.end()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
files->push_back(info);
|
2012-10-31 13:23:16 +01:00
|
|
|
}
|
|
|
|
|
closedir(dirp);
|
2012-03-24 23:39:19 +01:00
|
|
|
#endif
|
2021-07-19 10:31:48 +02:00
|
|
|
std::sort(files->begin(), files->end());
|
2024-11-29 16:00:34 +01:00
|
|
|
if (LOG_IO) {
|
|
|
|
|
INFO_LOG(Log::System, "GetFilesInDir: Found %d files", (int)files->size());
|
|
|
|
|
}
|
2021-07-19 10:31:48 +02:00
|
|
|
return true;
|
2012-03-24 23:39:19 +01:00
|
|
|
}
|
|
|
|
|
|
2021-07-19 10:31:48 +02:00
|
|
|
#if PPSSPP_PLATFORM(WINDOWS)
|
2013-06-27 16:20:18 +02:00
|
|
|
// Returns a vector with the device names
|
2024-11-27 15:14:03 +01:00
|
|
|
std::vector<std::string> GetWindowsDrives() {
|
2013-06-27 16:20:18 +02:00
|
|
|
std::vector<std::string> drives;
|
|
|
|
|
|
2022-07-06 22:59:47 +01:00
|
|
|
#if PPSSPP_PLATFORM(UWP)
|
|
|
|
|
DWORD logicaldrives = GetLogicalDrives();
|
|
|
|
|
for (int i = 0; i < 26; i++)
|
|
|
|
|
{
|
|
|
|
|
if (logicaldrives & (1 << i))
|
|
|
|
|
{
|
2022-10-17 23:13:18 +02:00
|
|
|
CHAR driveName[] = { (CHAR)(TEXT('A') + i), TEXT(':'), TEXT('\\'), TEXT('\0') };
|
2022-07-06 22:59:47 +01:00
|
|
|
std::string str(driveName);
|
|
|
|
|
drives.push_back(driveName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return drives;
|
|
|
|
|
#else
|
2013-06-27 16:20:18 +02:00
|
|
|
const DWORD buffsize = GetLogicalDriveStrings(0, NULL);
|
2020-09-29 18:36:59 +02:00
|
|
|
std::vector<wchar_t> buff(buffsize);
|
2024-11-27 15:14:03 +01:00
|
|
|
if (GetLogicalDriveStrings(buffsize, buff.data()) == buffsize - 1) {
|
2013-06-27 16:20:18 +02:00
|
|
|
auto drive = buff.data();
|
2024-11-27 15:14:03 +01:00
|
|
|
while (*drive) {
|
2013-08-26 18:59:08 +02:00
|
|
|
std::string str(ConvertWStringToUTF8(drive));
|
2013-06-27 16:20:18 +02:00
|
|
|
str.pop_back(); // we don't want the final backslash
|
|
|
|
|
str += "/";
|
|
|
|
|
drives.push_back(str);
|
|
|
|
|
// advance to next drive
|
|
|
|
|
while (*drive++) {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return drives;
|
2021-07-19 10:31:48 +02:00
|
|
|
#endif // PPSSPP_PLATFORM(UWP)
|
2013-06-27 16:20:18 +02:00
|
|
|
}
|
2021-07-19 10:31:48 +02:00
|
|
|
#endif // PPSSPP_PLATFORM(WINDOWS)
|
2021-04-25 20:38:22 +02:00
|
|
|
|
2021-04-25 20:52:29 +02:00
|
|
|
} // namespace File
|