Just getting crap out of my file

Started by
4 comments, last by Hippokrates 21 years, 6 months ago
I am currently writing an archive class to store my files. To add a file to an archive I am doing this:

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?
Im Anfang war die Tat...Faust
Advertisement
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...
Im Anfang war die Tat...Faust
Hope this helps

http://c.ittoolbox.com/code/d.asp?d=1647&a=s


Robert Ferraro
________________
[Draconia Studios]
Yes, it does indeed :D
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 ?
Im Anfang war die Tat...Faust
YEEEHAAAW!
It is actually working now!
I can`t believe it ;-)
Im Anfang war die Tat...Faust
Also, if you''re working in Win32, you can just call ::GetFileSize(LPCTSTR szFileName);, which returns a DWORD (unsigned long)
daerid@gmail.com

This topic is closed to new replies.

Advertisement