2019-06-03 05:26:49 +02:00
|
|
|
#include "common.h"
|
2020-04-17 15:31:11 +02:00
|
|
|
|
2019-10-30 00:12:58 +01: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);
|
2019-06-13 01:12:37 +02:00
|
|
|
CFileMgr::CloseFile(fd);
|
2019-06-03 05:26:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDirectory::WriteDirFile(const char *filename)
|
|
|
|
{
|
|
|
|
int fd, n;
|
|
|
|
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);
|
|
|
|
entries[numEntries++] = dirinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CDirectory::FindItem(const char *name, uint32 &offset, uint32 &size)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = 0; i < numEntries; i++)
|
2019-10-30 00:12:58 +01:00
|
|
|
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;
|
|
|
|
}
|