added caching on GameListItem level and disabling current one... prolly it is a little bit slower, but it is robust

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1058 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
fires.gc 2008-11-03 11:03:36 +00:00
parent 5e261fbec3
commit 4ad86ef180
5 changed files with 255 additions and 53 deletions

View File

@ -31,6 +31,7 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include <string>
#include "Common.h" #include "Common.h"
@ -88,6 +89,41 @@ public:
PanicAlert("Do(vector<>) does not yet work."); PanicAlert("Do(vector<>) does not yet work.");
} }
// Store strings.
void Do(std::string &x)
{
int stringLen = x.length() + 1;
Do(stringLen);
switch (mode)
{
case MODE_READ: x = (char*)*ptr; break;
case MODE_WRITE: memcpy(*ptr, x.c_str(), stringLen); break;
case MODE_MEASURE: break;
}
(*ptr) += stringLen;
}
void DoBuffer(u8** pBuffer, u32& _Size)
{
Do(_Size);
if (_Size > 0)
{
switch (mode)
{
case MODE_READ: *pBuffer = new u8[_Size]; memcpy(*pBuffer, *ptr, _Size); break;
case MODE_WRITE: memcpy(*ptr, *pBuffer, _Size); break;
case MODE_MEASURE: break;
}
}
else
{
*pBuffer = NULL;
}
(*ptr) += _Size;
}
template<class T> template<class T>
void DoArray(T *x, int count) { void DoArray(T *x, int count) {
DoVoid((void *)x, sizeof(T) * count); DoVoid((void *)x, sizeof(T) * count);
@ -105,4 +141,96 @@ public:
} }
}; };
class CChunkFileReader
{
public:
template<class T>
static bool Load(const std::string& _rFilename, int _Revision, T& _class)
{
FILE* pFile = fopen(_rFilename.c_str(), "rb");
if (pFile)
{
// get size
fseek(pFile, 0, SEEK_END);
size_t FileSize = ftell(pFile);
fseek(pFile, 0, SEEK_SET);
if (FileSize < sizeof(SChunkHeader))
{
fclose(pFile);
return false;
}
// read the header
SChunkHeader Header;
fread(&Header, sizeof(SChunkHeader), 1, pFile);
if (Header.Revision != _Revision)
{
fclose(pFile);
return false;
}
// get size
int sz = FileSize - sizeof(SChunkHeader);
if (Header.ExpectedSize != sz)
{
fclose(pFile);
return false;
}
// read the state
u8* buffer = new u8[sz];
fread(buffer, 1, sz, pFile);
fclose(pFile);
u8 *ptr = buffer;
PointerWrap p(&ptr, PointerWrap::MODE_READ);
_class.DoState(p);
delete [] buffer;
return true;
}
return false;
}
template<class T>
static bool Save(const std::string& _rFilename, int _Revision, T& _class)
{
FILE* pFile = fopen(_rFilename.c_str(), "wb");
if (pFile)
{
u8 *ptr = 0;
PointerWrap p(&ptr, PointerWrap::MODE_MEASURE);
_class.DoState(p);
size_t sz = (size_t)ptr;
u8 *buffer = new u8[sz];
ptr = buffer;
p.SetMode(PointerWrap::MODE_WRITE);
_class.DoState(p);
SChunkHeader Header;
Header.Compress = 0;
Header.Revision = _Revision;
Header.ExpectedSize = sz;
fwrite(&Header, sizeof(SChunkHeader), 1, pFile);
fwrite(buffer, sz, 1, pFile);
fclose(pFile);
return true;
}
return false;
}
private:
struct SChunkHeader
{
int Revision;
int Compress;
int ExpectedSize;
};
};
#endif // _POINTERWRAP_H #endif // _POINTERWRAP_H

View File

@ -1111,10 +1111,6 @@
RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_fs.h" RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_fs.h"
> >
</File> </File>
<File
RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_net.cpp"
>
</File>
<File <File
RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_net.h" RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_net.h"
> >
@ -1356,6 +1352,10 @@
RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_fs.cpp" RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_fs.cpp"
> >
</File> </File>
<File
RelativePath=".\Src\IPC_HLE\WII_IPC_HLE_Device_net.cpp"
>
</File>
<File <File
RelativePath=".\Src\IPC_HLE\WiiMote_HID_Attr.cpp" RelativePath=".\Src\IPC_HLE\WiiMote_HID_Attr.cpp"
> >

View File

@ -334,6 +334,7 @@ void CGameListCtrl::SetBackgroundColor()
void CGameListCtrl::ScanForISOs(bool loadcache) void CGameListCtrl::ScanForISOs(bool loadcache)
{ {
#if 0
FILE * cacheFile; FILE * cacheFile;
bool scanISO = true; bool scanISO = true;
if (loadcache) if (loadcache)
@ -358,6 +359,7 @@ void CGameListCtrl::ScanForISOs(bool loadcache)
} }
} }
m_ISOFiles.clear(); m_ISOFiles.clear();
if (!scanISO) if (!scanISO)
{ {
// TODO: complete cache loading here. this means ADDING THE BANNER >_< // TODO: complete cache loading here. this means ADDING THE BANNER >_<
@ -483,6 +485,8 @@ void CGameListCtrl::ScanForISOs(bool loadcache)
} }
} }
else else
#endif
{ {
CFileSearch::XStringVector Directories(SConfig::GetInstance().m_ISOFolder); CFileSearch::XStringVector Directories(SConfig::GetInstance().m_ISOFolder);
@ -528,6 +532,7 @@ void CGameListCtrl::ScanForISOs(bool loadcache)
GameListItem ISOFile(rFilenames[i]); GameListItem ISOFile(rFilenames[i]);
if (ISOFile.IsValid()) if (ISOFile.IsValid())
{ {
#if 0
if(cacheFile) if(cacheFile)
{ {
fseek(cacheFile, 0L, SEEK_END); fseek(cacheFile, 0L, SEEK_END);
@ -547,13 +552,16 @@ void CGameListCtrl::ScanForISOs(bool loadcache)
// TODO: add the banner saving TO 1 FILE AND JPG as well & make the cache MUCH better. // TODO: add the banner saving TO 1 FILE AND JPG as well & make the cache MUCH better.
// This is ugly as fuck // This is ugly as fuck
} }
#endif 0
m_ISOFiles.push_back(ISOFile); m_ISOFiles.push_back(ISOFile);
} }
else else
PanicAlert("Invalid ISO file %s", rFilenames[i].c_str()); PanicAlert("Invalid ISO file %s", rFilenames[i].c_str());
} }
} }
#if 0
fclose (cacheFile); fclose (cacheFile);
#endif
} }
std::sort(m_ISOFiles.begin(), m_ISOFiles.end()); std::sort(m_ISOFiles.begin(), m_ISOFiles.end());
} }

View File

@ -17,19 +17,22 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <wx/mstream.h>
#include "Globals.h" #include "Globals.h"
#include "FileUtil.h" #include "FileUtil.h"
#include "ISOFile.h" #include "ISOFile.h"
#include "StringUtil.h"
#include "VolumeCreator.h" #include "VolumeCreator.h"
#include "Filesystem.h" #include "Filesystem.h"
#include "BannerLoader.h" #include "BannerLoader.h"
#include "FileSearch.h" #include "FileSearch.h"
#include "CompressedBlob.h" #include "CompressedBlob.h"
#include "ChunkFile.h"
#include "../resources/no_banner.cpp" #include "../resources/no_banner.cpp"
#include <wx/mstream.h> #define CACHE_REVISION 0x103
#define DVD_BANNER_WIDTH 96 #define DVD_BANNER_WIDTH 96
#define DVD_BANNER_HEIGHT 32 #define DVD_BANNER_HEIGHT 32
@ -37,11 +40,20 @@
static u32 g_ImageTemp[DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT]; static u32 g_ImageTemp[DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT];
GameListItem::GameListItem(const std::string& _rFileName) GameListItem::GameListItem(const std::string& _rFileName)
: m_FileName(_rFileName), : m_FileName(_rFileName)
m_FileSize(0), , m_FileSize(0)
m_Valid(false), , m_Valid(false)
m_BlobCompressed(false) , m_BlobCompressed(false)
, m_pImage(NULL)
, m_ImageSize(0)
{ {
if (LoadFromCache())
{
m_Valid = true;
}
else
{
DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(_rFileName); DiscIO::IVolume* pVolume = DiscIO::CreateVolumeFromFilename(_rFileName);
if (pVolume != NULL) if (pVolume != NULL)
@ -70,25 +82,16 @@ GameListItem::GameListItem(const std::string& _rFileName)
pBannerLoader->GetDescription(m_Description); pBannerLoader->GetDescription(m_Description);
if (pBannerLoader->GetBanner(g_ImageTemp)) if (pBannerLoader->GetBanner(g_ImageTemp))
{ {
unsigned char* pImage = (unsigned char*)malloc(DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT * 3); m_ImageSize = DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT * 3;
m_pImage = new u8[m_ImageSize]; //(u8*)malloc(m_ImageSize);
for (size_t i = 0; i < DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT; i++) for (size_t i = 0; i < DVD_BANNER_WIDTH * DVD_BANNER_HEIGHT; i++)
{ {
pImage[i * 3 + 0] = (g_ImageTemp[i] & 0xFF0000) >> 16; m_pImage[i * 3 + 0] = (g_ImageTemp[i] & 0xFF0000) >> 16;
pImage[i * 3 + 1] = (g_ImageTemp[i] & 0x00FF00) >> 8; m_pImage[i * 3 + 1] = (g_ImageTemp[i] & 0x00FF00) >> 8;
pImage[i * 3 + 2] = (g_ImageTemp[i] & 0x0000FF) >> 0; m_pImage[i * 3 + 2] = (g_ImageTemp[i] & 0x0000FF) >> 0;
}
m_Image.Create(DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT, pImage);
} }
} }
else
{
// default banner
wxMemoryInputStream istream(no_banner_png, sizeof no_banner_png);
wxImage iNoBanner(istream, wxBITMAP_TYPE_PNG);
m_Image = iNoBanner;
} }
delete pBannerLoader; delete pBannerLoader;
@ -96,14 +99,66 @@ GameListItem::GameListItem(const std::string& _rFileName)
delete pFileSystem; delete pFileSystem;
} }
delete pVolume; delete pVolume;
m_Valid = true; m_Valid = true;
SaveToCache();
}
}
// i am not sure if this is a leak or if wxImage will release the code
if (m_pImage)
{
#if !defined(OSX64)
m_Image.Create(DVD_BANNER_WIDTH, DVD_BANNER_HEIGHT, m_pImage);
#endif
}
else
{
// default banner
wxMemoryInputStream istream(no_banner_png, sizeof no_banner_png);
wxImage iNoBanner(istream, wxBITMAP_TYPE_PNG);
m_Image = iNoBanner;
} }
} }
GameListItem::~GameListItem() GameListItem::~GameListItem()
{} {
}
bool GameListItem::LoadFromCache()
{
return CChunkFileReader::Load<GameListItem>(CreateCacheFilename(), CACHE_REVISION, *this);
}
void GameListItem::SaveToCache()
{
CChunkFileReader::Save<GameListItem>(CreateCacheFilename(), CACHE_REVISION, *this);
}
void GameListItem::DoState(PointerWrap &p)
{
p.Do(m_Name);
p.Do(m_Company);
p.Do(m_Description);
p.Do(m_UniqueID);
p.Do(m_FileSize);
p.Do(m_VolumeSize);
p.Do(m_Country);
p.Do(m_BlobCompressed);
p.DoBuffer(&m_pImage, m_ImageSize);
}
std::string GameListItem::CreateCacheFilename()
{
std::string Filename;
SplitPath(m_FileName, NULL, &Filename, NULL);
Filename.append(".cache");
std::string fullname("ISOCache\\");
fullname += Filename;
return fullname;
}

View File

@ -20,6 +20,7 @@
#include "Volume.h" #include "Volume.h"
class PointerWrap;
class GameListItem class GameListItem
{ {
public: public:
@ -36,11 +37,13 @@ public:
bool IsCompressed() const {return m_BlobCompressed;} bool IsCompressed() const {return m_BlobCompressed;}
u64 GetFileSize() const {return m_FileSize;} u64 GetFileSize() const {return m_FileSize;}
u64 GetVolumeSize() const {return m_VolumeSize;} u64 GetVolumeSize() const {return m_VolumeSize;}
#if !defined(OSX64) #if !defined(OSX64)
const wxImage& GetImage() const {return m_Image;} const wxImage& GetImage() const {return m_Image;}
#endif #endif
void DoState(PointerWrap &p);
private:
std::string m_FileName; std::string m_FileName;
std::string m_Name; std::string m_Name;
std::string m_Company; std::string m_Company;
@ -51,13 +54,21 @@ public:
u64 m_VolumeSize; u64 m_VolumeSize;
DiscIO::IVolume::ECountry m_Country; DiscIO::IVolume::ECountry m_Country;
bool m_BlobCompressed;
u32 m_ImageSize;
u8* m_pImage;
#if !defined(OSX64) #if !defined(OSX64)
wxImage m_Image; wxImage m_Image;
#endif #endif
bool m_Valid; bool m_Valid;
bool m_BlobCompressed; bool LoadFromCache();
void SaveToCache();
std::string CreateCacheFilename();
}; };