void TestMakeNameFromDirectory(void) { CFileUtil cFileUtil; CChars szName; CChars szDirectory; CChars szFileName; szDirectory.Init("c:"_FS_"Some"_FS_"Directory"_FS_"Or"_FS_"Other"_FS_); szFileName.Init("c:"_FS_"Some"_FS_"Directory"_FS_"Or"_FS_"Other"_FS_"More"_FS_"Dir"_FS_"FileName.txt"); cFileUtil.MakeNameFromDirectory(&szName, &szFileName, &szDirectory); AssertString("More/Dir/FileName.txt", szName.Text()); szName.Kill(); cFileUtil.MakeNameFromDirectory(&szName, &szDirectory, &szDirectory); AssertString("", szName.Text()); szName.Kill(); szDirectory.Kill(); szFileName.Kill(); }
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; }