|
|
|
@ -18,6 +18,7 @@
|
|
|
|
|
#include "ChunkFile.h"
|
|
|
|
|
#include "FileUtil.h"
|
|
|
|
|
#include "DirectoryFileSystem.h"
|
|
|
|
|
#include "ISOFileSystem.h"
|
|
|
|
|
#include "Core/HLE/sceKernel.h"
|
|
|
|
|
#include "file/zip_read.h"
|
|
|
|
|
|
|
|
|
@ -31,8 +32,12 @@
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if HOST_IS_CASE_SENSITIVE
|
|
|
|
|
typedef enum {
|
|
|
|
|
FPC_FILE_MUST_EXIST, // all path components must exist (rmdir, move from)
|
|
|
|
|
FPC_PATH_MUST_EXIST, // all except the last one must exist - still tries to fix last one (fopen, move to)
|
|
|
|
|
FPC_PARTIAL_ALLOWED, // don't care how many exist (mkdir recursive)
|
|
|
|
|
} FixPathCaseBehavior;
|
|
|
|
|
|
|
|
|
|
static bool FixFilenameCase(const std::string &path, std::string &filename)
|
|
|
|
|
{
|
|
|
|
@ -82,7 +87,7 @@ static bool FixFilenameCase(const std::string &path, std::string &filename)
|
|
|
|
|
return retValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DirectoryFileSystem::FixPathCase(std::string &path, FixPathCaseBehavior behavior)
|
|
|
|
|
bool FixPathCase(std::string& basePath, std::string &path, FixPathCaseBehavior behavior)
|
|
|
|
|
{
|
|
|
|
|
size_t len = path.size();
|
|
|
|
|
|
|
|
|
@ -133,6 +138,185 @@ bool DirectoryFileSystem::FixPathCase(std::string &path, FixPathCaseBehavior beh
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
std::string DirectoryFileHandle::GetLocalPath(std::string& basePath, std::string localpath)
|
|
|
|
|
{
|
|
|
|
|
if (localpath.empty())
|
|
|
|
|
return basePath;
|
|
|
|
|
|
|
|
|
|
if (localpath[0] == '/')
|
|
|
|
|
localpath.erase(0,1);
|
|
|
|
|
//Convert slashes
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
for (size_t i = 0; i < localpath.size(); i++) {
|
|
|
|
|
if (localpath[i] == '/')
|
|
|
|
|
localpath[i] = '\\';
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return basePath + localpath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DirectoryFileHandle::Open(std::string& basePath, std::string& fileName, FileAccess access)
|
|
|
|
|
{
|
|
|
|
|
#if HOST_IS_CASE_SENSITIVE
|
|
|
|
|
if (access & (FILEACCESS_APPEND|FILEACCESS_CREATE|FILEACCESS_WRITE))
|
|
|
|
|
{
|
|
|
|
|
DEBUG_LOG(HLE, "Checking case for path %s", fileName.c_str());
|
|
|
|
|
if ( ! FixPathCase(basePath, fileName, FPC_PATH_MUST_EXIST) )
|
|
|
|
|
return false; // or go on and attempt (for a better error code than just 0?)
|
|
|
|
|
}
|
|
|
|
|
// else we try fopen first (in case we're lucky) before simulating case insensitivity
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
std::string fullName = GetLocalPath(basePath,fileName);
|
|
|
|
|
INFO_LOG(HLE,"Actually opening %s", fullName.c_str());
|
|
|
|
|
|
|
|
|
|
//TODO: tests, should append seek to end of file? seeking in a file opened for append?
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
// Convert parameters to Windows permissions and access
|
|
|
|
|
DWORD desired = 0;
|
|
|
|
|
DWORD sharemode = 0;
|
|
|
|
|
DWORD openmode = 0;
|
|
|
|
|
if (access & FILEACCESS_READ) {
|
|
|
|
|
desired |= GENERIC_READ;
|
|
|
|
|
sharemode |= FILE_SHARE_READ;
|
|
|
|
|
}
|
|
|
|
|
if (access & FILEACCESS_WRITE) {
|
|
|
|
|
desired |= GENERIC_WRITE;
|
|
|
|
|
sharemode |= FILE_SHARE_WRITE;
|
|
|
|
|
}
|
|
|
|
|
if (access & FILEACCESS_CREATE) {
|
|
|
|
|
openmode = OPEN_ALWAYS;
|
|
|
|
|
} else {
|
|
|
|
|
openmode = OPEN_EXISTING;
|
|
|
|
|
}
|
|
|
|
|
//Let's do it!
|
|
|
|
|
hFile = CreateFile(fullName.c_str(), desired, sharemode, 0, openmode, 0, 0);
|
|
|
|
|
bool success = hFile != INVALID_HANDLE_VALUE;
|
|
|
|
|
#else
|
|
|
|
|
// Convert flags in access parameter to fopen access mode
|
|
|
|
|
const char *mode = NULL;
|
|
|
|
|
if (access & FILEACCESS_APPEND) {
|
|
|
|
|
if (access & FILEACCESS_READ)
|
|
|
|
|
mode = "ab+"; // append+read, create if needed
|
|
|
|
|
else
|
|
|
|
|
mode = "ab"; // append only, create if needed
|
|
|
|
|
} else if (access & FILEACCESS_WRITE) {
|
|
|
|
|
if (access & FILEACCESS_READ) {
|
|
|
|
|
// FILEACCESS_CREATE is ignored for read only, write only, and append
|
|
|
|
|
// because C++ standard fopen's nonexistant file creation can only be
|
|
|
|
|
// customized for files opened read+write
|
|
|
|
|
if (access & FILEACCESS_CREATE)
|
|
|
|
|
mode = "wb+"; // read+write, create if needed
|
|
|
|
|
else
|
|
|
|
|
mode = "rb+"; // read+write, but don't create
|
|
|
|
|
} else {
|
|
|
|
|
mode = "wb"; // write only, create if needed
|
|
|
|
|
}
|
|
|
|
|
} else { // neither write nor append, so default to read only
|
|
|
|
|
mode = "rb"; // read only, don't create
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hFile = fopen(fullName.c_str(), mode);
|
|
|
|
|
bool success = hFile != 0;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if HOST_IS_CASE_SENSITIVE
|
|
|
|
|
if (!success &&
|
|
|
|
|
!(access & FILEACCESS_APPEND) &&
|
|
|
|
|
!(access & FILEACCESS_CREATE) &&
|
|
|
|
|
!(access & FILEACCESS_WRITE))
|
|
|
|
|
{
|
|
|
|
|
if ( ! FixPathCase(basePath,fileName, FPC_PATH_MUST_EXIST) )
|
|
|
|
|
return 0; // or go on and attempt (for a better error code than just 0?)
|
|
|
|
|
fullName = GetLocalPath(basePath,fileName);
|
|
|
|
|
const char* fullNameC = fullName.c_str();
|
|
|
|
|
|
|
|
|
|
DEBUG_LOG(HLE, "Case may have been incorrect, second try opening %s (%s)", fullNameC, fileName.c_str());
|
|
|
|
|
|
|
|
|
|
// And try again with the correct case this time
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
hFile = CreateFile(fullNameC, desired, sharemode, 0, openmode, 0, 0);
|
|
|
|
|
success = hFile != INVALID_HANDLE_VALUE;
|
|
|
|
|
#else
|
|
|
|
|
hFile = fopen(fullNameC, mode);
|
|
|
|
|
success = hFile != 0;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t DirectoryFileHandle::Read(u8* pointer, s64 size)
|
|
|
|
|
{
|
|
|
|
|
size_t bytesRead;
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
::ReadFile(hFile, (LPVOID)pointer, (DWORD)size, (LPDWORD)&bytesRead, 0);
|
|
|
|
|
#else
|
|
|
|
|
bytesRead = fread(pointer, 1, size, hFile);
|
|
|
|
|
#endif
|
|
|
|
|
return bytesRead;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t DirectoryFileHandle::Write(const u8* pointer, s64 size)
|
|
|
|
|
{
|
|
|
|
|
size_t bytesWritten;
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
::WriteFile(hFile, (LPVOID)pointer, (DWORD)size, (LPDWORD)&bytesWritten, 0);
|
|
|
|
|
#else
|
|
|
|
|
bytesWritten = fwrite(pointer, 1, size, hFile);
|
|
|
|
|
#endif
|
|
|
|
|
return bytesWritten;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t DirectoryFileHandle::Seek(s32 position, FileMove type)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
DWORD moveMethod = 0;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case FILEMOVE_BEGIN: moveMethod = FILE_BEGIN; break;
|
|
|
|
|
case FILEMOVE_CURRENT: moveMethod = FILE_CURRENT; break;
|
|
|
|
|
case FILEMOVE_END: moveMethod = FILE_END; break;
|
|
|
|
|
}
|
|
|
|
|
DWORD newPos = SetFilePointer(hFile, (LONG)position, 0, moveMethod);
|
|
|
|
|
return newPos;
|
|
|
|
|
#else
|
|
|
|
|
int moveMethod = 0;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case FILEMOVE_BEGIN: moveMethod = SEEK_SET; break;
|
|
|
|
|
case FILEMOVE_CURRENT: moveMethod = SEEK_CUR; break;
|
|
|
|
|
case FILEMOVE_END: moveMethod = SEEK_END; break;
|
|
|
|
|
}
|
|
|
|
|
fseek(hFile, position, moveMethod);
|
|
|
|
|
return ftell(hFile);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DirectoryFileHandle::Close()
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
if (hFile != (HANDLE)-1)
|
|
|
|
|
CloseHandle(hFile);
|
|
|
|
|
#else
|
|
|
|
|
if (hFile != 0)
|
|
|
|
|
fclose(hFile);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u64 getFileSize(std::string& fileName)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
WIN32_FILE_ATTRIBUTE_DATA data;
|
|
|
|
|
GetFileAttributesEx(fileName.c_str(), GetFileExInfoStandard, &data);
|
|
|
|
|
|
|
|
|
|
return data.nFileSizeLow | ((u64)data.nFileSizeHigh<<32);
|
|
|
|
|
#else
|
|
|
|
|
struct stat s;
|
|
|
|
|
stat(fileName.c_str(), &s);
|
|
|
|
|
return s.st_size;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DirectoryFileSystem::DirectoryFileSystem(IHandleAllocator *_hAlloc, std::string _basePath) : basePath(_basePath) {
|
|
|
|
|
File::CreateFullPath(basePath);
|
|
|
|
|
hAlloc = _hAlloc;
|
|
|
|
@ -140,11 +324,7 @@ DirectoryFileSystem::DirectoryFileSystem(IHandleAllocator *_hAlloc, std::string
|
|
|
|
|
|
|
|
|
|
DirectoryFileSystem::~DirectoryFileSystem() {
|
|
|
|
|
for (auto iter = entries.begin(); iter != entries.end(); ++iter) {
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
CloseHandle((*iter).second.hFile);
|
|
|
|
|
#else
|
|
|
|
|
fclose((*iter).second.hFile);
|
|
|
|
|
#endif
|
|
|
|
|
iter->second.hFile.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -165,13 +345,12 @@ std::string DirectoryFileSystem::GetLocalPath(std::string localpath) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool DirectoryFileSystem::MkDir(const std::string &dirname) {
|
|
|
|
|
|
|
|
|
|
#if HOST_IS_CASE_SENSITIVE
|
|
|
|
|
// Must fix case BEFORE attempting, because MkDir would create
|
|
|
|
|
// duplicate (different case) directories
|
|
|
|
|
|
|
|
|
|
std::string fixedCase = dirname;
|
|
|
|
|
if ( ! FixPathCase(fixedCase, FPC_PARTIAL_ALLOWED) )
|
|
|
|
|
if ( ! FixPathCase(basePath,fixedCase, FPC_PARTIAL_ALLOWED) )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return File::CreateFullPath(GetLocalPath(fixedCase));
|
|
|
|
@ -190,7 +369,7 @@ bool DirectoryFileSystem::RmDir(const std::string &dirname) {
|
|
|
|
|
|
|
|
|
|
// Nope, fix case and try again
|
|
|
|
|
fullName = dirname;
|
|
|
|
|
if ( ! FixPathCase(fullName, FPC_FILE_MUST_EXIST) )
|
|
|
|
|
if ( ! FixPathCase(basePath,fullName, FPC_FILE_MUST_EXIST) )
|
|
|
|
|
return false; // or go on and attempt (for a better error code than just false?)
|
|
|
|
|
|
|
|
|
|
fullName = GetLocalPath(fullName);
|
|
|
|
@ -225,7 +404,7 @@ int DirectoryFileSystem::RenameFile(const std::string &from, const std::string &
|
|
|
|
|
|
|
|
|
|
#if HOST_IS_CASE_SENSITIVE
|
|
|
|
|
// In case TO should overwrite a file with different case
|
|
|
|
|
if ( ! FixPathCase(fullTo, FPC_PATH_MUST_EXIST) )
|
|
|
|
|
if ( ! FixPathCase(basePath,fullTo, FPC_PATH_MUST_EXIST) )
|
|
|
|
|
return -1; // or go on and attempt (for a better error code than just false?)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
@ -243,7 +422,7 @@ int DirectoryFileSystem::RenameFile(const std::string &from, const std::string &
|
|
|
|
|
{
|
|
|
|
|
// May have failed due to case sensitivity on FROM, so try again
|
|
|
|
|
fullFrom = from;
|
|
|
|
|
if ( ! FixPathCase(fullFrom, FPC_FILE_MUST_EXIST) )
|
|
|
|
|
if ( ! FixPathCase(basePath,fullFrom, FPC_FILE_MUST_EXIST) )
|
|
|
|
|
return -1; // or go on and attempt (for a better error code than just false?)
|
|
|
|
|
fullFrom = GetLocalPath(fullFrom);
|
|
|
|
|
|
|
|
|
@ -272,7 +451,7 @@ bool DirectoryFileSystem::RemoveFile(const std::string &filename) {
|
|
|
|
|
{
|
|
|
|
|
// May have failed due to case sensitivity, so try again
|
|
|
|
|
fullName = filename;
|
|
|
|
|
if ( ! FixPathCase(fullName, FPC_FILE_MUST_EXIST) )
|
|
|
|
|
if ( ! FixPathCase(basePath,fullName, FPC_FILE_MUST_EXIST) )
|
|
|
|
|
return false; // or go on and attempt (for a better error code than just false?)
|
|
|
|
|
fullName = GetLocalPath(fullName);
|
|
|
|
|
|
|
|
|
@ -288,95 +467,8 @@ bool DirectoryFileSystem::RemoveFile(const std::string &filename) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u32 DirectoryFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) {
|
|
|
|
|
#if HOST_IS_CASE_SENSITIVE
|
|
|
|
|
if (access & (FILEACCESS_APPEND|FILEACCESS_CREATE|FILEACCESS_WRITE))
|
|
|
|
|
{
|
|
|
|
|
DEBUG_LOG(HLE, "Checking case for path %s", filename.c_str());
|
|
|
|
|
if ( ! FixPathCase(filename, FPC_PATH_MUST_EXIST) )
|
|
|
|
|
return 0; // or go on and attempt (for a better error code than just 0?)
|
|
|
|
|
}
|
|
|
|
|
// else we try fopen first (in case we're lucky) before simulating case insensitivity
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
std::string fullName = GetLocalPath(filename);
|
|
|
|
|
const char *fullNameC = fullName.c_str();
|
|
|
|
|
INFO_LOG(HLE,"Actually opening %s (%s)", fullNameC, filename.c_str());
|
|
|
|
|
|
|
|
|
|
OpenFileEntry entry;
|
|
|
|
|
|
|
|
|
|
//TODO: tests, should append seek to end of file? seeking in a file opened for append?
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
// Convert parameters to Windows permissions and access
|
|
|
|
|
DWORD desired = 0;
|
|
|
|
|
DWORD sharemode = 0;
|
|
|
|
|
DWORD openmode = 0;
|
|
|
|
|
if (access & FILEACCESS_READ) {
|
|
|
|
|
desired |= GENERIC_READ;
|
|
|
|
|
sharemode |= FILE_SHARE_READ;
|
|
|
|
|
}
|
|
|
|
|
if (access & FILEACCESS_WRITE) {
|
|
|
|
|
desired |= GENERIC_WRITE;
|
|
|
|
|
sharemode |= FILE_SHARE_WRITE;
|
|
|
|
|
}
|
|
|
|
|
if (access & FILEACCESS_CREATE) {
|
|
|
|
|
openmode = OPEN_ALWAYS;
|
|
|
|
|
} else {
|
|
|
|
|
openmode = OPEN_EXISTING;
|
|
|
|
|
}
|
|
|
|
|
//Let's do it!
|
|
|
|
|
entry.hFile = CreateFile(fullNameC, desired, sharemode, 0, openmode, 0, 0);
|
|
|
|
|
bool success = entry.hFile != INVALID_HANDLE_VALUE;
|
|
|
|
|
#else
|
|
|
|
|
// Convert flags in access parameter to fopen access mode
|
|
|
|
|
const char *mode = NULL;
|
|
|
|
|
if (access & FILEACCESS_APPEND) {
|
|
|
|
|
if (access & FILEACCESS_READ)
|
|
|
|
|
mode = "ab+"; // append+read, create if needed
|
|
|
|
|
else
|
|
|
|
|
mode = "ab"; // append only, create if needed
|
|
|
|
|
} else if (access & FILEACCESS_WRITE) {
|
|
|
|
|
if (access & FILEACCESS_READ) {
|
|
|
|
|
// FILEACCESS_CREATE is ignored for read only, write only, and append
|
|
|
|
|
// because C++ standard fopen's nonexistant file creation can only be
|
|
|
|
|
// customized for files opened read+write
|
|
|
|
|
if (access & FILEACCESS_CREATE)
|
|
|
|
|
mode = "wb+"; // read+write, create if needed
|
|
|
|
|
else
|
|
|
|
|
mode = "rb+"; // read+write, but don't create
|
|
|
|
|
} else {
|
|
|
|
|
mode = "wb"; // write only, create if needed
|
|
|
|
|
}
|
|
|
|
|
} else { // neither write nor append, so default to read only
|
|
|
|
|
mode = "rb"; // read only, don't create
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry.hFile = fopen(fullNameC, mode);
|
|
|
|
|
bool success = entry.hFile != 0;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if HOST_IS_CASE_SENSITIVE
|
|
|
|
|
if (!success &&
|
|
|
|
|
!(access & FILEACCESS_APPEND) &&
|
|
|
|
|
!(access & FILEACCESS_CREATE) &&
|
|
|
|
|
!(access & FILEACCESS_WRITE))
|
|
|
|
|
{
|
|
|
|
|
if ( ! FixPathCase(filename, FPC_PATH_MUST_EXIST) )
|
|
|
|
|
return 0; // or go on and attempt (for a better error code than just 0?)
|
|
|
|
|
fullName = GetLocalPath(filename);
|
|
|
|
|
fullNameC = fullName.c_str();
|
|
|
|
|
|
|
|
|
|
DEBUG_LOG(HLE, "Case may have been incorrect, second try opening %s (%s)", fullNameC, filename.c_str());
|
|
|
|
|
|
|
|
|
|
// And try again with the correct case this time
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
entry.hFile = CreateFile(fullNameC, desired, sharemode, 0, openmode, 0, 0);
|
|
|
|
|
success = entry.hFile != INVALID_HANDLE_VALUE;
|
|
|
|
|
#else
|
|
|
|
|
entry.hFile = fopen(fullNameC, mode);
|
|
|
|
|
success = entry.hFile != 0;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
bool success = entry.hFile.Open(basePath,filename,access);
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
@ -389,7 +481,7 @@ u32 DirectoryFileSystem::OpenFile(std::string filename, FileAccess access, const
|
|
|
|
|
} else {
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
if (access & FILEACCESS_APPEND)
|
|
|
|
|
SetFilePointer(entry.hFile, 0, NULL, FILE_END);
|
|
|
|
|
entry.hFile.Seek(0,FILEMOVE_END);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
u32 newHandle = hAlloc->GetNewHandle();
|
|
|
|
@ -403,11 +495,7 @@ void DirectoryFileSystem::CloseFile(u32 handle) {
|
|
|
|
|
EntryMap::iterator iter = entries.find(handle);
|
|
|
|
|
if (iter != entries.end()) {
|
|
|
|
|
hAlloc->FreeHandle(handle);
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
CloseHandle((*iter).second.hFile);
|
|
|
|
|
#else
|
|
|
|
|
fclose((*iter).second.hFile);
|
|
|
|
|
#endif
|
|
|
|
|
iter->second.hFile.Close();
|
|
|
|
|
entries.erase(iter);
|
|
|
|
|
} else {
|
|
|
|
|
//This shouldn't happen...
|
|
|
|
@ -424,12 +512,7 @@ size_t DirectoryFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size) {
|
|
|
|
|
EntryMap::iterator iter = entries.find(handle);
|
|
|
|
|
if (iter != entries.end())
|
|
|
|
|
{
|
|
|
|
|
size_t bytesRead;
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
::ReadFile(iter->second.hFile, (LPVOID)pointer, (DWORD)size, (LPDWORD)&bytesRead, 0);
|
|
|
|
|
#else
|
|
|
|
|
bytesRead = fread(pointer, 1, size, iter->second.hFile);
|
|
|
|
|
#endif
|
|
|
|
|
size_t bytesRead = iter->second.hFile.Read(pointer,size);
|
|
|
|
|
return bytesRead;
|
|
|
|
|
} else {
|
|
|
|
|
//This shouldn't happen...
|
|
|
|
@ -442,12 +525,7 @@ size_t DirectoryFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size) {
|
|
|
|
|
EntryMap::iterator iter = entries.find(handle);
|
|
|
|
|
if (iter != entries.end())
|
|
|
|
|
{
|
|
|
|
|
size_t bytesWritten;
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
::WriteFile(iter->second.hFile, (LPVOID)pointer, (DWORD)size, (LPDWORD)&bytesWritten, 0);
|
|
|
|
|
#else
|
|
|
|
|
bytesWritten = fwrite(pointer, 1, size, iter->second.hFile);
|
|
|
|
|
#endif
|
|
|
|
|
size_t bytesWritten = iter->second.hFile.Write(pointer,size);
|
|
|
|
|
return bytesWritten;
|
|
|
|
|
} else {
|
|
|
|
|
//This shouldn't happen...
|
|
|
|
@ -459,25 +537,7 @@ size_t DirectoryFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size) {
|
|
|
|
|
size_t DirectoryFileSystem::SeekFile(u32 handle, s32 position, FileMove type) {
|
|
|
|
|
EntryMap::iterator iter = entries.find(handle);
|
|
|
|
|
if (iter != entries.end()) {
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
DWORD moveMethod = 0;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case FILEMOVE_BEGIN: moveMethod = FILE_BEGIN; break;
|
|
|
|
|
case FILEMOVE_CURRENT: moveMethod = FILE_CURRENT; break;
|
|
|
|
|
case FILEMOVE_END: moveMethod = FILE_END; break;
|
|
|
|
|
}
|
|
|
|
|
DWORD newPos = SetFilePointer((*iter).second.hFile, (LONG)position, 0, moveMethod);
|
|
|
|
|
return newPos;
|
|
|
|
|
#else
|
|
|
|
|
int moveMethod = 0;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case FILEMOVE_BEGIN: moveMethod = SEEK_SET; break;
|
|
|
|
|
case FILEMOVE_CURRENT: moveMethod = SEEK_CUR; break;
|
|
|
|
|
case FILEMOVE_END: moveMethod = SEEK_END; break;
|
|
|
|
|
}
|
|
|
|
|
fseek(iter->second.hFile, position, moveMethod);
|
|
|
|
|
return ftell(iter->second.hFile);
|
|
|
|
|
#endif
|
|
|
|
|
return iter->second.hFile.Seek(position,type);
|
|
|
|
|
} else {
|
|
|
|
|
//This shouldn't happen...
|
|
|
|
|
ERROR_LOG(HLE,"Cannot seek in file that hasn't been opened: %08x", handle);
|
|
|
|
@ -492,7 +552,7 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename) {
|
|
|
|
|
std::string fullName = GetLocalPath(filename);
|
|
|
|
|
if (! File::Exists(fullName)) {
|
|
|
|
|
#if HOST_IS_CASE_SENSITIVE
|
|
|
|
|
if (! FixPathCase(filename, FPC_FILE_MUST_EXIST))
|
|
|
|
|
if (! FixPathCase(basePath,filename, FPC_FILE_MUST_EXIST))
|
|
|
|
|
return x;
|
|
|
|
|
fullName = GetLocalPath(filename);
|
|
|
|
|
|
|
|
|
@ -509,14 +569,8 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename) {
|
|
|
|
|
{
|
|
|
|
|
struct stat s;
|
|
|
|
|
stat(fullName.c_str(), &s);
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
WIN32_FILE_ATTRIBUTE_DATA data;
|
|
|
|
|
GetFileAttributesEx(fullName.c_str(), GetFileExInfoStandard, &data);
|
|
|
|
|
|
|
|
|
|
x.size = data.nFileSizeLow | ((u64)data.nFileSizeHigh<<32);
|
|
|
|
|
#else
|
|
|
|
|
x.size = s.st_size;
|
|
|
|
|
#endif
|
|
|
|
|
x.size = getFileSize(fullName);
|
|
|
|
|
x.access = s.st_mode & 0x1FF;
|
|
|
|
|
localtime_r((time_t*)&s.st_atime,&x.atime);
|
|
|
|
|
localtime_r((time_t*)&s.st_ctime,&x.ctime);
|
|
|
|
@ -589,7 +643,7 @@ std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) {
|
|
|
|
|
DIR *dp = opendir(localPath.c_str());
|
|
|
|
|
|
|
|
|
|
#if HOST_IS_CASE_SENSITIVE
|
|
|
|
|
if(dp == NULL && FixPathCase(path, FPC_FILE_MUST_EXIST)) {
|
|
|
|
|
if(dp == NULL && FixPathCase(basePath,path, FPC_FILE_MUST_EXIST)) {
|
|
|
|
|
// May have failed due to case sensitivity, try again
|
|
|
|
|
localPath = GetLocalPath(path);
|
|
|
|
|
dp = opendir(localPath.c_str());
|
|
|
|
@ -631,6 +685,445 @@ void DirectoryFileSystem::DoState(PointerWrap &p) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VirtualDiscFileSystem::VirtualDiscFileSystem(IHandleAllocator *_hAlloc, std::string _basePath)
|
|
|
|
|
: basePath(_basePath),currentBlockIndex(0) {
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
if (basePath.size() > 0 && basePath[basePath.size()-1] != '\\')
|
|
|
|
|
basePath = basePath + "\\";
|
|
|
|
|
#else
|
|
|
|
|
if (basePath.size() > 0 && basePath[basePath.size()-1] != '/')
|
|
|
|
|
basePath = basePath + "/";
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
hAlloc = _hAlloc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VirtualDiscFileSystem::~VirtualDiscFileSystem() {
|
|
|
|
|
for (auto iter = entries.begin(); iter != entries.end(); ++iter) {
|
|
|
|
|
if (!iter->second.type != VFILETYPE_ISO)
|
|
|
|
|
iter->second.hFile.Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VirtualDiscFileSystem::DoState(PointerWrap &p)
|
|
|
|
|
{
|
|
|
|
|
int fileListSize = fileList.size();
|
|
|
|
|
int entryCount = entries.size();
|
|
|
|
|
|
|
|
|
|
p.Do(fileListSize);
|
|
|
|
|
p.Do(entryCount);
|
|
|
|
|
p.Do(currentBlockIndex);
|
|
|
|
|
|
|
|
|
|
if (p.mode == p.MODE_READ)
|
|
|
|
|
{
|
|
|
|
|
fileList.clear();
|
|
|
|
|
entries.clear();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < fileListSize; i++)
|
|
|
|
|
{
|
|
|
|
|
FileListEntry entry;
|
|
|
|
|
p.Do(entry.fileName);
|
|
|
|
|
p.Do(entry.firstBlock);
|
|
|
|
|
p.Do(entry.totalSize);
|
|
|
|
|
fileList.push_back(entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < entryCount; i++)
|
|
|
|
|
{
|
|
|
|
|
u32 fd;
|
|
|
|
|
OpenFileEntry of;
|
|
|
|
|
|
|
|
|
|
p.Do(fd);
|
|
|
|
|
p.Do(of.fileIndex);
|
|
|
|
|
p.Do(of.type);
|
|
|
|
|
p.Do(of.curOffset);
|
|
|
|
|
p.Do(of.startOffset);
|
|
|
|
|
p.Do(of.size);
|
|
|
|
|
|
|
|
|
|
// open file
|
|
|
|
|
if (of.type != VFILETYPE_ISO)
|
|
|
|
|
{
|
|
|
|
|
bool success = of.hFile.Open(basePath,fileList[of.fileIndex].fileName,FILEACCESS_READ);
|
|
|
|
|
if (!success)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(FILESYS, "Failed to create file handle for %s.",fileList[of.fileIndex].fileName.c_str());
|
|
|
|
|
} else {
|
|
|
|
|
if (of.type == VFILETYPE_LBN)
|
|
|
|
|
{
|
|
|
|
|
of.hFile.Seek(of.curOffset+of.startOffset,FILEMOVE_BEGIN);
|
|
|
|
|
} else {
|
|
|
|
|
of.hFile.Seek(of.curOffset,FILEMOVE_BEGIN);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entries[fd] = of;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (int i = 0; i < fileListSize; i++)
|
|
|
|
|
{
|
|
|
|
|
p.Do(fileList[i].fileName);
|
|
|
|
|
p.Do(fileList[i].firstBlock);
|
|
|
|
|
p.Do(fileList[i].totalSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (EntryMap::iterator it = entries.begin(), end = entries.end(); it != end; ++it)
|
|
|
|
|
{
|
|
|
|
|
OpenFileEntry &of = it->second;
|
|
|
|
|
|
|
|
|
|
p.Do(it->first);
|
|
|
|
|
p.Do(of.fileIndex);
|
|
|
|
|
p.Do(of.type);
|
|
|
|
|
p.Do(of.curOffset);
|
|
|
|
|
p.Do(of.startOffset);
|
|
|
|
|
p.Do(of.size);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.DoMarker("VirtualDiscFileSystem");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string VirtualDiscFileSystem::GetLocalPath(std::string localpath) {
|
|
|
|
|
if (localpath.empty())
|
|
|
|
|
return basePath;
|
|
|
|
|
|
|
|
|
|
if (localpath[0] == '/')
|
|
|
|
|
localpath.erase(0,1);
|
|
|
|
|
//Convert slashes
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
for (size_t i = 0; i < localpath.size(); i++) {
|
|
|
|
|
if (localpath[i] == '/')
|
|
|
|
|
localpath[i] = '\\';
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return basePath + localpath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VirtualDiscFileSystem::getFileListIndex(std::string& fileName)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < fileList.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
if (fileList[i].fileName == fileName)
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unknown file - add it
|
|
|
|
|
std::string fullName = GetLocalPath(fileName);
|
|
|
|
|
if (! File::Exists(fullName)) {
|
|
|
|
|
#if HOST_IS_CASE_SENSITIVE
|
|
|
|
|
if (! FixPathCase(basePath,fileName, FPC_FILE_MUST_EXIST))
|
|
|
|
|
return -1;
|
|
|
|
|
fullName = GetLocalPath(fileName);
|
|
|
|
|
|
|
|
|
|
if (! File::Exists(fullName))
|
|
|
|
|
return -1;
|
|
|
|
|
#else
|
|
|
|
|
return -1;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileType type = File::IsDirectory(fullName) ? FILETYPE_DIRECTORY : FILETYPE_NORMAL;
|
|
|
|
|
if (type == FILETYPE_DIRECTORY)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
FileListEntry entry;
|
|
|
|
|
entry.fileName = fileName;
|
|
|
|
|
entry.totalSize = getFileSize(fullName);
|
|
|
|
|
entry.firstBlock = currentBlockIndex;
|
|
|
|
|
currentBlockIndex += (entry.totalSize+2047)/2048;
|
|
|
|
|
|
|
|
|
|
fileList.push_back(entry);
|
|
|
|
|
|
|
|
|
|
return fileList.size()-1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VirtualDiscFileSystem::getFileListIndex(u32 accessBlock, u32 accessSize)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < fileList.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
if (fileList[i].firstBlock <= accessBlock)
|
|
|
|
|
{
|
|
|
|
|
u32 sectorOffset = (accessBlock-fileList[i].firstBlock)*2048;
|
|
|
|
|
u32 endOffset = sectorOffset+accessSize;
|
|
|
|
|
if (endOffset <= fileList[i].totalSize)
|
|
|
|
|
{
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u32 VirtualDiscFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename)
|
|
|
|
|
{
|
|
|
|
|
OpenFileEntry entry;
|
|
|
|
|
entry.curOffset = 0;
|
|
|
|
|
entry.size = 0;
|
|
|
|
|
entry.startOffset = 0;
|
|
|
|
|
|
|
|
|
|
if (filename == "")
|
|
|
|
|
{
|
|
|
|
|
entry.type = VFILETYPE_ISO;
|
|
|
|
|
entry.fileIndex = -1;
|
|
|
|
|
|
|
|
|
|
u32 newHandle = hAlloc->GetNewHandle();
|
|
|
|
|
entries[newHandle] = entry;
|
|
|
|
|
|
|
|
|
|
return newHandle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (filename.compare(0,8,"/sce_lbn") == 0)
|
|
|
|
|
{
|
|
|
|
|
u32 sectorStart = 0xFFFFFFFF, readSize = 0xFFFFFFFF;
|
|
|
|
|
parseLBN(filename, §orStart, &readSize);
|
|
|
|
|
|
|
|
|
|
entry.type = VFILETYPE_LBN;
|
|
|
|
|
entry.size = readSize;
|
|
|
|
|
|
|
|
|
|
entry.fileIndex = getFileListIndex(sectorStart,readSize);
|
|
|
|
|
if (entry.fileIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(FILESYS, "VirtualDiscFileSystem: sce_lbn used without calling fileinfo.");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry.startOffset = (sectorStart-fileList[entry.fileIndex].firstBlock)*2048;
|
|
|
|
|
|
|
|
|
|
// now we just need an actual file handle
|
|
|
|
|
bool success = entry.hFile.Open(basePath,fileList[entry.fileIndex].fileName,FILEACCESS_READ);
|
|
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
{
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
ERROR_LOG(HLE, "VirtualDiscFileSystem::OpenFile: FAILED, %i", GetLastError());
|
|
|
|
|
#else
|
|
|
|
|
ERROR_LOG(HLE, "VirtualDiscFileSystem::OpenFile: FAILED");
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// seek to start
|
|
|
|
|
entry.hFile.Seek(entry.startOffset,FILEMOVE_BEGIN);
|
|
|
|
|
|
|
|
|
|
u32 newHandle = hAlloc->GetNewHandle();
|
|
|
|
|
entries[newHandle] = entry;
|
|
|
|
|
|
|
|
|
|
return newHandle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entry.type = VFILETYPE_NORMAL;
|
|
|
|
|
bool success = entry.hFile.Open(basePath,filename,access);
|
|
|
|
|
|
|
|
|
|
if (!success) {
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
ERROR_LOG(HLE, "VirtualDiscFileSystem::OpenFile: FAILED, %i - access = %i", GetLastError(), (int)access);
|
|
|
|
|
#else
|
|
|
|
|
ERROR_LOG(HLE, "VirtualDiscFileSystem::OpenFile: FAILED, access = %i", (int)access);
|
|
|
|
|
#endif
|
|
|
|
|
//wwwwaaaaahh!!
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
entry.fileIndex = getFileListIndex(filename);
|
|
|
|
|
|
|
|
|
|
u32 newHandle = hAlloc->GetNewHandle();
|
|
|
|
|
entries[newHandle] = entry;
|
|
|
|
|
|
|
|
|
|
return newHandle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t VirtualDiscFileSystem::SeekFile(u32 handle, s32 position, FileMove type) {
|
|
|
|
|
EntryMap::iterator iter = entries.find(handle);
|
|
|
|
|
if (iter != entries.end()) {
|
|
|
|
|
switch (iter->second.type)
|
|
|
|
|
{
|
|
|
|
|
case VFILETYPE_NORMAL:
|
|
|
|
|
{
|
|
|
|
|
return iter->second.hFile.Seek(position,type);
|
|
|
|
|
}
|
|
|
|
|
case VFILETYPE_LBN:
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case FILEMOVE_BEGIN: iter->second.curOffset = position; break;
|
|
|
|
|
case FILEMOVE_CURRENT: iter->second.curOffset += position; break;
|
|
|
|
|
case FILEMOVE_END: iter->second.curOffset = iter->second.size-position; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u32 off = iter->second.startOffset+iter->second.curOffset;
|
|
|
|
|
iter->second.hFile.Seek(off,FILEMOVE_BEGIN);
|
|
|
|
|
return iter->second.curOffset;
|
|
|
|
|
}
|
|
|
|
|
case VFILETYPE_ISO:
|
|
|
|
|
{
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case FILEMOVE_BEGIN: iter->second.curOffset = position; break;
|
|
|
|
|
case FILEMOVE_CURRENT: iter->second.curOffset += position; break;
|
|
|
|
|
case FILEMOVE_END: return -1; // unsupported
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return iter->second.curOffset;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
//This shouldn't happen...
|
|
|
|
|
ERROR_LOG(HLE,"VirtualDiscFileSystem: Cannot seek in file that hasn't been opened: %08x", handle);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t VirtualDiscFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size) {
|
|
|
|
|
EntryMap::iterator iter = entries.find(handle);
|
|
|
|
|
if (iter != entries.end())
|
|
|
|
|
{
|
|
|
|
|
// it's the whole iso... it could reference any of the files on the disc.
|
|
|
|
|
// For now let's just open and close the files on demand. Can certainly be done
|
|
|
|
|
// better though
|
|
|
|
|
if (iter->second.type == VFILETYPE_ISO)
|
|
|
|
|
{
|
|
|
|
|
int fileIndex = getFileListIndex(iter->second.curOffset,size*2048);
|
|
|
|
|
if (fileIndex == -1)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(HLE,"VirtualDiscFileSystem: Reading from unknown address", handle);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DirectoryFileHandle hFile;
|
|
|
|
|
bool success = hFile.Open(basePath,fileList[fileIndex].fileName,FILEACCESS_READ);
|
|
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(HLE,"VirtualDiscFileSystem: Error opening file %s", fileList[fileIndex].fileName.c_str());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u32 startOffset = (iter->second.curOffset-fileList[fileIndex].firstBlock)*2048;
|
|
|
|
|
size_t bytesRead;
|
|
|
|
|
|
|
|
|
|
hFile.Seek(startOffset,FILEMOVE_BEGIN);
|
|
|
|
|
bytesRead = hFile.Read(pointer,size*2048);
|
|
|
|
|
hFile.Close();
|
|
|
|
|
|
|
|
|
|
return bytesRead;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t bytesRead = iter->second.hFile.Read(pointer,size);
|
|
|
|
|
iter->second.curOffset += bytesRead;
|
|
|
|
|
return bytesRead;
|
|
|
|
|
} else {
|
|
|
|
|
//This shouldn't happen...
|
|
|
|
|
ERROR_LOG(HLE,"VirtualDiscFileSystem: Cannot read file that hasn't been opened: %08x", handle);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VirtualDiscFileSystem::CloseFile(u32 handle) {
|
|
|
|
|
EntryMap::iterator iter = entries.find(handle);
|
|
|
|
|
if (iter != entries.end()) {
|
|
|
|
|
hAlloc->FreeHandle(handle);
|
|
|
|
|
iter->second.hFile.Close();
|
|
|
|
|
entries.erase(iter);
|
|
|
|
|
} else {
|
|
|
|
|
//This shouldn't happen...
|
|
|
|
|
ERROR_LOG(HLE,"VirtualDiscFileSystem: Cannot close file that hasn't been opened: %08x", handle);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VirtualDiscFileSystem::OwnsHandle(u32 handle) {
|
|
|
|
|
EntryMap::iterator iter = entries.find(handle);
|
|
|
|
|
return (iter != entries.end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PSPFileInfo VirtualDiscFileSystem::GetFileInfo(std::string filename) {
|
|
|
|
|
PSPFileInfo x;
|
|
|
|
|
x.name = filename;
|
|
|
|
|
|
|
|
|
|
std::string fullName = GetLocalPath(filename);
|
|
|
|
|
if (! File::Exists(fullName)) {
|
|
|
|
|
#if HOST_IS_CASE_SENSITIVE
|
|
|
|
|
if (! FixPathCase(basePath,filename, FPC_FILE_MUST_EXIST))
|
|
|
|
|
return x;
|
|
|
|
|
fullName = GetLocalPath(filename);
|
|
|
|
|
|
|
|
|
|
if (! File::Exists(fullName))
|
|
|
|
|
return x;
|
|
|
|
|
#else
|
|
|
|
|
return x;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
x.type = File::IsDirectory(fullName) ? FILETYPE_DIRECTORY : FILETYPE_NORMAL;
|
|
|
|
|
x.exists = true;
|
|
|
|
|
|
|
|
|
|
if (x.type != FILETYPE_DIRECTORY)
|
|
|
|
|
{
|
|
|
|
|
struct stat s;
|
|
|
|
|
stat(fullName.c_str(), &s);
|
|
|
|
|
|
|
|
|
|
x.size = getFileSize(fullName);
|
|
|
|
|
|
|
|
|
|
int fileIndex = getFileListIndex(filename);
|
|
|
|
|
x.startSector = fileList[fileIndex].firstBlock;
|
|
|
|
|
x.numSectors = (x.size+2047)/2048;
|
|
|
|
|
|
|
|
|
|
x.access = s.st_mode & 0x1FF;
|
|
|
|
|
localtime_r((time_t*)&s.st_atime,&x.atime);
|
|
|
|
|
localtime_r((time_t*)&s.st_ctime,&x.ctime);
|
|
|
|
|
localtime_r((time_t*)&s.st_mtime,&x.mtime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VirtualDiscFileSystem::GetHostPath(const std::string &inpath, std::string &outpath)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(HLE,"VirtualDiscFileSystem: Retrieving host path");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<PSPFileInfo> VirtualDiscFileSystem::GetDirListing(std::string path)
|
|
|
|
|
{
|
|
|
|
|
// todo
|
|
|
|
|
std::vector<PSPFileInfo> result;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t VirtualDiscFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(HLE,"VirtualDiscFileSystem: Cannot write to file on virtual disc");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VirtualDiscFileSystem::MkDir(const std::string &dirname)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(HLE,"VirtualDiscFileSystem: Cannot create directory on virtual disc");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VirtualDiscFileSystem::RmDir(const std::string &dirname)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(HLE,"VirtualDiscFileSystem: Cannot remove directory on virtual disc");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int VirtualDiscFileSystem::RenameFile(const std::string &from, const std::string &to)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(HLE,"VirtualDiscFileSystem: Cannot rename file on virtual disc");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VirtualDiscFileSystem::RemoveFile(const std::string &filename)
|
|
|
|
|
{
|
|
|
|
|
ERROR_LOG(HLE,"VirtualDiscFileSystem: Cannot remove file on virtual disc");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VFSFileSystem::VFSFileSystem(IHandleAllocator *_hAlloc, std::string _basePath) : basePath(_basePath) {
|
|
|
|
|
INFO_LOG(HLE, "Creating VFS file system");
|
|
|
|
|
hAlloc = _hAlloc;
|
|
|
|
|