mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-02-28 22:13:24 +00:00
vfsLocalDir, rFile routines improved
This commit is contained in:
parent
2798827066
commit
d032bc5691
@ -5,23 +5,37 @@
|
||||
#include <wx/file.h>
|
||||
#include <wx/filename.h>
|
||||
#include "rFile.h"
|
||||
#include "errno.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
|
||||
// Maybe in StrFmt?
|
||||
std::wstring ConvertUTF8ToWString(const std::string &source)
|
||||
#define GET_API_ERROR static_cast<u64>(GetLastError())
|
||||
|
||||
std::unique_ptr<wchar_t> ConvertUTF8ToWChar(const std::string& source)
|
||||
{
|
||||
int len = (int)source.size();
|
||||
int size = (int)MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, NULL, 0);
|
||||
std::wstring str;
|
||||
str.resize(size);
|
||||
if (size > 0) {
|
||||
MultiByteToWideChar(CP_UTF8, 0, source.c_str(), len, &str[0], size);
|
||||
const size_t length = source.size() + 1; // size + null terminator
|
||||
|
||||
const int size = length && length <= INT_MAX ? static_cast<int>(length) : throw std::length_error(__FUNCTION__);
|
||||
|
||||
std::unique_ptr<wchar_t> buffer(new wchar_t[length]); // allocate buffer assuming that length is the max possible size
|
||||
|
||||
if (!MultiByteToWideChar(CP_UTF8, 0, source.c_str(), size, buffer.get(), size))
|
||||
{
|
||||
LOG_ERROR(GENERAL, "ConvertUTF8ToWChar(source='%s') failed: 0x%llx", source.c_str(), GET_API_ERROR);
|
||||
}
|
||||
return str;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
time_t to_time_t(const FILETIME& ft)
|
||||
{
|
||||
ULARGE_INTEGER v;
|
||||
v.LowPart = ft.dwLowDateTime;
|
||||
v.HighPart = ft.dwHighDateTime;
|
||||
|
||||
return v.QuadPart / 10000000ULL - 11644473600ULL;
|
||||
}
|
||||
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
@ -30,59 +44,76 @@ std::wstring ConvertUTF8ToWString(const std::string &source)
|
||||
#else
|
||||
#include <sys/sendfile.h>
|
||||
#endif
|
||||
#endif
|
||||
#include "errno.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define GET_API_ERROR static_cast<u64>(GetLastError())
|
||||
#else
|
||||
#define GET_API_ERROR static_cast<u64>(errno)
|
||||
|
||||
#endif
|
||||
|
||||
bool getFileInfo(const char *path, FileInfo *fileInfo)
|
||||
bool get_file_info(const std::string& path, FileInfo& info)
|
||||
{
|
||||
// TODO: Expand relative paths?
|
||||
fileInfo->fullName = path;
|
||||
info.fullName = path;
|
||||
|
||||
#ifdef _WIN32
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrs;
|
||||
if (!GetFileAttributesExW(ConvertUTF8ToWString(path).c_str(), GetFileExInfoStandard, &attrs)) {
|
||||
fileInfo->size = 0;
|
||||
fileInfo->isDirectory = false;
|
||||
fileInfo->isWritable = false;
|
||||
fileInfo->exists = false;
|
||||
if (!GetFileAttributesExW(ConvertUTF8ToWChar(path).get(), GetFileExInfoStandard, &attrs))
|
||||
{
|
||||
info.exists = false;
|
||||
info.isDirectory = false;
|
||||
info.isWritable = false;
|
||||
info.size = 0;
|
||||
return false;
|
||||
}
|
||||
fileInfo->size = (uint64_t)attrs.nFileSizeLow | ((uint64_t)attrs.nFileSizeHigh << 32);
|
||||
fileInfo->isDirectory = (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
fileInfo->isWritable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
|
||||
fileInfo->exists = true;
|
||||
|
||||
info.exists = true;
|
||||
info.isDirectory = (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
info.isWritable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0;
|
||||
info.size = (uint64_t)attrs.nFileSizeLow | ((uint64_t)attrs.nFileSizeHigh << 32);
|
||||
info.atime = to_time_t(attrs.ftLastAccessTime);
|
||||
info.mtime = to_time_t(attrs.ftLastWriteTime);
|
||||
info.ctime = to_time_t(attrs.ftCreationTime);
|
||||
#else
|
||||
struct stat64 file_info;
|
||||
int result = stat64(path, &file_info);
|
||||
|
||||
if (result < 0) {
|
||||
fileInfo->size = 0;
|
||||
fileInfo->isDirectory = false;
|
||||
fileInfo->isWritable = false;
|
||||
fileInfo->exists = false;
|
||||
if (stat64(path, &file_info) < 0)
|
||||
{
|
||||
info.exists = false;
|
||||
info.isDirectory = false;
|
||||
info.isWritable = false;
|
||||
info.size = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
fileInfo->isDirectory = S_ISDIR(file_info.st_mode);
|
||||
fileInfo->isWritable = false;
|
||||
fileInfo->size = file_info.st_size;
|
||||
fileInfo->exists = true;
|
||||
// HACK: approximation
|
||||
if (file_info.st_mode & 0200)
|
||||
fileInfo->isWritable = true;
|
||||
info.exists = true;
|
||||
info.isDirectory = S_ISDIR(file_info.st_mode);
|
||||
info.isWritable = file_info.st_mode & 0200; // HACK: approximation
|
||||
info.size = file_info.st_size;
|
||||
info.atime = file_info.st_atime;
|
||||
info.mtime = file_info.st_mtime;
|
||||
info.ctime = file_info.st_ctime;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rIsDir(const std::string &filename) {
|
||||
FileInfo info;
|
||||
getFileInfo(filename.c_str(), &info);
|
||||
return info.isDirectory;
|
||||
bool rIsDir(const std::string& dir)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
DWORD attrs;
|
||||
if ((attrs = GetFileAttributesW(ConvertUTF8ToWChar(dir).get())) == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (attrs & FILE_ATTRIBUTE_DIRECTORY) != 0;
|
||||
#else
|
||||
struct stat64 file_info;
|
||||
if (stat64(path, &file_info) < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return S_ISDIR(file_info.st_mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool rMkdir(const std::string& dir)
|
||||
@ -124,7 +155,7 @@ bool rMkpath(const std::string &path)
|
||||
bool rRmdir(const std::string& dir)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!RemoveDirectory(ConvertUTF8ToWString(dir).c_str()))
|
||||
if (!RemoveDirectory(ConvertUTF8ToWChar(dir).get()))
|
||||
#else
|
||||
if (rmdir(dir.c_str()))
|
||||
#endif
|
||||
@ -140,7 +171,7 @@ bool rRename(const std::string &from, const std::string &to)
|
||||
{
|
||||
// TODO: Deal with case-sensitivity
|
||||
#ifdef _WIN32
|
||||
if (!MoveFile(ConvertUTF8ToWString(from).c_str(), ConvertUTF8ToWString(to).c_str()))
|
||||
if (!MoveFile(ConvertUTF8ToWChar(from).get(), ConvertUTF8ToWChar(to).get()))
|
||||
#else
|
||||
if (rename(from.c_str(), to.c_str()))
|
||||
#endif
|
||||
@ -191,7 +222,7 @@ int OSCopyFile(const char* source, const char* destination, bool overwrite)
|
||||
bool rCopy(const std::string& from, const std::string& to, bool overwrite)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!CopyFile(ConvertUTF8ToWString(from).c_str(), ConvertUTF8ToWString(to).c_str(), !overwrite))
|
||||
if (!CopyFile(ConvertUTF8ToWChar(from).get(), ConvertUTF8ToWChar(to).get(), !overwrite))
|
||||
#else
|
||||
if (OSCopyFile(from.c_str(), to.c_str(), overwrite))
|
||||
#endif
|
||||
@ -206,18 +237,17 @@ bool rCopy(const std::string& from, const std::string& to, bool overwrite)
|
||||
bool rExists(const std::string& file)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
std::wstring wstr = ConvertUTF8ToWString(file);
|
||||
return GetFileAttributes(wstr.c_str()) != 0xFFFFFFFF;
|
||||
return GetFileAttributes(ConvertUTF8ToWChar(file).get()) != 0xFFFFFFFF;
|
||||
#else
|
||||
struct stat buffer;
|
||||
return (stat (file.c_str(), &buffer) == 0);
|
||||
return stat(file.c_str(), &buffer) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool rRemoveFile(const std::string& file)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!DeleteFile(ConvertUTF8ToWString(file).c_str()))
|
||||
if (!DeleteFile(ConvertUTF8ToWChar(file).get()))
|
||||
#else
|
||||
if (unlink(file.c_str()))
|
||||
#endif
|
||||
|
@ -1,16 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
struct FileInfo {
|
||||
struct FileInfo
|
||||
{
|
||||
std::string name;
|
||||
std::string fullName;
|
||||
bool exists;
|
||||
bool isDirectory;
|
||||
bool isWritable;
|
||||
uint64_t size;
|
||||
time_t atime;
|
||||
time_t mtime;
|
||||
time_t ctime;
|
||||
};
|
||||
|
||||
bool getFileInfo(const char *path, FileInfo *fileInfo);
|
||||
bool rIsDir(const std::string& filename);
|
||||
bool get_file_info(const std::string& path, FileInfo& fileInfo);
|
||||
bool rIsDir(const std::string& dir);
|
||||
bool rRmdir(const std::string& dir);
|
||||
bool rMkdir(const std::string& dir);
|
||||
bool rMkpath(const std::string& path);
|
||||
|
@ -16,12 +16,14 @@ struct DirEntryInfo
|
||||
{
|
||||
std::string name;
|
||||
u32 flags;
|
||||
u64 size;
|
||||
time_t create_time;
|
||||
time_t access_time;
|
||||
time_t modify_time;
|
||||
|
||||
DirEntryInfo()
|
||||
: flags(0)
|
||||
, size(0)
|
||||
, create_time(0)
|
||||
, access_time(0)
|
||||
, modify_time(0)
|
||||
|
@ -12,30 +12,29 @@ vfsLocalDir::~vfsLocalDir()
|
||||
|
||||
bool vfsLocalDir::Open(const std::string& path)
|
||||
{
|
||||
if(!vfsDirBase::Open(path))
|
||||
return false;
|
||||
|
||||
if(!dir.Open(path))
|
||||
if (!vfsDirBase::Open(path) || !dir.Open(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string name;
|
||||
|
||||
for (bool is_ok = dir.GetFirst(&name); is_ok; is_ok = dir.GetNext(&name))
|
||||
{
|
||||
std::string dir_path = path + "/" + name;
|
||||
FileInfo file_info;
|
||||
get_file_info(path + "/" + name, file_info);
|
||||
|
||||
m_entries.emplace_back();
|
||||
// TODO: Use same info structure as fileinfo?
|
||||
|
||||
DirEntryInfo& info = m_entries.back();
|
||||
|
||||
info.name = name;
|
||||
|
||||
FileInfo fileinfo;
|
||||
getFileInfo(dir_path.c_str(), &fileinfo);
|
||||
|
||||
// Not sure of purpose for below. I hope these don't need to be correct
|
||||
info.flags |= rIsDir(dir_path) ? DirEntry_TypeDir : DirEntry_TypeFile;
|
||||
if(fileinfo.isWritable) info.flags |= DirEntry_PermWritable;
|
||||
info.flags |= DirEntry_PermReadable; // Always?
|
||||
info.flags |= DirEntry_PermExecutable; // Always?
|
||||
info.flags |= file_info.isDirectory ? DirEntry_TypeDir | DirEntry_PermExecutable : DirEntry_TypeFile;
|
||||
info.flags |= file_info.isWritable ? DirEntry_PermWritable | DirEntry_PermReadable : DirEntry_PermReadable;
|
||||
info.size = file_info.size;
|
||||
info.access_time = file_info.atime;
|
||||
info.modify_time = file_info.mtime;
|
||||
info.create_time = file_info.ctime;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -439,6 +439,18 @@ namespace vm
|
||||
|
||||
// PS3 emulation is main now, so lets it be as default
|
||||
using namespace ps3;
|
||||
|
||||
struct null_t
|
||||
{
|
||||
template<typename T, int lvl, typename AT> operator _ptr_base<T, lvl, AT>() const
|
||||
{
|
||||
const std::array<AT, 1> value = {};
|
||||
return _ptr_base<T, lvl, AT>::make(value[0]);
|
||||
}
|
||||
};
|
||||
|
||||
// vm::null is convertible to any vm::ptr type as null pointer in virtual memory
|
||||
static const null_t null;
|
||||
}
|
||||
|
||||
namespace fmt
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -271,11 +271,11 @@ struct SaveDataEntry
|
||||
std::string title;
|
||||
std::string subtitle;
|
||||
std::string details;
|
||||
u32 sizeKB;
|
||||
s64 st_atime_;
|
||||
s64 st_mtime_;
|
||||
s64 st_ctime_;
|
||||
void* iconBuf;
|
||||
u32 iconBufSize;
|
||||
u64 sizeKB;
|
||||
s64 atime;
|
||||
s64 mtime;
|
||||
s64 ctime;
|
||||
//void* iconBuf;
|
||||
//u32 iconBufSize;
|
||||
bool isNew;
|
||||
};
|
||||
|
@ -72,7 +72,6 @@ Emulator::~Emulator()
|
||||
delete m_callback_manager;
|
||||
delete m_event_manager;
|
||||
delete m_module_manager;
|
||||
delete m_sync_prim_manager;
|
||||
delete m_vfs;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ class CallbackManager;
|
||||
class CPUThread;
|
||||
class EventManager;
|
||||
class ModuleManager;
|
||||
class SyncPrimManager;
|
||||
struct VFS;
|
||||
|
||||
struct EmuInfo
|
||||
@ -91,7 +90,6 @@ class Emulator
|
||||
CallbackManager* m_callback_manager;
|
||||
EventManager* m_event_manager;
|
||||
ModuleManager* m_module_manager;
|
||||
SyncPrimManager* m_sync_prim_manager;
|
||||
VFS* m_vfs;
|
||||
|
||||
EmuInfo m_info;
|
||||
|
Loading…
x
Reference in New Issue
Block a user