Example #1
0
//////////////////////////////////////////////////////////////////////////
//																		//
//																		//
//////////////////////////////////////////////////////////////////////////
void CCFile::Path(CChars* pszPath)
{
	CFileUtil	cFileUtil;

	pszPath->Init(mszFullName);
	cFileUtil.RemoveLastFromPath(pszPath);
}
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;
}
void TestFileUtilMisc(void)
{
	CFileUtil	cFileUtil;
	BOOL		bResult;
	CChars		szPath;

	szPath.Init("TestFileUtil");
	bResult = cFileUtil.MakeDir(szPath.Text());
	AssertTrue(bResult);

	cFileUtil.AppendToPath(&szPath, "FileOfDoom.Indiana");
	bResult = cFileUtil.Touch(szPath.Text());
	AssertTrue(bResult);

	bResult = cFileUtil.Exists(szPath.Text());
	AssertTrue(bResult);

	cFileUtil.RemoveLastFromPath(&szPath);
	cFileUtil.AppendToPath(&szPath, "AnotherDir");
	bResult = cFileUtil.MakeDir(szPath.Text());
	AssertTrue(bResult);

	cFileUtil.RemoveLastFromPath(&szPath);
	cFileUtil.AppendToPath(&szPath, "Master.Chief");
	bResult = cFileUtil.Touch(szPath.Text());
	AssertTrue(bResult);

	bResult = cFileUtil.Delete(szPath.Text());
	AssertTrue(bResult);

	bResult = cFileUtil.Exists(szPath.Text());
	AssertFalse(bResult);

	cFileUtil.RemoveLastFromPath(&szPath);
	cFileUtil.RemoveDir(szPath.Text());
}
Example #4
0
void TestFileUtilRemoveLastFromPath(void)
{
	CFileUtil	cFileUtil;
	CChars		szFileName;

	szFileName.Init("home\\directory");
	cFileUtil.RemoveLastFromPath(&szFileName);
	AssertString("home", szFileName.Text());
	szFileName.Kill();

	szFileName.Init("\\directory");
	cFileUtil.RemoveLastFromPath(&szFileName);
	AssertString("\\", szFileName.Text());
	szFileName.Kill();

	szFileName.Init("\\home\\directory");
	cFileUtil.RemoveLastFromPath(&szFileName);
	AssertString("\\home", szFileName.Text());
	szFileName.Kill();

	szFileName.Init("C:\\directory");
	cFileUtil.RemoveLastFromPath(&szFileName);
	AssertString("C:\\", szFileName.Text());
	szFileName.Kill();

	szFileName.Init("C:\\home\\directory");
	cFileUtil.RemoveLastFromPath(&szFileName);
	AssertString("C:\\home", szFileName.Text());
	szFileName.Kill();

	szFileName.Init("directory");
	cFileUtil.RemoveLastFromPath(&szFileName);
	AssertString("", szFileName.Text());
	szFileName.Kill();

	szFileName.Init("");
	cFileUtil.RemoveLastFromPath(&szFileName);
	AssertString("", szFileName.Text());
	szFileName.Kill();
}