mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Merge pull request #14411 from hrydgard/file-util-cleanup
FileUtil cleanup
This commit is contained in:
commit
f818e514f2
37 changed files with 217 additions and 308 deletions
|
@ -119,7 +119,7 @@ static std::vector<int> ParseCPUList(const std::string &filename) {
|
|||
std::string data;
|
||||
std::vector<int> results;
|
||||
|
||||
if (readFileToString(true, filename.c_str(), data)) {
|
||||
if (File::ReadFileToString(true, filename.c_str(), data)) {
|
||||
std::vector<std::string> ranges;
|
||||
SplitString(data, ',', ranges);
|
||||
for (auto range : ranges) {
|
||||
|
|
|
@ -11,7 +11,7 @@ JsonReader::JsonReader(const std::string &filename) {
|
|||
parse();
|
||||
} else {
|
||||
// Okay, try to read on the local file system
|
||||
buffer_ = (char *)ReadLocalFile(filename.c_str(), &buf_size);
|
||||
buffer_ = (char *)File::ReadLocalFile(filename.c_str(), &buf_size);
|
||||
if (buffer_) {
|
||||
parse();
|
||||
} else {
|
||||
|
|
|
@ -72,7 +72,7 @@ std::string I18NRepo::GetIniPath(const std::string &languageID) const {
|
|||
}
|
||||
|
||||
bool I18NRepo::IniExists(const std::string &languageID) const {
|
||||
FileInfo info;
|
||||
File::FileInfo info;
|
||||
if (!VFSGetFileInfo(GetIniPath(languageID).c_str(), &info))
|
||||
return false;
|
||||
if (!info.exists)
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "Common/Data/Encoding/Utf8.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Common/File/DirListing.h"
|
||||
#include "Common/File/FileUtil.h"
|
||||
|
||||
#if !defined(__linux__) && !defined(_WIN32) && !defined(__QNX__)
|
||||
#define stat64 stat
|
||||
|
@ -33,18 +34,20 @@
|
|||
#define fileno
|
||||
#endif // HAVE_LIBNX
|
||||
|
||||
// Returns true if filename is a directory
|
||||
bool isDirectory(const std::string & filename) {
|
||||
FileInfo info;
|
||||
getFileInfo(filename.c_str(), &info);
|
||||
return info.isDirectory;
|
||||
}
|
||||
namespace File {
|
||||
|
||||
bool getFileInfo(const char *path, FileInfo * fileInfo) {
|
||||
bool GetFileInfo(const char *path, FileInfo * fileInfo) {
|
||||
// TODO: Expand relative paths?
|
||||
fileInfo->fullName = path;
|
||||
|
||||
#ifdef _WIN32
|
||||
auto 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);
|
||||
};
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrs;
|
||||
if (!GetFileAttributesExW(ConvertUTF8ToWString(path).c_str(), GetFileExInfoStandard, &attrs)) {
|
||||
fileInfo->size = 0;
|
||||
|
@ -56,16 +59,25 @@ bool getFileInfo(const char *path, FileInfo * fileInfo) {
|
|||
fileInfo->isDirectory = (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
fileInfo->isWritable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
|
||||
fileInfo->exists = true;
|
||||
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
|
||||
}
|
||||
#else
|
||||
|
||||
std::string copy(path);
|
||||
|
||||
#if (defined __ANDROID__) && (__ANDROID_API__ < 21)
|
||||
struct stat file_info;
|
||||
int result = stat(copy.c_str(), &file_info);
|
||||
int result = stat(path, &file_info);
|
||||
#else
|
||||
struct stat64 file_info;
|
||||
int result = stat64(copy.c_str(), &file_info);
|
||||
int result = stat64(path, &file_info);
|
||||
#endif
|
||||
if (result < 0) {
|
||||
fileInfo->exists = false;
|
||||
|
@ -76,6 +88,10 @@ bool getFileInfo(const char *path, FileInfo * fileInfo) {
|
|||
fileInfo->isWritable = false;
|
||||
fileInfo->size = file_info.st_size;
|
||||
fileInfo->exists = true;
|
||||
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;
|
||||
// HACK: approximation
|
||||
if (file_info.st_mode & 0200)
|
||||
fileInfo->isWritable = true;
|
||||
|
@ -83,14 +99,16 @@ bool getFileInfo(const char *path, FileInfo * fileInfo) {
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string getFileExtension(const std::string & fn) {
|
||||
int pos = (int)fn.rfind(".");
|
||||
if (pos < 0) return "";
|
||||
std::string ext = fn.substr(pos + 1);
|
||||
for (size_t i = 0; i < ext.size(); i++) {
|
||||
ext[i] = tolower(ext[i]);
|
||||
bool GetModifTime(const std::string & filename, tm & return_time) {
|
||||
memset(&return_time, 0, sizeof(return_time));
|
||||
FileInfo info;
|
||||
if (GetFileInfo(filename.c_str(), &info)) {
|
||||
time_t t = info.mtime;
|
||||
localtime_r((time_t*)&t, &return_time);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
|
||||
bool FileInfo::operator <(const FileInfo & other) const {
|
||||
|
@ -104,7 +122,7 @@ bool FileInfo::operator <(const FileInfo & other) const {
|
|||
return false;
|
||||
}
|
||||
|
||||
size_t getFilesInDir(const char *directory, std::vector<FileInfo> * files, const char *filter, int flags) {
|
||||
size_t GetFilesInDir(const char *directory, std::vector<FileInfo> * files, const char *filter, int flags) {
|
||||
size_t foundEntries = 0;
|
||||
std::set<std::string> filters;
|
||||
if (filter) {
|
||||
|
@ -172,12 +190,12 @@ size_t getFilesInDir(const char *directory, std::vector<FileInfo> * files, const
|
|||
dir.append("/");
|
||||
|
||||
info.fullName = dir + virtualName;
|
||||
info.isDirectory = isDirectory(info.fullName);
|
||||
info.isDirectory = IsDirectory(info.fullName);
|
||||
info.exists = true;
|
||||
info.size = 0;
|
||||
info.isWritable = false; // TODO - implement some kind of check
|
||||
if (!info.isDirectory) {
|
||||
std::string ext = getFileExtension(info.fullName);
|
||||
std::string ext = GetFileExtension(info.fullName);
|
||||
if (filter) {
|
||||
if (filters.find(ext) == filters.end())
|
||||
continue;
|
||||
|
@ -199,25 +217,25 @@ size_t getFilesInDir(const char *directory, std::vector<FileInfo> * files, const
|
|||
return foundEntries;
|
||||
}
|
||||
|
||||
int64_t getDirectoryRecursiveSize(const std::string & path, const char *filter, int flags) {
|
||||
int64_t GetDirectoryRecursiveSize(const std::string & path, const char *filter, int flags) {
|
||||
std::vector<FileInfo> fileInfo;
|
||||
getFilesInDir(path.c_str(), &fileInfo, filter, flags);
|
||||
GetFilesInDir(path.c_str(), &fileInfo, filter, flags);
|
||||
int64_t sizeSum = 0;
|
||||
// Note: getFileInDir does not fill in fileSize properly.
|
||||
// Note: GetFilesInDir does not fill in fileSize properly.
|
||||
for (size_t i = 0; i < fileInfo.size(); i++) {
|
||||
FileInfo finfo;
|
||||
getFileInfo(fileInfo[i].fullName.c_str(), &finfo);
|
||||
GetFileInfo(fileInfo[i].fullName.c_str(), &finfo);
|
||||
if (!finfo.isDirectory)
|
||||
sizeSum += finfo.size;
|
||||
else
|
||||
sizeSum += getDirectoryRecursiveSize(finfo.fullName, filter, flags);
|
||||
sizeSum += GetDirectoryRecursiveSize(finfo.fullName, filter, flags);
|
||||
}
|
||||
return sizeSum;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
// Returns a vector with the device names
|
||||
std::vector<std::string> getWindowsDrives()
|
||||
std::vector<std::string> GetWindowsDrives()
|
||||
{
|
||||
#if PPSSPP_PLATFORM(UWP)
|
||||
return std::vector<std::string>(); // TODO UWP http://stackoverflow.com/questions/37404405/how-to-get-logical-drives-names-in-windows-10
|
||||
|
@ -244,3 +262,5 @@ std::vector<std::string> getWindowsDrives()
|
|||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace File
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
|
||||
// Beginnings of a directory utility system. TODO: Improve.
|
||||
|
||||
namespace File {
|
||||
|
||||
struct FileInfo {
|
||||
std::string name;
|
||||
std::string fullName;
|
||||
|
@ -17,19 +19,24 @@ struct FileInfo {
|
|||
bool isWritable;
|
||||
uint64_t size;
|
||||
|
||||
uint64_t atime;
|
||||
uint64_t mtime;
|
||||
uint64_t ctime;
|
||||
uint32_t access; // st_mode & 0x1ff
|
||||
|
||||
bool operator <(const FileInfo &other) const;
|
||||
};
|
||||
|
||||
std::string getFileExtension(const std::string &fn);
|
||||
bool getFileInfo(const char *path, FileInfo *fileInfo);
|
||||
FILE *openCFile(const std::string &filename, const char *mode);
|
||||
bool GetFileInfo(const char *path, FileInfo *fileInfo);
|
||||
|
||||
enum {
|
||||
GETFILES_GETHIDDEN = 1
|
||||
};
|
||||
size_t getFilesInDir(const char *directory, std::vector<FileInfo> *files, const char *filter = nullptr, int flags = 0);
|
||||
int64_t getDirectoryRecursiveSize(const std::string &path, const char *filter = nullptr, int flags = 0);
|
||||
size_t GetFilesInDir(const char *directory, std::vector<FileInfo> *files, const char *filter = nullptr, int flags = 0);
|
||||
int64_t GetDirectoryRecursiveSize(const std::string &path, const char *filter = nullptr, int flags = 0);
|
||||
|
||||
#ifdef _WIN32
|
||||
std::vector<std::string> getWindowsDrives();
|
||||
std::vector<std::string> GetWindowsDrives();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
@ -377,7 +377,6 @@ bool CreateFullPath(const std::string &path)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Deletes a directory filename, returns true on success
|
||||
bool DeleteDir(const std::string &filename)
|
||||
{
|
||||
|
@ -501,73 +500,6 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
static int64_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
|
||||
|
||||
// Returns file attributes.
|
||||
bool GetFileDetails(const std::string &filename, FileDetails *details) {
|
||||
#ifdef _WIN32
|
||||
WIN32_FILE_ATTRIBUTE_DATA attr;
|
||||
if (!GetFileAttributesEx(ConvertUTF8ToWString(filename).c_str(), GetFileExInfoStandard, &attr))
|
||||
return false;
|
||||
details->isDirectory = (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
details->size = ((uint64_t)attr.nFileSizeHigh << 32) | (uint64_t)attr.nFileSizeLow;
|
||||
details->atime = FiletimeToStatTime(attr.ftLastAccessTime);
|
||||
details->mtime = FiletimeToStatTime(attr.ftLastWriteTime);
|
||||
details->ctime = FiletimeToStatTime(attr.ftCreationTime);
|
||||
if (attr.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
|
||||
details->access = 0444; // Read
|
||||
} else {
|
||||
details->access = 0666; // Read/Write
|
||||
}
|
||||
if (attr.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
|
||||
details->access |= 0111; // Execute
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
if (!Exists(filename)) {
|
||||
return false;
|
||||
}
|
||||
#if __ANDROID__ && __ANDROID_API__ < 21
|
||||
struct stat buf;
|
||||
if (stat(filename.c_str(), &buf) == 0) {
|
||||
#else
|
||||
struct stat64 buf;
|
||||
if (stat64(filename.c_str(), &buf) == 0) {
|
||||
#endif
|
||||
details->size = buf.st_size;
|
||||
details->isDirectory = S_ISDIR(buf.st_mode);
|
||||
details->atime = buf.st_atime;
|
||||
details->mtime = buf.st_mtime;
|
||||
details->ctime = buf.st_ctime;
|
||||
details->access = buf.st_mode & 0x1ff;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool GetModifTime(const std::string &filename, tm &return_time) {
|
||||
memset(&return_time, 0, sizeof(return_time));
|
||||
FileDetails details;
|
||||
if (GetFileDetails(filename, &details)) {
|
||||
time_t t = details.mtime;
|
||||
localtime_r((time_t*)&t, &return_time);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string GetDir(const std::string &path) {
|
||||
if (path == "/")
|
||||
return path;
|
||||
|
@ -594,6 +526,18 @@ std::string GetFilename(std::string path) {
|
|||
return path;
|
||||
}
|
||||
|
||||
std::string GetFileExtension(const std::string & fn) {
|
||||
size_t pos = fn.rfind(".");
|
||||
if (pos == std::string::npos) {
|
||||
return "";
|
||||
}
|
||||
std::string ext = fn.substr(pos + 1);
|
||||
for (size_t i = 0; i < ext.size(); i++) {
|
||||
ext[i] = tolower(ext[i]);
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
|
||||
// Returns the size of file (64bit)
|
||||
// TODO: Add a way to return an error.
|
||||
uint64_t GetFileSize(const std::string &filename) {
|
||||
|
@ -668,7 +612,6 @@ uint64_t GetFileSize(FILE *f)
|
|||
bool CreateEmptyFile(const std::string &filename)
|
||||
{
|
||||
INFO_LOG(COMMON, "CreateEmptyFile: %s", filename.c_str());
|
||||
|
||||
FILE *pFile = OpenCFile(filename, "wb");
|
||||
if (!pFile) {
|
||||
ERROR_LOG(COMMON, "CreateEmptyFile: failed %s: %s", filename.c_str(), GetLastErrorMsg().c_str());
|
||||
|
@ -752,47 +695,7 @@ bool DeleteDirRecursively(const std::string &directory)
|
|||
return File::DeleteDir(directory);
|
||||
}
|
||||
|
||||
|
||||
// Create directory and copy contents (does not overwrite existing files)
|
||||
void CopyDir(const std::string &source_path, const std::string &dest_path)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
if (source_path == dest_path) return;
|
||||
if (!File::Exists(source_path)) return;
|
||||
if (!File::Exists(dest_path)) File::CreateFullPath(dest_path);
|
||||
|
||||
struct dirent *result = NULL;
|
||||
DIR *dirp = opendir(source_path.c_str());
|
||||
if (!dirp) return;
|
||||
|
||||
while ((result = readdir(dirp)))
|
||||
{
|
||||
const std::string virtualName(result->d_name);
|
||||
// check for "." and ".."
|
||||
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
|
||||
((virtualName[0] == '.') && (virtualName[1] == '.') &&
|
||||
(virtualName[2] == '\0')))
|
||||
continue;
|
||||
|
||||
std::string source, dest;
|
||||
source = source_path + virtualName;
|
||||
dest = dest_path + virtualName;
|
||||
if (IsDirectory(source))
|
||||
{
|
||||
source += '/';
|
||||
dest += '/';
|
||||
if (!File::Exists(dest)) File::CreateFullPath(dest);
|
||||
CopyDir(source, dest);
|
||||
}
|
||||
else if (!File::Exists(dest)) File::Copy(source, dest);
|
||||
}
|
||||
closedir(dirp);
|
||||
#else
|
||||
ERROR_LOG(COMMON, "CopyDir not supported on this platform");
|
||||
#endif
|
||||
}
|
||||
|
||||
void openIniFile(const std::string& fileName) {
|
||||
void OpenFileInEditor(const std::string& fileName) {
|
||||
#if defined(_WIN32)
|
||||
#if PPSSPP_PLATFORM(UWP)
|
||||
// Do nothing.
|
||||
|
@ -984,9 +887,7 @@ bool IOFile::Resize(uint64_t size)
|
|||
return m_good;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool readFileToString(bool text_file, const char *filename, std::string & str)
|
||||
bool ReadFileToString(bool text_file, const char *filename, std::string & str)
|
||||
{
|
||||
FILE *f = File::OpenCFile(filename, text_file ? "r" : "rb");
|
||||
if (!f)
|
||||
|
@ -1027,7 +928,7 @@ uint8_t *ReadLocalFile(const char *filename, size_t * size) {
|
|||
return contents;
|
||||
}
|
||||
|
||||
bool writeStringToFile(bool text_file, const std::string &str, const char *filename)
|
||||
bool WriteStringToFile(bool text_file, const std::string &str, const char *filename)
|
||||
{
|
||||
FILE *f = File::OpenCFile(filename, text_file ? "w" : "wb");
|
||||
if (!f)
|
||||
|
@ -1042,7 +943,7 @@ bool writeStringToFile(bool text_file, const std::string &str, const char *filen
|
|||
return true;
|
||||
}
|
||||
|
||||
bool writeDataToFile(bool text_file, const void* data, const unsigned int size, const char *filename)
|
||||
bool WriteDataToFile(bool text_file, const void* data, const unsigned int size, const char *filename)
|
||||
{
|
||||
FILE *f = File::OpenCFile(filename, text_file ? "w" : "wb");
|
||||
if (!f)
|
||||
|
@ -1056,3 +957,5 @@ bool writeDataToFile(bool text_file, const void* data, const unsigned int size,
|
|||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace File
|
||||
|
|
|
@ -36,16 +36,7 @@ inline struct tm* localtime_r(const time_t *clock, struct tm *result) {
|
|||
|
||||
namespace File {
|
||||
|
||||
struct FileDetails {
|
||||
bool isDirectory;
|
||||
uint64_t size;
|
||||
uint64_t atime;
|
||||
uint64_t mtime;
|
||||
uint64_t ctime;
|
||||
uint32_t access; // st_mode & 0x1ff
|
||||
};
|
||||
|
||||
// Mostly to handle utf-8 filenames better on Windows.
|
||||
// Mostly to handle UTF-8 filenames better on Windows.
|
||||
FILE *OpenCFile(const std::string &filename, const char *mode);
|
||||
bool OpenCPPFile(std::fstream & stream, const std::string &filename, std::ios::openmode mode);
|
||||
|
||||
|
@ -58,8 +49,8 @@ bool Exists(const std::string &filename);
|
|||
// Returns true if filename is a directory
|
||||
bool IsDirectory(const std::string &filename);
|
||||
|
||||
// Returns file attributes.
|
||||
bool GetFileDetails(const std::string &filename, FileDetails *details);
|
||||
// Parses the extension out from a filename.
|
||||
std::string GetFileExtension(const std::string &filename);
|
||||
|
||||
// Extracts the directory from a path.
|
||||
std::string GetDir(const std::string &path);
|
||||
|
@ -87,6 +78,7 @@ bool CreateFullPath(const std::string &fullPath);
|
|||
bool Delete(const std::string &filename);
|
||||
|
||||
// Deletes a directory filename, returns true on success
|
||||
// Directory must be empty.
|
||||
bool DeleteDir(const std::string &filename);
|
||||
|
||||
// renames file srcFilename to destFilename, returns true on success
|
||||
|
@ -101,18 +93,11 @@ bool CreateEmptyFile(const std::string &filename);
|
|||
// deletes the given directory and anything under it. Returns true on success.
|
||||
bool DeleteDirRecursively(const std::string &directory);
|
||||
|
||||
// Returns the current directory
|
||||
std::string GetCurrentDir();
|
||||
|
||||
// Create directory and copy contents (does not overwrite existing files)
|
||||
void CopyDir(const std::string &source_path, const std::string &dest_path);
|
||||
|
||||
// Opens ini file (cheats, texture replacements etc.)
|
||||
void openIniFile(const std::string& fileName);
|
||||
|
||||
// Set the current directory to given directory
|
||||
bool SetCurrentDir(const std::string &directory);
|
||||
// TODO: Belongs in System or something.
|
||||
void OpenFileInEditor(const std::string& fileName);
|
||||
|
||||
// TODO: Belongs in System or something.
|
||||
const std::string &GetExeDirectory();
|
||||
|
||||
|
||||
|
@ -191,14 +176,14 @@ private:
|
|||
bool m_good;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
// TODO: Refactor, this was moved from the old file_util.cpp.
|
||||
|
||||
// Whole-file reading/writing
|
||||
bool writeStringToFile(bool text_file, const std::string &str, const char *filename);
|
||||
bool writeDataToFile(bool text_file, const void* data, const unsigned int size, const char *filename);
|
||||
bool WriteStringToFile(bool text_file, const std::string &str, const char *filename);
|
||||
bool WriteDataToFile(bool text_file, const void* data, const unsigned int size, const char *filename);
|
||||
|
||||
bool readFileToString(bool text_file, const char *filename, std::string &str);
|
||||
bool ReadFileToString(bool text_file, const char *filename, std::string &str);
|
||||
// Return value must be delete[]-d.
|
||||
uint8_t *ReadLocalFile(const char *filename, size_t *size);
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "Common/Net/URL.h"
|
||||
|
||||
#include "Common/File/PathBrowser.h"
|
||||
#include "Common/File/FileUtil.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Common/TimeUtil.h"
|
||||
#include "Common/Log.h"
|
||||
|
@ -15,7 +16,7 @@
|
|||
|
||||
#include "Core/System.h"
|
||||
|
||||
bool LoadRemoteFileList(const std::string &url, bool *cancel, std::vector<FileInfo> &files) {
|
||||
bool LoadRemoteFileList(const std::string &url, bool *cancel, std::vector<File::FileInfo> &files) {
|
||||
http::Client http;
|
||||
Buffer result;
|
||||
int code = 500;
|
||||
|
@ -77,7 +78,7 @@ bool LoadRemoteFileList(const std::string &url, bool *cancel, std::vector<FileIn
|
|||
if (item == baseURL.Resource())
|
||||
continue;
|
||||
|
||||
FileInfo info;
|
||||
File::FileInfo info;
|
||||
info.name = item;
|
||||
info.fullName = baseURL.Relative(item).ToString();
|
||||
info.isDirectory = endsWith(item, "/");
|
||||
|
@ -91,7 +92,7 @@ bool LoadRemoteFileList(const std::string &url, bool *cancel, std::vector<FileIn
|
|||
return !files.empty();
|
||||
}
|
||||
|
||||
std::vector<FileInfo> ApplyFilter(std::vector<FileInfo> files, const char *filter) {
|
||||
std::vector<File::FileInfo> ApplyFilter(std::vector<File::FileInfo> files, const char *filter) {
|
||||
std::set<std::string> filters;
|
||||
if (filter) {
|
||||
std::string tmp;
|
||||
|
@ -107,10 +108,10 @@ std::vector<FileInfo> ApplyFilter(std::vector<FileInfo> files, const char *filte
|
|||
filters.insert(std::move(tmp));
|
||||
}
|
||||
|
||||
auto pred = [&](const FileInfo &info) {
|
||||
auto pred = [&](const File::FileInfo &info) {
|
||||
if (info.isDirectory || !filter)
|
||||
return false;
|
||||
std::string ext = getFileExtension(info.fullName);
|
||||
std::string ext = File::GetFileExtension(info.fullName);
|
||||
return filters.find(ext) == filters.end();
|
||||
};
|
||||
files.erase(std::remove_if(files.begin(), files.end(), pred), files.end());
|
||||
|
@ -174,7 +175,7 @@ void PathBrowser::HandlePath() {
|
|||
setCurrentThreadName("PathBrowser");
|
||||
|
||||
std::unique_lock<std::mutex> guard(pendingLock_);
|
||||
std::vector<FileInfo> results;
|
||||
std::vector<File::FileInfo> results;
|
||||
std::string lastPath;
|
||||
while (!pendingStop_) {
|
||||
while (lastPath == pendingPath_ && !pendingCancel_) {
|
||||
|
@ -233,7 +234,7 @@ std::string PathBrowser::GetFriendlyPath() const {
|
|||
return str;
|
||||
}
|
||||
|
||||
bool PathBrowser::GetListing(std::vector<FileInfo> &fileInfo, const char *filter, bool *cancel) {
|
||||
bool PathBrowser::GetListing(std::vector<File::FileInfo> &fileInfo, const char *filter, bool *cancel) {
|
||||
std::unique_lock<std::mutex> guard(pendingLock_);
|
||||
while (!IsListingReady() && (!cancel || !*cancel)) {
|
||||
// In case cancel changes, just sleep.
|
||||
|
@ -245,11 +246,11 @@ bool PathBrowser::GetListing(std::vector<FileInfo> &fileInfo, const char *filter
|
|||
#ifdef _WIN32
|
||||
if (path_ == "/") {
|
||||
// Special path that means root of file system.
|
||||
std::vector<std::string> drives = getWindowsDrives();
|
||||
std::vector<std::string> drives = File::GetWindowsDrives();
|
||||
for (auto drive = drives.begin(); drive != drives.end(); ++drive) {
|
||||
if (*drive == "A:/" || *drive == "B:/")
|
||||
continue;
|
||||
FileInfo fake;
|
||||
File::FileInfo fake;
|
||||
fake.fullName = *drive;
|
||||
fake.name = *drive;
|
||||
fake.isDirectory = true;
|
||||
|
@ -265,7 +266,7 @@ bool PathBrowser::GetListing(std::vector<FileInfo> &fileInfo, const char *filter
|
|||
fileInfo = ApplyFilter(pendingFiles_, filter);
|
||||
return true;
|
||||
} else {
|
||||
getFilesInDir(path_.c_str(), &fileInfo, filter);
|
||||
File::GetFilesInDir(path_.c_str(), &fileInfo, filter);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
|
||||
void SetPath(const std::string &path);
|
||||
bool IsListingReady();
|
||||
bool GetListing(std::vector<FileInfo> &fileInfo, const char *filter = nullptr, bool *cancel = nullptr);
|
||||
bool GetListing(std::vector<File::FileInfo> &fileInfo, const char *filter = nullptr, bool *cancel = nullptr);
|
||||
|
||||
bool CanNavigateUp();
|
||||
void NavigateUp();
|
||||
|
@ -41,7 +41,7 @@ private:
|
|||
|
||||
std::string path_;
|
||||
std::string pendingPath_;
|
||||
std::vector<FileInfo> pendingFiles_;
|
||||
std::vector<File::FileInfo> pendingFiles_;
|
||||
std::condition_variable pendingCond_;
|
||||
std::mutex pendingLock_;
|
||||
std::thread pendingThread_;
|
||||
|
|
|
@ -42,7 +42,7 @@ ZipAssetReader::ZipAssetReader(const char *zip_file, const char *in_zip_path) {
|
|||
ERROR_LOG(IO, "Failed to open %s as a zip file", zip_file);
|
||||
}
|
||||
|
||||
std::vector<FileInfo> info;
|
||||
std::vector<File::FileInfo> info;
|
||||
GetFileListing("assets", &info, 0);
|
||||
for (size_t i = 0; i < info.size(); i++) {
|
||||
if (info[i].isDirectory) {
|
||||
|
@ -64,7 +64,7 @@ uint8_t *ZipAssetReader::ReadAsset(const char *path, size_t *size) {
|
|||
return ReadFromZip(zip_file_, temp_path, size);
|
||||
}
|
||||
|
||||
bool ZipAssetReader::GetFileListing(const char *orig_path, std::vector<FileInfo> *listing, const char *filter = 0) {
|
||||
bool ZipAssetReader::GetFileListing(const char *orig_path, std::vector<File::FileInfo> *listing, const char *filter = 0) {
|
||||
char path[1024];
|
||||
strcpy(path, in_zip_path_);
|
||||
strcat(path, orig_path);
|
||||
|
@ -111,7 +111,7 @@ bool ZipAssetReader::GetFileListing(const char *orig_path, std::vector<FileInfo>
|
|||
}
|
||||
|
||||
for (auto diter = directories.begin(); diter != directories.end(); ++diter) {
|
||||
FileInfo info;
|
||||
File::FileInfo info;
|
||||
info.name = *diter;
|
||||
info.fullName = std::string(path);
|
||||
if (info.fullName[info.fullName.size() - 1] == '/')
|
||||
|
@ -127,7 +127,7 @@ bool ZipAssetReader::GetFileListing(const char *orig_path, std::vector<FileInfo>
|
|||
}
|
||||
|
||||
for (auto fiter = files.begin(); fiter != files.end(); ++fiter) {
|
||||
FileInfo info;
|
||||
File::FileInfo info;
|
||||
info.name = *fiter;
|
||||
info.fullName = std::string(path);
|
||||
if (info.fullName[info.fullName.size() - 1] == '/')
|
||||
|
@ -137,7 +137,7 @@ bool ZipAssetReader::GetFileListing(const char *orig_path, std::vector<FileInfo>
|
|||
info.exists = true;
|
||||
info.isWritable = false;
|
||||
info.isDirectory = false;
|
||||
std::string ext = getFileExtension(info.fullName);
|
||||
std::string ext = File::GetFileExtension(info.fullName);
|
||||
if (filter) {
|
||||
if (filters.find(ext) == filters.end())
|
||||
continue;
|
||||
|
@ -149,7 +149,7 @@ bool ZipAssetReader::GetFileListing(const char *orig_path, std::vector<FileInfo>
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ZipAssetReader::GetFileInfo(const char *path, FileInfo *info) {
|
||||
bool ZipAssetReader::GetFileInfo(const char *path, File::FileInfo *info) {
|
||||
struct zip_stat zstat;
|
||||
char temp_path[1024];
|
||||
strcpy(temp_path, in_zip_path_);
|
||||
|
@ -187,10 +187,10 @@ uint8_t *DirectoryAssetReader::ReadAsset(const char *path, size_t *size) {
|
|||
strcpy(new_path, path_);
|
||||
}
|
||||
strcat(new_path, path);
|
||||
return ReadLocalFile(new_path, size);
|
||||
return File::ReadLocalFile(new_path, size);
|
||||
}
|
||||
|
||||
bool DirectoryAssetReader::GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter = 0)
|
||||
bool DirectoryAssetReader::GetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter = 0)
|
||||
{
|
||||
char new_path[2048];
|
||||
new_path[0] = '\0';
|
||||
|
@ -201,13 +201,13 @@ bool DirectoryAssetReader::GetFileListing(const char *path, std::vector<FileInfo
|
|||
strcpy(new_path, path_);
|
||||
}
|
||||
strcat(new_path, path);
|
||||
FileInfo info;
|
||||
if (!getFileInfo(new_path, &info))
|
||||
File::FileInfo info;
|
||||
if (!File::GetFileInfo(new_path, &info))
|
||||
return false;
|
||||
|
||||
if (info.isDirectory)
|
||||
{
|
||||
getFilesInDir(new_path, listing, filter);
|
||||
File::GetFilesInDir(new_path, listing, filter);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -216,7 +216,7 @@ bool DirectoryAssetReader::GetFileListing(const char *path, std::vector<FileInfo
|
|||
}
|
||||
}
|
||||
|
||||
bool DirectoryAssetReader::GetFileInfo(const char *path, FileInfo *info)
|
||||
bool DirectoryAssetReader::GetFileInfo(const char *path, File::FileInfo *info)
|
||||
{
|
||||
char new_path[2048];
|
||||
new_path[0] = '\0';
|
||||
|
@ -227,5 +227,5 @@ bool DirectoryAssetReader::GetFileInfo(const char *path, FileInfo *info)
|
|||
strcpy(new_path, path_);
|
||||
}
|
||||
strcat(new_path, path);
|
||||
return getFileInfo(new_path, info);
|
||||
return File::GetFileInfo(new_path, info);
|
||||
}
|
||||
|
|
|
@ -9,9 +9,7 @@
|
|||
#include <string>
|
||||
|
||||
#include "Common/File/VFS/VFS.h"
|
||||
|
||||
// Direct readers. deallocate using delete [].
|
||||
uint8_t *ReadLocalFile(const char *filename, size_t *size);
|
||||
#include "Common/File/FileUtil.h"
|
||||
|
||||
class AssetReader {
|
||||
public:
|
||||
|
@ -19,8 +17,8 @@ public:
|
|||
// use delete[]
|
||||
virtual uint8_t *ReadAsset(const char *path, size_t *size) = 0;
|
||||
// Filter support is optional but nice to have
|
||||
virtual bool GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter = 0) = 0;
|
||||
virtual bool GetFileInfo(const char *path, FileInfo *info) = 0;
|
||||
virtual bool GetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter = 0) = 0;
|
||||
virtual bool GetFileInfo(const char *path, File::FileInfo *info) = 0;
|
||||
virtual std::string toString() const = 0;
|
||||
};
|
||||
|
||||
|
@ -32,8 +30,8 @@ public:
|
|||
~ZipAssetReader();
|
||||
// use delete[]
|
||||
virtual uint8_t *ReadAsset(const char *path, size_t *size);
|
||||
virtual bool GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter);
|
||||
virtual bool GetFileInfo(const char *path, FileInfo *info);
|
||||
virtual bool GetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter);
|
||||
virtual bool GetFileInfo(const char *path, File::FileInfo *info);
|
||||
virtual std::string toString() const {
|
||||
return in_zip_path_;
|
||||
}
|
||||
|
@ -49,8 +47,8 @@ public:
|
|||
explicit DirectoryAssetReader(const char *path);
|
||||
// use delete[]
|
||||
virtual uint8_t *ReadAsset(const char *path, size_t *size);
|
||||
virtual bool GetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter);
|
||||
virtual bool GetFileInfo(const char *path, FileInfo *info);
|
||||
virtual bool GetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter);
|
||||
virtual bool GetFileInfo(const char *path, File::FileInfo *info);
|
||||
virtual std::string toString() const {
|
||||
return path_;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ uint8_t *VFSReadFile(const char *filename, size_t *size) {
|
|||
if (IsLocalPath(filename)) {
|
||||
// Local path, not VFS.
|
||||
// INFO_LOG(IO, "Not a VFS path: %s . Reading local file.", filename);
|
||||
return ReadLocalFile(filename, size);
|
||||
return File::ReadLocalFile(filename, size);
|
||||
}
|
||||
|
||||
int fn_len = (int)strlen(filename);
|
||||
|
@ -64,11 +64,11 @@ uint8_t *VFSReadFile(const char *filename, size_t *size) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool VFSGetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter) {
|
||||
bool VFSGetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter) {
|
||||
if (IsLocalPath(path)) {
|
||||
// Local path, not VFS.
|
||||
// INFO_LOG(IO, "Not a VFS path: %s . Reading local directory.", path);
|
||||
getFilesInDir(path, listing, filter);
|
||||
File::GetFilesInDir(path, listing, filter);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -91,11 +91,11 @@ bool VFSGetFileListing(const char *path, std::vector<FileInfo> *listing, const c
|
|||
return false;
|
||||
}
|
||||
|
||||
bool VFSGetFileInfo(const char *path, FileInfo *info) {
|
||||
bool VFSGetFileInfo(const char *path, File::FileInfo *info) {
|
||||
if (IsLocalPath(path)) {
|
||||
// Local path, not VFS.
|
||||
// INFO_LOG(IO, "Not a VFS path: %s . Getting local file info.", path);
|
||||
return getFileInfo(path, info);
|
||||
return File::GetFileInfo(path, info);
|
||||
}
|
||||
|
||||
bool fileSystemFound = false;
|
||||
|
|
|
@ -17,5 +17,5 @@ void VFSShutdown();
|
|||
// Always allocates an extra zero byte at the end, so that it
|
||||
// can be used for text like shader sources.
|
||||
uint8_t *VFSReadFile(const char *filename, size_t *size);
|
||||
bool VFSGetFileListing(const char *path, std::vector<FileInfo> *listing, const char *filter = 0);
|
||||
bool VFSGetFileInfo(const char *filename, FileInfo *fileInfo);
|
||||
bool VFSGetFileListing(const char *path, std::vector<File::FileInfo> *listing, const char *filter = 0);
|
||||
bool VFSGetFileInfo(const char *filename, File::FileInfo *fileInfo);
|
||||
|
|
|
@ -104,7 +104,7 @@ bool glsl_recompile(GLSLProgram *program, std::string *error_message) {
|
|||
program->vshader_mtime = vs.st_mtime;
|
||||
if (!program->vshader_source) {
|
||||
size_t sz;
|
||||
vsh_src.reset((char *)ReadLocalFile(program->vshader_filename, &sz));
|
||||
vsh_src.reset((char *)File::ReadLocalFile(program->vshader_filename, &sz));
|
||||
}
|
||||
} else {
|
||||
program->vshader_mtime = 0;
|
||||
|
@ -114,7 +114,7 @@ bool glsl_recompile(GLSLProgram *program, std::string *error_message) {
|
|||
program->fshader_mtime = fs.st_mtime;
|
||||
if (!program->fshader_source) {
|
||||
size_t sz;
|
||||
fsh_src.reset((char *)ReadLocalFile(program->fshader_filename, &sz));
|
||||
fsh_src.reset((char *)File::ReadLocalFile(program->fshader_filename, &sz));
|
||||
}
|
||||
} else {
|
||||
program->fshader_mtime = 0;
|
||||
|
|
|
@ -794,8 +794,8 @@ u32 DiskCachingFileLoaderCache::CountCachedFiles() {
|
|||
dir = GetSysDirectory(DIRECTORY_CACHE);
|
||||
}
|
||||
|
||||
std::vector<FileInfo> files;
|
||||
return (u32)getFilesInDir(dir.c_str(), &files, "ppdc:");
|
||||
std::vector<File::FileInfo> files;
|
||||
return (u32)GetFilesInDir(dir.c_str(), &files, "ppdc:");
|
||||
}
|
||||
|
||||
void DiskCachingFileLoaderCache::GarbageCollectCacheFiles(u64 goalBytes) {
|
||||
|
@ -811,12 +811,12 @@ void DiskCachingFileLoaderCache::GarbageCollectCacheFiles(u64 goalBytes) {
|
|||
dir = GetSysDirectory(DIRECTORY_CACHE);
|
||||
}
|
||||
|
||||
std::vector<FileInfo> files;
|
||||
getFilesInDir(dir.c_str(), &files, "ppdc:");
|
||||
std::vector<File::FileInfo> files;
|
||||
File::GetFilesInDir(dir.c_str(), &files, "ppdc:");
|
||||
|
||||
u64 remaining = goalBytes;
|
||||
// TODO: Could order by LRU or etc.
|
||||
for (FileInfo file : files) {
|
||||
for (File::FileInfo &file : files) {
|
||||
if (file.isDirectory) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -112,15 +112,15 @@ bool LocalFileLoader::Exists() {
|
|||
#else
|
||||
if (handle_ != INVALID_HANDLE_VALUE || IsDirectory()) {
|
||||
#endif
|
||||
FileInfo info;
|
||||
return getFileInfo(filename_.c_str(), &info);
|
||||
File::FileInfo info;
|
||||
return File::GetFileInfo(filename_.c_str(), &info);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LocalFileLoader::IsDirectory() {
|
||||
FileInfo info;
|
||||
if (getFileInfo(filename_.c_str(), &info)) {
|
||||
File::FileInfo info;
|
||||
if (File::GetFileInfo(filename_.c_str(), &info)) {
|
||||
return info.isDirectory;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -751,15 +751,15 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename) {
|
|||
x.exists = true;
|
||||
|
||||
if (x.type != FILETYPE_DIRECTORY) {
|
||||
File::FileDetails details;
|
||||
if (!File::GetFileDetails(fullName, &details)) {
|
||||
ERROR_LOG(FILESYS, "DirectoryFileSystem::GetFileInfo: GetFileDetails failed: %s", fullName.c_str());
|
||||
File::FileInfo info;
|
||||
if (!File::GetFileInfo(fullName.c_str(), &info)) {
|
||||
ERROR_LOG(FILESYS, "DirectoryFileSystem::GetFileInfo: GetFileInfo failed: %s", fullName.c_str());
|
||||
} else {
|
||||
x.size = details.size;
|
||||
x.access = details.access;
|
||||
time_t atime = details.atime;
|
||||
time_t ctime = details.ctime;
|
||||
time_t mtime = details.mtime;
|
||||
x.size = info.size;
|
||||
x.access = info.access;
|
||||
time_t atime = info.atime;
|
||||
time_t ctime = info.ctime;
|
||||
time_t mtime = info.mtime;
|
||||
|
||||
localtime_r((time_t*)&atime, &x.atime);
|
||||
localtime_r((time_t*)&ctime, &x.ctime);
|
||||
|
@ -1095,7 +1095,7 @@ PSPFileInfo VFSFileSystem::GetFileInfo(std::string filename) {
|
|||
x.name = filename;
|
||||
|
||||
std::string fullName = GetLocalPath(filename);
|
||||
FileInfo fo;
|
||||
File::FileInfo fo;
|
||||
if (VFSGetFileInfo(fullName.c_str(), &fo)) {
|
||||
x.exists = fo.exists;
|
||||
if (x.exists) {
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <ctime>
|
||||
|
||||
#include "Common/File/FileUtil.h"
|
||||
#include "Common/File/DirListing.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Common/Serialize/Serializer.h"
|
||||
#include "Common/Serialize/SerializeFuncs.h"
|
||||
|
@ -631,9 +632,9 @@ PSPFileInfo VirtualDiscFileSystem::GetFileInfo(std::string filename) {
|
|||
}
|
||||
|
||||
if (x.type != FILETYPE_DIRECTORY) {
|
||||
File::FileDetails details;
|
||||
if (!File::GetFileDetails(fullName, &details)) {
|
||||
ERROR_LOG(FILESYS, "DirectoryFileSystem::GetFileInfo: GetFileDetails failed: %s", fullName.c_str());
|
||||
File::FileInfo details;
|
||||
if (!File::GetFileInfo(fullName.c_str(), &details)) {
|
||||
ERROR_LOG(FILESYS, "DirectoryFileSystem::GetFileInfo: GetFileInfo failed: %s", fullName.c_str());
|
||||
x.size = 0;
|
||||
x.access = 0;
|
||||
} else {
|
||||
|
|
|
@ -82,8 +82,8 @@ static PluginInfo ReadPluginIni(const std::string &subdir, IniFile &ini) {
|
|||
}
|
||||
|
||||
static std::vector<PluginInfo> FindPlugins(const std::string &gameID, const std::string &lang) {
|
||||
std::vector<FileInfo> pluginDirs;
|
||||
getFilesInDir(GetSysDirectory(DIRECTORY_PLUGINS).c_str(), &pluginDirs);
|
||||
std::vector<File::FileInfo> pluginDirs;
|
||||
GetFilesInDir(GetSysDirectory(DIRECTORY_PLUGINS).c_str(), &pluginDirs);
|
||||
|
||||
std::vector<PluginInfo> found;
|
||||
for (auto subdir : pluginDirs) {
|
||||
|
|
|
@ -450,7 +450,7 @@ namespace Reporting
|
|||
void AddScreenshotData(MultipartFormDataEncoder &postdata, std::string filename)
|
||||
{
|
||||
std::string data;
|
||||
if (!filename.empty() && readFileToString(false, filename.c_str(), data))
|
||||
if (!filename.empty() && File::ReadFileToString(false, filename.c_str(), data))
|
||||
postdata.Add("screenshot", data, "screenshot.jpg", "image/jpeg");
|
||||
|
||||
const std::string iconFilename = "disc0:/PSP_GAME/ICON0.PNG";
|
||||
|
@ -552,7 +552,7 @@ namespace Reporting
|
|||
if (!File::Exists(g_Config.flash0Directory + "/font/jpn0.pgf"))
|
||||
return false;
|
||||
#else
|
||||
FileInfo fo;
|
||||
File::FileInfo fo;
|
||||
if (!VFSGetFileInfo("flash0/font/jpn0.pgf", &fo))
|
||||
return false;
|
||||
#endif
|
||||
|
|
|
@ -78,8 +78,8 @@ void LoadPostShaderInfo(const std::vector<std::string> &directories) {
|
|||
};
|
||||
|
||||
for (size_t d = 0; d < directories.size(); d++) {
|
||||
std::vector<FileInfo> fileInfo;
|
||||
getFilesInDir(directories[d].c_str(), &fileInfo, "ini:");
|
||||
std::vector<File::FileInfo> fileInfo;
|
||||
File::GetFilesInDir(directories[d].c_str(), &fileInfo, "ini:");
|
||||
|
||||
if (fileInfo.size() == 0) {
|
||||
VFSGetFileListing(directories[d].c_str(), &fileInfo, "ini:");
|
||||
|
|
|
@ -63,7 +63,7 @@ void CwCheatScreen::LoadCheatInfo() {
|
|||
|
||||
// We won't parse this, just using it to detect changes to the file.
|
||||
std::string str;
|
||||
if (readFileToString(true, engine_->CheatFilename().c_str(), str)) {
|
||||
if (File::ReadFileToString(true, engine_->CheatFilename().c_str(), str)) {
|
||||
fileCheckHash_ = XXH3_64bits(str.c_str(), str.size());
|
||||
}
|
||||
fileCheckCounter_ = 0;
|
||||
|
@ -120,7 +120,7 @@ void CwCheatScreen::update() {
|
|||
if (fileCheckCounter_++ >= FILE_CHECK_FRAME_INTERVAL && engine_) {
|
||||
// Check if the file has changed. If it has, we'll reload.
|
||||
std::string str;
|
||||
if (readFileToString(true, engine_->CheatFilename().c_str(), str)) {
|
||||
if (File::ReadFileToString(true, engine_->CheatFilename().c_str(), str)) {
|
||||
uint64_t newHash = XXH3_64bits(str.c_str(), str.size());
|
||||
if (newHash != fileCheckHash_) {
|
||||
// This will update the hash.
|
||||
|
@ -176,7 +176,7 @@ UI::EventReturn CwCheatScreen::OnEditCheatFile(UI::EventParams ¶ms) {
|
|||
#if PPSSPP_PLATFORM(UWP)
|
||||
LaunchBrowser(engine_->CheatFilename().c_str());
|
||||
#else
|
||||
File::openIniFile(engine_->CheatFilename());
|
||||
File::OpenFileInEditor(engine_->CheatFilename());
|
||||
#endif
|
||||
}
|
||||
return UI::EVENT_DONE;
|
||||
|
|
|
@ -113,7 +113,7 @@ u64 GameInfo::GetGameSizeInBytes() {
|
|||
switch (fileType) {
|
||||
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
||||
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY:
|
||||
return getDirectoryRecursiveSize(ResolvePBPDirectory(filePath_), nullptr, GETFILES_GETHIDDEN);
|
||||
return File::GetDirectoryRecursiveSize(ResolvePBPDirectory(filePath_), nullptr, File::GETFILES_GETHIDDEN);
|
||||
|
||||
default:
|
||||
return GetFileLoader()->FileSize();
|
||||
|
@ -124,8 +124,8 @@ u64 GameInfo::GetGameSizeInBytes() {
|
|||
std::vector<std::string> GameInfo::GetSaveDataDirectories() {
|
||||
std::string memc = GetSysDirectory(DIRECTORY_SAVEDATA);
|
||||
|
||||
std::vector<FileInfo> dirs;
|
||||
getFilesInDir(memc.c_str(), &dirs);
|
||||
std::vector<File::FileInfo> dirs;
|
||||
File::GetFilesInDir(memc.c_str(), &dirs);
|
||||
|
||||
std::vector<std::string> directories;
|
||||
if (id.size() < 5) {
|
||||
|
@ -149,12 +149,12 @@ u64 GameInfo::GetSaveDataSizeInBytes() {
|
|||
u64 totalSize = 0;
|
||||
u64 filesSizeInDir = 0;
|
||||
for (size_t j = 0; j < saveDataDir.size(); j++) {
|
||||
std::vector<FileInfo> fileInfo;
|
||||
getFilesInDir(saveDataDir[j].c_str(), &fileInfo);
|
||||
// Note: getFileInDir does not fill in fileSize properly.
|
||||
std::vector<File::FileInfo> fileInfo;
|
||||
File::GetFilesInDir(saveDataDir[j].c_str(), &fileInfo);
|
||||
// Note: GetFilesInDir does not fill in fileSize properly.
|
||||
for (size_t i = 0; i < fileInfo.size(); i++) {
|
||||
FileInfo finfo;
|
||||
getFileInfo(fileInfo[i].fullName.c_str(), &finfo);
|
||||
File::FileInfo finfo;
|
||||
File::GetFileInfo(fileInfo[i].fullName.c_str(), &finfo);
|
||||
if (!finfo.isDirectory)
|
||||
filesSizeInDir += finfo.size;
|
||||
}
|
||||
|
@ -176,12 +176,12 @@ u64 GameInfo::GetInstallDataSizeInBytes() {
|
|||
u64 totalSize = 0;
|
||||
u64 filesSizeInDir = 0;
|
||||
for (size_t j = 0; j < saveDataDir.size(); j++) {
|
||||
std::vector<FileInfo> fileInfo;
|
||||
getFilesInDir(saveDataDir[j].c_str(), &fileInfo);
|
||||
// Note: getFileInDir does not fill in fileSize properly.
|
||||
std::vector<File::FileInfo> fileInfo;
|
||||
File::GetFilesInDir(saveDataDir[j].c_str(), &fileInfo);
|
||||
// Note: GetFilesInDir does not fill in fileSize properly.
|
||||
for (size_t i = 0; i < fileInfo.size(); i++) {
|
||||
FileInfo finfo;
|
||||
getFileInfo(fileInfo[i].fullName.c_str(), &finfo);
|
||||
File::FileInfo finfo;
|
||||
File::GetFileInfo(fileInfo[i].fullName.c_str(), &finfo);
|
||||
if (!finfo.isDirectory)
|
||||
filesSizeInDir += finfo.size;
|
||||
}
|
||||
|
@ -230,8 +230,8 @@ void GameInfo::DisposeFileLoader() {
|
|||
bool GameInfo::DeleteAllSaveData() {
|
||||
std::vector<std::string> saveDataDir = GetSaveDataDirectories();
|
||||
for (size_t j = 0; j < saveDataDir.size(); j++) {
|
||||
std::vector<FileInfo> fileInfo;
|
||||
getFilesInDir(saveDataDir[j].c_str(), &fileInfo);
|
||||
std::vector<File::FileInfo> fileInfo;
|
||||
File::GetFilesInDir(saveDataDir[j].c_str(), &fileInfo);
|
||||
|
||||
for (size_t i = 0; i < fileInfo.size(); i++) {
|
||||
File::Delete(fileInfo[i].fullName.c_str());
|
||||
|
@ -402,9 +402,9 @@ public:
|
|||
std::string screenshot_png = GetSysDirectory(DIRECTORY_SCREENSHOT) + info_->id + "_00000.png";
|
||||
// Try using png/jpg screenshots first
|
||||
if (File::Exists(screenshot_png))
|
||||
readFileToString(false, screenshot_png.c_str(), info_->icon.data);
|
||||
File::ReadFileToString(false, screenshot_png.c_str(), info_->icon.data);
|
||||
else if (File::Exists(screenshot_jpg))
|
||||
readFileToString(false, screenshot_jpg.c_str(), info_->icon.data);
|
||||
File::ReadFileToString(false, screenshot_jpg.c_str(), info_->icon.data);
|
||||
else
|
||||
// Read standard icon
|
||||
ReadVFSToString("unknown.png", &info_->icon.data, &info_->lock);
|
||||
|
@ -449,9 +449,9 @@ handleELF:
|
|||
std::string screenshot_png = GetSysDirectory(DIRECTORY_SCREENSHOT) + info_->id + "_00000.png";
|
||||
// Try using png/jpg screenshots first
|
||||
if (File::Exists(screenshot_png)) {
|
||||
readFileToString(false, screenshot_png.c_str(), info_->icon.data);
|
||||
File::ReadFileToString(false, screenshot_png.c_str(), info_->icon.data);
|
||||
} else if (File::Exists(screenshot_jpg)) {
|
||||
readFileToString(false, screenshot_jpg.c_str(), info_->icon.data);
|
||||
File::ReadFileToString(false, screenshot_jpg.c_str(), info_->icon.data);
|
||||
} else {
|
||||
// Read standard icon
|
||||
VERBOSE_LOG(LOADER, "Loading unknown.png because there was an ELF");
|
||||
|
@ -492,7 +492,7 @@ handleELF:
|
|||
// Let's use the screenshot as an icon, too.
|
||||
std::string screenshotPath = ReplaceAll(gamePath_, ".ppst", ".jpg");
|
||||
if (File::Exists(screenshotPath)) {
|
||||
if (readFileToString(false, screenshotPath.c_str(), info_->icon.data)) {
|
||||
if (File::ReadFileToString(false, screenshotPath.c_str(), info_->icon.data)) {
|
||||
info_->icon.dataLoaded = true;
|
||||
} else {
|
||||
ERROR_LOG(G3D, "Error loading screenshot data: '%s'", screenshotPath.c_str());
|
||||
|
@ -577,9 +577,9 @@ handleELF:
|
|||
std::string screenshot_png = GetSysDirectory(DIRECTORY_SCREENSHOT) + info_->id + "_00000.png";
|
||||
// Try using png/jpg screenshots first
|
||||
if (File::Exists(screenshot_png))
|
||||
readFileToString(false, screenshot_png.c_str(), info_->icon.data);
|
||||
File::ReadFileToString(false, screenshot_png.c_str(), info_->icon.data);
|
||||
else if (File::Exists(screenshot_jpg))
|
||||
readFileToString(false, screenshot_jpg.c_str(), info_->icon.data);
|
||||
File::ReadFileToString(false, screenshot_jpg.c_str(), info_->icon.data);
|
||||
else {
|
||||
DEBUG_LOG(LOADER, "Loading unknown.png because no icon was found");
|
||||
ReadVFSToString("unknown.png", &info_->icon.data, &info_->lock);
|
||||
|
|
|
@ -421,7 +421,7 @@ void SetBackgroundPopupScreen::update() {
|
|||
|
||||
if (pic) {
|
||||
const std::string bgPng = GetSysDirectory(DIRECTORY_SYSTEM) + "background.png";
|
||||
writeStringToFile(false, pic->data, bgPng.c_str());
|
||||
File::WriteStringToFile(false, pic->data, bgPng.c_str());
|
||||
}
|
||||
|
||||
NativeMessageReceived("bgImage_updated", "");
|
||||
|
|
|
@ -1293,7 +1293,6 @@ void GameSettingsScreen::sendMessage(const char *message, const char *value) {
|
|||
}
|
||||
}
|
||||
|
||||
#if PPSSPP_PLATFORM(ANDROID)
|
||||
void GameSettingsScreen::CallbackMemstickFolder(bool yes) {
|
||||
auto sy = GetI18NCategory("System");
|
||||
|
||||
|
@ -1305,20 +1304,19 @@ void GameSettingsScreen::CallbackMemstickFolder(bool yes) {
|
|||
if (!File::Exists(pendingMemstickFolder_)) {
|
||||
File::CreateFullPath(pendingMemstickFolder_);
|
||||
}
|
||||
if (!writeDataToFile(true, "1", 1, testWriteFile.c_str())) {
|
||||
if (!File::WriteDataToFile(true, "1", 1, testWriteFile.c_str())) {
|
||||
settingInfo_->Show(sy->T("ChangingMemstickPathInvalid", "That path couldn't be used to save Memory Stick files."), nullptr);
|
||||
return;
|
||||
}
|
||||
File::Delete(testWriteFile);
|
||||
|
||||
writeDataToFile(true, pendingMemstickFolder_.c_str(), pendingMemstickFolder_.size(), memstickDirFile.c_str());
|
||||
File::WriteDataToFile(true, pendingMemstickFolder_.c_str(), pendingMemstickFolder_.size(), memstickDirFile.c_str());
|
||||
// Save so the settings, at least, are transferred.
|
||||
g_Config.memStickDirectory = pendingMemstickFolder_ + "/";
|
||||
g_Config.Save("MemstickPathChanged");
|
||||
screenManager()->RecreateAllViews();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void GameSettingsScreen::TriggerRestart(const char *why) {
|
||||
// Extra save here to make sure the choice really gets saved even if there are shutdown bugs in
|
||||
|
@ -1733,7 +1731,7 @@ UI::EventReturn DeveloperToolsScreen::OnOpenTexturesIniFile(UI::EventParams &e)
|
|||
std::string gameID = g_paramSFO.GetDiscID();
|
||||
std::string generatedFilename;
|
||||
if (TextureReplacer::GenerateIni(gameID, &generatedFilename)) {
|
||||
File::openIniFile(generatedFilename);
|
||||
File::OpenFileInEditor(generatedFilename);
|
||||
}
|
||||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
@ -1772,10 +1770,10 @@ UI::EventReturn DeveloperToolsScreen::OnCopyStatesToRoot(UI::EventParams &e) {
|
|||
std::string savestate_dir = GetSysDirectory(DIRECTORY_SAVESTATE);
|
||||
std::string root_dir = GetSysDirectory(DIRECTORY_MEMSTICK_ROOT);
|
||||
|
||||
std::vector<FileInfo> files;
|
||||
getFilesInDir(savestate_dir.c_str(), &files, nullptr, 0);
|
||||
std::vector<File::FileInfo> files;
|
||||
GetFilesInDir(savestate_dir.c_str(), &files, nullptr, 0);
|
||||
|
||||
for (const FileInfo &file : files) {
|
||||
for (const File::FileInfo &file : files) {
|
||||
std::string src = file.fullName;
|
||||
std::string dst = root_dir + file.name;
|
||||
INFO_LOG(SYSTEM, "Copying file '%s' to '%s'", src.c_str(), dst.c_str());
|
||||
|
@ -1785,7 +1783,6 @@ UI::EventReturn DeveloperToolsScreen::OnCopyStatesToRoot(UI::EventParams &e) {
|
|||
return UI::EVENT_DONE;
|
||||
}
|
||||
|
||||
|
||||
UI::EventReturn DeveloperToolsScreen::OnRemoteDebugger(UI::EventParams &e) {
|
||||
if (allowDebugger_) {
|
||||
StartWebServer(WebServerFlags::DEBUGGER);
|
||||
|
|
|
@ -43,9 +43,7 @@ protected:
|
|||
void CallbackRenderingBackend(bool yes);
|
||||
void CallbackRenderingDevice(bool yes);
|
||||
void CallbackInflightFrames(bool yes);
|
||||
#if PPSSPP_PLATFORM(ANDROID)
|
||||
void CallbackMemstickFolder(bool yes);
|
||||
#endif
|
||||
bool UseVerticalLayout() const;
|
||||
|
||||
private:
|
||||
|
@ -137,9 +135,8 @@ private:
|
|||
//edit the game-specific settings and restore the global settings after exiting
|
||||
bool editThenRestore_;
|
||||
|
||||
#if PPSSPP_PLATFORM(ANDROID)
|
||||
// Android-only
|
||||
std::string pendingMemstickFolder_;
|
||||
#endif
|
||||
};
|
||||
|
||||
class SettingInfoMessage : public UI::LinearLayout {
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
void InstallZipScreen::CreateViews() {
|
||||
using namespace UI;
|
||||
|
||||
FileInfo fileInfo;
|
||||
bool success = getFileInfo(zipPath_.c_str(), &fileInfo);
|
||||
File::FileInfo fileInfo;
|
||||
bool success = File::GetFileInfo(zipPath_.c_str(), &fileInfo);
|
||||
|
||||
auto di = GetI18NCategory("Dialog");
|
||||
auto iz = GetI18NCategory("InstallZip");
|
||||
|
|
|
@ -712,7 +712,7 @@ void GameBrowser::Refresh() {
|
|||
gameButtons.push_back(new GameButton(filenames[i], *gridStyle_, new UI::LinearLayoutParams(*gridStyle_ == true ? UI::WRAP_CONTENT : UI::FILL_PARENT, UI::WRAP_CONTENT)));
|
||||
}
|
||||
} else if (!listingPending_) {
|
||||
std::vector<FileInfo> fileInfo;
|
||||
std::vector<File::FileInfo> fileInfo;
|
||||
path_.GetListing(fileInfo, "iso:cso:pbp:elf:prx:ppdmp:");
|
||||
for (size_t i = 0; i < fileInfo.size(); i++) {
|
||||
bool isGame = !fileInfo[i].isDirectory;
|
||||
|
|
|
@ -485,7 +485,7 @@ NewLanguageScreen::NewLanguageScreen(const std::string &title) : ListPopupScreen
|
|||
#endif
|
||||
langValuesMapping = GetLangValuesMapping();
|
||||
|
||||
std::vector<FileInfo> tempLangs;
|
||||
std::vector<File::FileInfo> tempLangs;
|
||||
VFSGetFileListing("lang", &tempLangs, "ini");
|
||||
std::vector<std::string> listing;
|
||||
int selected = -1;
|
||||
|
@ -508,7 +508,7 @@ NewLanguageScreen::NewLanguageScreen(const std::string &title) : ListPopupScreen
|
|||
}
|
||||
#endif
|
||||
|
||||
FileInfo lang = tempLangs[i];
|
||||
File::FileInfo lang = tempLangs[i];
|
||||
langs_.push_back(lang);
|
||||
|
||||
std::string code;
|
||||
|
|
|
@ -100,7 +100,7 @@ private:
|
|||
bool ShowButtons() const override { return true; }
|
||||
std::map<std::string, std::pair<std::string, int>> langValuesMapping;
|
||||
std::map<std::string, std::string> titleCodeMapping;
|
||||
std::vector<FileInfo> langs_;
|
||||
std::vector<File::FileInfo> langs_;
|
||||
};
|
||||
|
||||
class PostProcScreen : public ListPopupScreen {
|
||||
|
|
|
@ -386,7 +386,7 @@ static void CheckFailedGPUBackends() {
|
|||
|
||||
if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) {
|
||||
std::string data;
|
||||
if (readFileToString(true, cache.c_str(), data))
|
||||
if (File::ReadFileToString(true, cache.c_str(), data))
|
||||
g_Config.sFailedGPUBackends = data;
|
||||
}
|
||||
|
||||
|
@ -414,7 +414,7 @@ static void CheckFailedGPUBackends() {
|
|||
// Let's try to create, in case it doesn't exist.
|
||||
if (!File::Exists(GetSysDirectory(DIRECTORY_APP_CACHE)))
|
||||
File::CreateDir(GetSysDirectory(DIRECTORY_APP_CACHE));
|
||||
writeStringToFile(true, g_Config.sFailedGPUBackends, cache.c_str());
|
||||
File::WriteStringToFile(true, g_Config.sFailedGPUBackends, cache.c_str());
|
||||
} else {
|
||||
// Just save immediately, since we have storage.
|
||||
g_Config.Save("got storage permission");
|
||||
|
@ -502,7 +502,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
|
|||
std::string memstickDirFile = g_Config.internalDataDirectory + "/memstick_dir.txt";
|
||||
if (File::Exists(memstickDirFile)) {
|
||||
std::string memstickDir;
|
||||
readFileToString(true, memstickDirFile.c_str(), memstickDir);
|
||||
File::ReadFileToString(true, memstickDirFile.c_str(), memstickDir);
|
||||
if (!memstickDir.empty() && File::Exists(memstickDir)) {
|
||||
g_Config.memStickDirectory = memstickDir + "/";
|
||||
}
|
||||
|
@ -1023,8 +1023,8 @@ void TakeScreenshot() {
|
|||
snprintf(filename, sizeof(filename), "%s/%s_%05d.png", path.c_str(), gameId.c_str(), i);
|
||||
else
|
||||
snprintf(filename, sizeof(filename), "%s/%s_%05d.jpg", path.c_str(), gameId.c_str(), i);
|
||||
FileInfo info;
|
||||
if (!getFileInfo(filename, &info))
|
||||
File::FileInfo info;
|
||||
if (!File::Exists(filename))
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
|
|
|
@ -241,7 +241,7 @@ bool RemoteISOConnectScreen::FindServer(std::string &resultHost, int &resultPort
|
|||
|
||||
static bool LoadGameList(const std::string &url, std::vector<std::string> &games) {
|
||||
PathBrowser browser(url);
|
||||
std::vector<FileInfo> files;
|
||||
std::vector<File::FileInfo> files;
|
||||
browser.GetListing(files, "iso:cso:pbp:elf:prx:ppdmp:", &scanCancelled);
|
||||
if (scanCancelled) {
|
||||
return false;
|
||||
|
|
|
@ -430,7 +430,7 @@ static time_t GetTotalSize(const SavedataButton *b) {
|
|||
switch (Identify_File(fileLoader.get())) {
|
||||
case IdentifiedFileType::PSP_PBP_DIRECTORY:
|
||||
case IdentifiedFileType::PSP_SAVEDATA_DIRECTORY:
|
||||
return getDirectoryRecursiveSize(ResolvePBPDirectory(b->GamePath()), nullptr, GETFILES_GETHIDDEN);
|
||||
return File::GetDirectoryRecursiveSize(ResolvePBPDirectory(b->GamePath()), nullptr, File::GETFILES_GETHIDDEN);
|
||||
|
||||
default:
|
||||
return fileLoader->FileSize();
|
||||
|
@ -488,8 +488,8 @@ void SavedataBrowser::Refresh() {
|
|||
// Find games in the current directory and create new ones.
|
||||
std::vector<SavedataButton *> savedataButtons;
|
||||
|
||||
std::vector<FileInfo> fileInfo;
|
||||
getFilesInDir(path_.c_str(), &fileInfo, "ppst:");
|
||||
std::vector<File::FileInfo> fileInfo;
|
||||
GetFilesInDir(path_.c_str(), &fileInfo, "ppst:");
|
||||
|
||||
for (size_t i = 0; i < fileInfo.size(); i++) {
|
||||
bool isState = !fileInfo[i].isDirectory;
|
||||
|
|
|
@ -136,7 +136,7 @@ std::string StorageFileLoader::Path() const {
|
|||
}
|
||||
|
||||
std::string StorageFileLoader::Extension() {
|
||||
return "." + getFileExtension(path_);
|
||||
return "." + File::GetFileExtension(path_);
|
||||
}
|
||||
|
||||
void StorageFileLoader::EnsureOpen() {
|
||||
|
|
|
@ -122,12 +122,12 @@ void UWPHost::BootDone() {
|
|||
}
|
||||
|
||||
static std::string SymbolMapFilename(const char *currentFilename, char* ext) {
|
||||
FileInfo info;
|
||||
File::FileInfo info;
|
||||
|
||||
std::string result = currentFilename;
|
||||
|
||||
// can't fail, definitely exists if it gets this far
|
||||
getFileInfo(currentFilename, &info);
|
||||
File::GetFileInfo(currentFilename, &info);
|
||||
if (info.isDirectory) {
|
||||
#ifdef _WIN32
|
||||
char* slash = "\\";
|
||||
|
|
|
@ -269,12 +269,12 @@ void WindowsHost::BootDone() {
|
|||
}
|
||||
|
||||
static std::string SymbolMapFilename(const char *currentFilename, const char* ext) {
|
||||
FileInfo info;
|
||||
File::FileInfo info;
|
||||
|
||||
std::string result = currentFilename;
|
||||
|
||||
// can't fail, definitely exists if it gets this far
|
||||
getFileInfo(currentFilename, &info);
|
||||
File::GetFileInfo(currentFilename, &info);
|
||||
if (info.isDirectory) {
|
||||
#ifdef _WIN32
|
||||
const char* slash = "\\";
|
||||
|
|
|
@ -297,7 +297,7 @@ bool CompareOutput(const std::string &bootFilename, const std::string &output, b
|
|||
printf("%s", output.c_str());
|
||||
printf("============== expected output:\n");
|
||||
std::string fullExpected;
|
||||
if (readFileToString(true, expect_filename.c_str(), fullExpected))
|
||||
if (File::ReadFileToString(true, expect_filename.c_str(), fullExpected))
|
||||
printf("%s", fullExpected.c_str());
|
||||
printf("===============================\n");
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue