Пример #1
0
//============================================================================
//		NFileUtilities::GetDirectorySize : Get a directory size.
//----------------------------------------------------------------------------
uint64_t NFileUtilities::GetDirectorySize(const NFile &theDirectory)
{	NFileIterator				fileIterator;
	NFileList					theFiles;
	NFile						theFile;
	uint64_t					theSize;
	NFileListConstIterator		theIter;



	// Validate our parameters
	NN_ASSERT(theDirectory.IsDirectory());



	// Get the state we need
	theFiles = fileIterator.GetFiles(theDirectory);
	theSize  = 0;



	// Get the size
	for (theIter = theFiles.begin(); theIter != theFiles.end(); theIter++)
		{
		theFile = *theIter;

		if (theFile.IsFile())
			theSize += theFile.GetSize();
		}

	return(theSize);
}
Пример #2
0
//============================================================================
//		NFileUtilities::GetFileData : Get a file as data.
//----------------------------------------------------------------------------
NData NFileUtilities::GetFileData(const NFile &theFile)
{	uint64_t		theSize, numRead;
	NFile			mutableFile;
	NData			theData;
	NStatus			theErr;



	// Get the state we need
	mutableFile = theFile;
	theSize     = mutableFile.GetSize();
	NN_ASSERT( ((int64_t) theSize) <= kInt32Max);



	// Resize the buffer
	if (!theData.SetSize((NIndex) theSize))
		return(theData);



	// Open the file
	theErr = mutableFile.Open();
	if (theErr != kNoErr)
		{
		theData.Clear();
		return(theData);
		}



	// Read the data
	theErr = mutableFile.Read(theSize, theData.GetData(), numRead);
	theData.SetSize((NIndex) numRead);

	NN_ASSERT_NOERR(theErr);
	NN_ASSERT(numRead == theSize);
	NN_ASSERT(((int64_t) numRead) <= kInt32Max);



	// Clean up
	mutableFile.Close();

	return(theData);
}