mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Merge pull request #2 from Kingcom/virtfs
Fix issues in virtual disc filesystem.
This commit is contained in:
commit
9ba2af1c48
2 changed files with 36 additions and 7 deletions
|
@ -239,15 +239,17 @@ int VirtualDiscFileSystem::getFileListIndex(std::string& fileName)
|
||||||
return fileList.size()-1;
|
return fileList.size()-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int VirtualDiscFileSystem::getFileListIndex(u32 accessBlock, u32 accessSize)
|
int VirtualDiscFileSystem::getFileListIndex(u32 accessBlock, u32 accessSize, bool blockMode)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < fileList.size(); i++)
|
for (size_t i = 0; i < fileList.size(); i++)
|
||||||
{
|
{
|
||||||
if (fileList[i].firstBlock <= accessBlock)
|
if (fileList[i].firstBlock <= accessBlock)
|
||||||
{
|
{
|
||||||
u32 sectorOffset = (accessBlock-fileList[i].firstBlock)*2048;
|
u32 sectorOffset = (accessBlock-fileList[i].firstBlock)*2048;
|
||||||
|
u32 totalFileSize = blockMode ? (fileList[i].totalSize+2047) & ~2047 : fileList[i].totalSize;
|
||||||
|
|
||||||
u32 endOffset = sectorOffset+accessSize;
|
u32 endOffset = sectorOffset+accessSize;
|
||||||
if (endOffset <= fileList[i].totalSize)
|
if (endOffset <= totalFileSize)
|
||||||
{
|
{
|
||||||
return (int)i;
|
return (int)i;
|
||||||
}
|
}
|
||||||
|
@ -364,7 +366,7 @@ size_t VirtualDiscFileSystem::SeekFile(u32 handle, s32 position, FileMove type)
|
||||||
{
|
{
|
||||||
case FILEMOVE_BEGIN: iter->second.curOffset = position; break;
|
case FILEMOVE_BEGIN: iter->second.curOffset = position; break;
|
||||||
case FILEMOVE_CURRENT: iter->second.curOffset += position; break;
|
case FILEMOVE_CURRENT: iter->second.curOffset += position; break;
|
||||||
case FILEMOVE_END: return -1; // unsupported
|
case FILEMOVE_END: iter->second.curOffset = currentBlockIndex+position; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return iter->second.curOffset;
|
return iter->second.curOffset;
|
||||||
|
@ -387,7 +389,7 @@ size_t VirtualDiscFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size) {
|
||||||
// better though
|
// better though
|
||||||
if (iter->second.type == VFILETYPE_ISO)
|
if (iter->second.type == VFILETYPE_ISO)
|
||||||
{
|
{
|
||||||
int fileIndex = getFileListIndex(iter->second.curOffset,size*2048);
|
int fileIndex = getFileListIndex(iter->second.curOffset,size*2048,true);
|
||||||
if (fileIndex == -1)
|
if (fileIndex == -1)
|
||||||
{
|
{
|
||||||
ERROR_LOG(HLE,"VirtualDiscFileSystem: Reading from unknown address %08x", handle);
|
ERROR_LOG(HLE,"VirtualDiscFileSystem: Reading from unknown address %08x", handle);
|
||||||
|
@ -407,10 +409,22 @@ size_t VirtualDiscFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size) {
|
||||||
size_t bytesRead;
|
size_t bytesRead;
|
||||||
|
|
||||||
hFile.Seek(startOffset,FILEMOVE_BEGIN);
|
hFile.Seek(startOffset,FILEMOVE_BEGIN);
|
||||||
|
|
||||||
|
u32 remainingSize = fileList[fileIndex].totalSize-startOffset;
|
||||||
|
if (remainingSize < size*2048)
|
||||||
|
{
|
||||||
|
// the file doesn't fill the whole last sector
|
||||||
|
// read what's there and zero fill the rest like on a real disc
|
||||||
|
bytesRead = hFile.Read(pointer,remainingSize);
|
||||||
|
memset(&pointer[bytesRead],0,size*2048-bytesRead);
|
||||||
|
} else {
|
||||||
bytesRead = hFile.Read(pointer,size*2048);
|
bytesRead = hFile.Read(pointer,size*2048);
|
||||||
|
}
|
||||||
|
|
||||||
hFile.Close();
|
hFile.Close();
|
||||||
|
|
||||||
return bytesRead;
|
iter->second.curOffset += size;
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bytesRead = iter->second.hFile.Read(pointer,size);
|
size_t bytesRead = iter->second.hFile.Read(pointer,size);
|
||||||
|
@ -444,6 +458,21 @@ PSPFileInfo VirtualDiscFileSystem::GetFileInfo(std::string filename) {
|
||||||
PSPFileInfo x;
|
PSPFileInfo x;
|
||||||
x.name = filename;
|
x.name = filename;
|
||||||
|
|
||||||
|
if (filename.compare(0,8,"/sce_lbn") == 0)
|
||||||
|
{
|
||||||
|
u32 sectorStart = 0xFFFFFFFF, readSize = 0xFFFFFFFF;
|
||||||
|
parseLBN(filename, §orStart, &readSize);
|
||||||
|
|
||||||
|
PSPFileInfo fileInfo;
|
||||||
|
fileInfo.name = filename;
|
||||||
|
fileInfo.exists = true;
|
||||||
|
fileInfo.size = readSize;
|
||||||
|
fileInfo.startSector = sectorStart;
|
||||||
|
fileInfo.isOnSectorSystem = true;
|
||||||
|
fileInfo.numSectors = (readSize + 2047) / 2048;
|
||||||
|
return fileInfo;
|
||||||
|
}
|
||||||
|
|
||||||
std::string fullName = GetLocalPath(filename);
|
std::string fullName = GetLocalPath(filename);
|
||||||
if (! File::Exists(fullName)) {
|
if (! File::Exists(fullName)) {
|
||||||
#if HOST_IS_CASE_SENSITIVE
|
#if HOST_IS_CASE_SENSITIVE
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void LoadFileListIndex();
|
void LoadFileListIndex();
|
||||||
int getFileListIndex(std::string& fileName);
|
int getFileListIndex(std::string& fileName);
|
||||||
int getFileListIndex(u32 accessBlock, u32 accessSize);
|
int getFileListIndex(u32 accessBlock, u32 accessSize, bool blockMode = false);
|
||||||
std::string GetLocalPath(std::string localpath);
|
std::string GetLocalPath(std::string localpath);
|
||||||
|
|
||||||
typedef enum { VFILETYPE_NORMAL, VFILETYPE_LBN, VFILETYPE_ISO } VirtualFileType;
|
typedef enum { VFILETYPE_NORMAL, VFILETYPE_LBN, VFILETYPE_ISO } VirtualFileType;
|
||||||
|
|
Loading…
Add table
Reference in a new issue