bool CArchive::AddFile(LPSTR strFileName) {
LPBYTE pbyFileContent = NULL;
DWORD dwSize = 0;
CDataPackage * pData = NULL;
std::ifstream FileIn(strFileName, std::ios::binary);
char c;
while(FileIn.good()) {
FileIn.read(&c, sizeof(char));
dwSize++;
}
FileIn.close();
pbyFileContent = new BYTE[dwSize];
FileIn.open(strFileName, std::ios::binary);
FileIn.read((char *)pbyFileContent, dwSize);
FileIn.close();
pData = new CDataPackage(m_pDebug);
pData->Create(dwSize);
memcpy(pData->GetData(), pbyFileContent, dwSize);
m_Files.push_back(new ARCHIVEFILE);
m_Files.back()->strFileName = strdup(strFileName);
m_Files.back()->pData = pData;
m_Header.wNumberFiles++;
m_FileEntries.resize(m_FileEntries.size() + 1);
strcpy(m_FileEntries.back().strFileName, strFileName);
m_FileEntries.back().dwBegin = 0;
m_FileEntries.back().dwEnd = 0;
m_FileEntries.back().dwUncompressedSize = dwSize;
SafeDeleteV(pbyFileContent);
return true;
}
For I do not know how to determine the file size with std::ifstream I have to do it manually.
But after reading the pbyFileContent buffer it still contains only rubbish.
I am testing this by reading in a text file so I should be able to understand what is read in but I am not because the buffer is full of crap...
Any ideas?
Just getting crap out of my file
I am currently writing an archive class to store my files.
To add a file to an archive I am doing this:
Does at least someone know how to determine the file size quickly?
If I have a 4MB file it takes 45 seconds to determine the size this way...
If I have a 4MB file it takes 45 seconds to determine the size this way...
Yes, it does indeed :D
I hope this:
sets the file pointer to the beginning of the file again, allowing me to read from the file ?
I hope this:
FileIn.seekg(0, std::ios::beg);
sets the file pointer to the beginning of the file again, allowing me to read from the file ?
Also, if you''re working in Win32, you can just call ::GetFileSize(LPCTSTR szFileName);, which returns a DWORD (unsigned long)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement