Skip to content

Commit

Permalink
Open ISOs very slightly faster by not reopening
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jun 19, 2013
1 parent 0839a6e commit 61b510b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
25 changes: 11 additions & 14 deletions Core/FileSystems/BlockDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,18 @@ BlockDevice *constructBlockDevice(const char *filename) {
return 0;
char buffer[4];
auto size = fread(buffer, 1, 4, f); //size_t
fclose(f);
fseek(f, 0, SEEK_SET);
if (!memcmp(buffer, "CISO", 4) && size == 4)
return new CISOFileBlockDevice(filename);
return new CISOFileBlockDevice(f);
else if (!memcmp(buffer, "\x00PBP", 4) && size == 4)
return new NPDRMDemoBlockDevice(filename);
return new NPDRMDemoBlockDevice(f);
else
return new FileBlockDevice(filename);
return new FileBlockDevice(f);
}

FileBlockDevice::FileBlockDevice(std::string _filename)
: filename(_filename)
FileBlockDevice::FileBlockDevice(FILE *file)
: f(file)
{
f = fopen(_filename.c_str(), "rb");
fseek(f,0,SEEK_END);
filesize = ftell(f);
fseek(f,0,SEEK_SET);
Expand Down Expand Up @@ -94,12 +93,12 @@ typedef struct ciso_header

// TODO: Need much better error handling.

CISOFileBlockDevice::CISOFileBlockDevice(std::string _filename)
: filename(_filename)
CISOFileBlockDevice::CISOFileBlockDevice(FILE *file)
: f(file)
{
// CISO format is EXTREMELY crappy and incomplete. All tools make broken CISO.

f = fopen(_filename.c_str(), "rb");
f = file;
CISO_H hdr;
size_t readSize = fread(&hdr, sizeof(CISO_H), 1, f);
if (readSize != 1 || memcmp(hdr.magic, "CISO", 4) != 0)
Expand Down Expand Up @@ -206,17 +205,15 @@ bool CISOFileBlockDevice::ReadBlock(int blockNumber, u8 *outPtr)
}


NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(std::string _filename)
: filename_(_filename)
NPDRMDemoBlockDevice::NPDRMDemoBlockDevice(FILE *file)
: f(file)
{
MAC_KEY mkey;
CIPHER_KEY ckey;
u8 np_header[256];
u32 tableOffset, tableSize;
u32 lbaStart, lbaEnd;

f = fopen(_filename.c_str(), "rb");

fseek(f, 0x24, SEEK_SET);
fread(&psarOffset, 1, 4, f);
fseek(f, psarOffset, SEEK_SET);
Expand Down
9 changes: 3 additions & 6 deletions Core/FileSystems/BlockDevices.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ class BlockDevice
class CISOFileBlockDevice : public BlockDevice
{
public:
CISOFileBlockDevice(std::string _filename);
CISOFileBlockDevice(FILE *file);
~CISOFileBlockDevice();
bool ReadBlock(int blockNumber, u8 *outPtr);
u32 GetNumBlocks() { return numBlocks;}

private:
std::string filename;
FILE *f;
u32 *index;
int indexShift;
Expand All @@ -57,13 +56,12 @@ class CISOFileBlockDevice : public BlockDevice
class FileBlockDevice : public BlockDevice
{
public:
FileBlockDevice(std::string _filename);
FileBlockDevice(FILE *file);
~FileBlockDevice();
bool ReadBlock(int blockNumber, u8 *outPtr);
u32 GetNumBlocks() {return (u32)(filesize / GetBlockSize());}

private:
std::string filename;
FILE *f;
size_t filesize;
};
Expand All @@ -82,14 +80,13 @@ struct table_info {
class NPDRMDemoBlockDevice : public BlockDevice
{
public:
NPDRMDemoBlockDevice(std::string _filename);
NPDRMDemoBlockDevice(FILE *file);
~NPDRMDemoBlockDevice();

bool ReadBlock(int blockNumber, u8 *outPtr);
u32 GetNumBlocks() {return (u32)lbaSize;}

private:
std::string filename_;
FILE *f;
u32 lbaSize;

Expand Down

0 comments on commit 61b510b

Please sign in to comment.