Some minor reformatting, JLOG instrumentation of the zip file loading.

This commit is contained in:
wrenczes@gmail.com
2011-02-01 05:53:19 +00:00
parent 4d15756f76
commit 9085b2a0e1
+20 -10
View File
@@ -42,7 +42,8 @@ void JFileSystem::preloadZip(string filename){
JZipCache * cache = new JZipCache(); JZipCache * cache = new JZipCache();
mZipCache[filename] = cache; mZipCache[filename] = cache;
if (!mZipAvailable || !mZipFile) { if (!mZipAvailable || !mZipFile)
{
AttachZipFile(filename); AttachZipFile(filename);
if (!mZipAvailable || !mZipFile) return; if (!mZipAvailable || !mZipFile) return;
} }
@@ -143,8 +144,14 @@ void JFileSystem::DetachZipFile()
{ {
if (mZipAvailable && mZipFile != NULL) if (mZipAvailable && mZipFile != NULL)
{ {
unzCloseCurrentFile(mZipFile); JLOG("DetachZipFile");
unzClose(mZipFile); int error = unzCloseCurrentFile(mZipFile);
if (error < 0 )
JLOG("error calling unzCloseCurrentFile");
error = unzClose(mZipFile);
if (error < 0)
JLOG("Error calling unzClose");
} }
mZipFile = NULL; mZipFile = NULL;
@@ -154,22 +161,25 @@ void JFileSystem::DetachZipFile()
bool JFileSystem::OpenFile(const string &filename) bool JFileSystem::OpenFile(const string &filename)
{ {
string path = mResourceRoot + filename; string path = mResourceRoot + filename;
JLOG("JFileSystem::OpenFile");
JLOG(path.c_str()); JLOG(path.c_str());
if (mZipAvailable && mZipFile != NULL) if (mZipAvailable && mZipFile != NULL)
{ {
JLOG("zip available, calling preload")
preloadZip(mZipFileName); preloadZip(mZipFileName);
map<string,JZipCache *>::iterator it = mZipCache.find(mZipFileName); map<string,JZipCache *>::iterator it = mZipCache.find(mZipFileName);
if (it == mZipCache.end()){ if (it == mZipCache.end())
{
JLOG("zip cache miss, detaching & calling open again");
DetachZipFile(); DetachZipFile();
return OpenFile(filename); return OpenFile(filename);
} }
JZipCache * zc = it->second; JZipCache * zc = it->second;
map<string,unz_file_pos *>::iterator it2 = zc->dir.find(filename); map<string,unz_file_pos *>::iterator it2 = zc->dir.find(filename);
if (it2 == zc->dir.end()){ if (it2 == zc->dir.end())
{
JLOG("directory miss, detaching & calling open again");
DetachZipFile(); DetachZipFile();
return OpenFile(filename); return OpenFile(filename);
} }
@@ -177,6 +187,7 @@ bool JFileSystem::OpenFile(const string &filename)
char filenameInzip[256]; char filenameInzip[256];
unz_file_info fileInfo; unz_file_info fileInfo;
JLOG("calling unzGetCurrentFileInfo");
if (unzGetCurrentFileInfo(mZipFile, &fileInfo, filenameInzip, sizeof(filenameInzip), NULL, 0, NULL, 0) == UNZ_OK) if (unzGetCurrentFileInfo(mZipFile, &fileInfo, filenameInzip, sizeof(filenameInzip), NULL, 0, NULL, 0) == UNZ_OK)
mFileSize = fileInfo.uncompressed_size; mFileSize = fileInfo.uncompressed_size;
else else
@@ -196,20 +207,19 @@ bool JFileSystem::OpenFile(const string &filename)
return true; return true;
} }
#else #else
JLOG("calling sceIOpen");
mFile = sceIoOpen(path.c_str(), PSP_O_RDONLY, 0777); mFile = sceIoOpen(path.c_str(), PSP_O_RDONLY, 0777);
if (mFile > 0) if (mFile > 0)
{ {
JLOG("calling sceIoSeek");
mFileSize = sceIoLseek(mFile, 0, PSP_SEEK_END); mFileSize = sceIoLseek(mFile, 0, PSP_SEEK_END);
sceIoLseek(mFile, 0, PSP_SEEK_SET); sceIoLseek(mFile, 0, PSP_SEEK_SET);
return true; return true;
} }
#endif #endif
} }
return false; return false;
} }