BOOL CPackFiles::RecurseUnpack(CFileNodePackFileNode* pcNode, char* szDestination)
{
	CChars					szFileName;
	CFileNodePackFileNode*	pcChild;
	int						i;
	CPackFileNode*			pcFile;
	BOOL					bResult;
	CPackFile*				pcPackFile;
	CFileCopier				cCopier;
	CDiskFile				cDiskFile;
	CFileUtil				cFileUtil;

	if (pcNode->IsDirectory())
	{
		bResult = TRUE;
		for (i = 0; i < pcNode->Directory()->maNodeFiles.NumElements(); i++)
		{
			pcChild = (CFileNodePackFileNode*)pcNode->Directory()->maNodeFiles.Get(i);
			bResult &= RecurseUnpack(pcChild, szDestination);
		}
		return bResult;
	}
	else if (pcNode->IsFile())
	{
		szFileName.Init(szDestination);
		szFileName.Append('/');
		pcNode->GetFullName(&szFileName);
		szFileName.Replace('/', FILE_SEPARATOR[0]);

		pcFile = pcNode->File();
		pcPackFile = PackFile(this, pcFile);

		if (!pcPackFile)
		{
			szFileName.Kill();
			return FALSE;
		}

		cDiskFile.Init(szFileName.Text());

		cFileUtil.RemoveLastFromPath(&szFileName);
		cFileUtil.MakeDir(szFileName.Text());
		bResult = cCopier.Copy(pcPackFile, &cDiskFile);

		cDiskFile.Kill();

		szFileName.Kill();
		return bResult;
	}
	return FALSE;
}
BOOL CPackFiles::AddDirectory(char* szDirectory, char* szPackDirectory)
{
	CFileUtil		cFileUtil;
	CArrayChars	aszFileNames;
	int				i;
	CChars*			pszFileName;
	CDiskFile		cDiskFile;
	CChars			szName;
	CChars			szNameDirectory;
	BOOL			bResult;
	BOOL			bAnyFiles;

	aszFileNames.Init();
	bAnyFiles = cFileUtil.FindAllFiles(szDirectory, &aszFileNames, TRUE, FALSE);

	if (!bAnyFiles)
	{
		aszFileNames.Kill();
		return FALSE;
	}

	szNameDirectory.Init(szDirectory);
	for (i = 0; i < aszFileNames.NumElements(); i++)
	{
		pszFileName = aszFileNames.Get(i);
		cDiskFile.Init(pszFileName->Text());
		cFileUtil.MakeNameFromDirectory(&szName, pszFileName, &szNameDirectory);
		if (szPackDirectory)
		{
			szName.Insert(0, '/');
			szName.Insert(0, szPackDirectory);
		}

		bResult = AddFile(&cDiskFile, szName.Text());
		szName.Kill();
		cDiskFile.Kill();

		if (!bResult)
		{
			aszFileNames.Kill();
			return FALSE;
		}
	}

	aszFileNames.Kill();
	return TRUE;
}
Example #3
0
CFileIndex CIndexTreeBlockFile::LoadRootFileIndex(char* szRootFileName)
{
	CFileBasic	cFileBasic;
	CDiskFile	cDiskFile;
	CFileUtil	cFileUtil;
	CFileIndex	cIndex;
	filePos		iSize;

	iSize = cFileUtil.Size(szRootFileName);
	if (iSize != -1)
	{
		if (iSize == sizeof(CFileIndex))
		{
			cDiskFile.Init(szRootFileName);
			cFileBasic.Init(&cDiskFile);

			cFileBasic.Open(EFM_Read);
			cFileBasic.Read(&cIndex, 0, sizeof(CFileIndex));
			cFileBasic.Close();

			cFileBasic.Kill();
			cDiskFile.Kill();

			return cIndex;
		}
		else
		{
			gcLogger.Error2(__METHOD__, "Index Root file size [", LongLongToString(iSize), "] is incorrect.  Should be SizeOf(CFileIndex).", NULL);
			cIndex.Init();
			return cIndex;
		}
	}
	else
	{
		cIndex.Init();
		return cIndex;
	}
}