當前位置: 首頁>>代碼示例>>C++>>正文


C++ DirectoryEntry::getName方法代碼示例

本文整理匯總了C++中DirectoryEntry::getName方法的典型用法代碼示例。如果您正苦於以下問題:C++ DirectoryEntry::getName方法的具體用法?C++ DirectoryEntry::getName怎麽用?C++ DirectoryEntry::getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DirectoryEntry的用法示例。


在下文中一共展示了DirectoryEntry::getName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: writeDirectory

void RsfsFormatter::writeDirectory(const DirectoryEntry& dir, const WORD wDataRegionOffset, std::ostream& fileIndexBuffer, std::ostream& fileRawDataBuffer)
{
	char fileReadBuffer[100];

	const std::vector<DirectoryEntry>& dirs = dir.getDirectories();
	const std::vector<FileEntry>& files = dir.getFiles();
	
	WORD wBuffer = 0;

	if(dir.getName().length() > 0)
	{
		wBuffer = RSFS_ENTRYTYPE_DIRECTORY;
		fileIndexBuffer.write(reinterpret_cast<char*>(&wBuffer), sizeof(WORD));

		fileIndexBuffer.write(dir.getName().c_str(), dir.getName().length());

		for(unsigned int i = RSFS_NAME_SIZE - dir.getName().length(); i > 0; i--)
			fileIndexBuffer.put(0);

		if(dir.getDirectories().size() > 0xFFFF)
			throw FormattingException("The number of sub-directories exceeds the max permittable number of sub-directories.");

		wBuffer = static_cast<WORD>(dir.getDirectories().size() + dir.getFiles().size());
		fileIndexBuffer.write(reinterpret_cast<char*>(&wBuffer), sizeof(WORD));

		fileIndexBuffer.put(0);
		fileIndexBuffer.put(0);
	}

	for(std::vector<FileEntry>::const_iterator it = files.begin(); it != files.end(); it++)
	{
		if(it->getName().length() >= RSFS_NAME_SIZE)
		{
			throw new FormattingException(std::string("Skipped due to file name exceeding max length: ") + it->getName());
			continue;
		}

		wBuffer = RSFS_ENTRYTYPE_FILE;
		fileIndexBuffer.write(reinterpret_cast<char*>(&wBuffer), sizeof(WORD));

		fileIndexBuffer.write(it->getName().c_str(), it->getName().length());

		//Padd the file name with nulls.
		for(unsigned int i = RSFS_NAME_SIZE - it->getName().length(); i > 0; i--)
			fileIndexBuffer.put(0);
		
		if(it->getSize() > 0xFFFF)
			throw FormattingException("Size of file exceeded permitable size.");

		wBuffer = static_cast<WORD>(it->getSize());
		fileIndexBuffer.write(reinterpret_cast<char*>(&wBuffer), sizeof(WORD));

		//Make sure data is aligned in words
		std::streamoff offset = 0;
		for(offset = wDataRegionOffset + fileRawDataBuffer.tellp(); offset % 2; offset++)
			fileRawDataBuffer.put(0);

		if(offset + it->getSize() > 0xFFFF)
			throw FormattingException("Size of medium exceeded permitable size.");

		WORD wFileDataOffset = static_cast<WORD>(offset) / 2; //Offset in terms of words.

		fileIndexBuffer.write(reinterpret_cast<char*>(&wFileDataOffset), sizeof(WORD));

		//Write our file's data to the fileRawBuffer.
		std::ifstream inFile(it->getSourceFile(), std::ifstream::binary | std::ifstream::in);
		
		if(!inFile.good())
			throw FormattingException(std::string("Error reading from source file") + it->getName());

		while(!inFile.eof())
		{
			inFile.read(fileReadBuffer, sizeof(fileReadBuffer));
			fileRawDataBuffer.write(fileReadBuffer, inFile.gcount());
		}
	}

	for(std::vector<DirectoryEntry>::const_iterator it = dirs.begin(); it != dirs.end(); it++)
		writeDirectory(*it, wDataRegionOffset, fileIndexBuffer, fileRawDataBuffer);

}
開發者ID:JeremyWildsmith,項目名稱:DCPUOS,代碼行數:81,代碼來源:RsfsFormatter.cpp


注:本文中的DirectoryEntry::getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。