Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Hippokrates

Just getting crap out of my file

This topic is 5743 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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 ?

Share this post


Link to post
Share on other sites
Also, if you''re working in Win32, you can just call ::GetFileSize(LPCTSTR szFileName);, which returns a DWORD (unsigned long)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!