当前位置: 首页>>代码示例>>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;未经允许,请勿转载。