re3-wiiu/src/core/Directory.cpp

75 lines
1.4 KiB
C++
Raw Normal View History

2019-06-03 05:26:49 +02:00
#include "common.h"
2020-04-17 15:31:11 +02:00
#include "General.h"
2019-06-03 05:26:49 +02:00
#include "FileMgr.h"
#include "Directory.h"
CDirectory::CDirectory(int32 maxEntries)
: numEntries(0), maxEntries(maxEntries)
{
entries = new DirectoryInfo[maxEntries];
}
CDirectory::~CDirectory(void)
{
delete[] entries;
}
void
CDirectory::ReadDirFile(const char *filename)
{
int fd;
DirectoryInfo dirinfo;
fd = CFileMgr::OpenFile(filename, "rb");
while(CFileMgr::Read(fd, (char*)&dirinfo, sizeof(dirinfo)))
AddItem(dirinfo);
CFileMgr::CloseFile(fd);
2019-06-03 05:26:49 +02:00
}
bool
CDirectory::WriteDirFile(const char *filename)
{
2020-07-22 13:56:28 +02:00
int fd;
2020-12-27 04:03:38 +01:00
size_t n;
2019-06-03 05:26:49 +02:00
fd = CFileMgr::OpenFileForWriting(filename);
n = CFileMgr::Write(fd, (char*)entries, numEntries*sizeof(DirectoryInfo));
CFileMgr::CloseFile(fd);
return n == numEntries*sizeof(DirectoryInfo);
}
void
CDirectory::AddItem(const DirectoryInfo &dirinfo)
{
assert(numEntries < maxEntries);
2020-04-21 13:56:33 +02:00
#ifdef FIX_BUGS
// don't add if already exists
uint32 offset, size;
if(FindItem(dirinfo.name, offset, size))
return;
#endif
2019-06-03 05:26:49 +02:00
entries[numEntries++] = dirinfo;
}
2020-04-21 13:56:33 +02:00
void
CDirectory::AddItem(const DirectoryInfo &dirinfo, int32 imgId)
{
DirectoryInfo di = dirinfo;
di.offset |= imgId<<24;
AddItem(di);
}
2019-06-03 05:26:49 +02:00
bool
CDirectory::FindItem(const char *name, uint32 &offset, uint32 &size)
{
int i;
for(i = 0; i < numEntries; i++)
if(!CGeneral::faststricmp(entries[i].name, name)){
2019-06-03 05:26:49 +02:00
offset = entries[i].offset;
size = entries[i].size;
return true;
}
return false;
}