예제 #1
0
const CDirectoryItem *CDirectoryFolder::GetItem(const hlChar *lpName, HLFindType eFind) const
{
    for(hlUInt i = 0; i < this->pDirectoryItemVector->size(); i++)
    {
        CDirectoryItem *pItem = (*this->pDirectoryItemVector)[i];
        if((pItem->GetType() == HL_ITEM_FILE && (eFind & HL_FIND_FILES)) || (pItem->GetType() == HL_ITEM_FOLDER && (eFind & HL_FIND_FOLDERS)))
        {
            if(this->Compare(lpName, pItem->GetName(), eFind) == 0)
            {
                return pItem;
            }
        }
    }

    return 0;
}
예제 #2
0
파일: PAKFile.cpp 프로젝트: panzi/HLLib
CDirectoryFolder *CPAKFile::CreateRoot()
{
	CDirectoryFolder *pRoot = new CDirectoryFolder(this);

	hlUInt uiItemCount = this->pHeader->uiDirectoryLength / sizeof(PAKDirectoryItem);

	// Loop through each file in the PAK file.
	for(hlUInt i = 0; i < uiItemCount; i++)
	{
		hlChar lpFileName[56];
		strlcpy(lpFileName, this->lpDirectoryItems[i].lpItemName, sizeof(lpFileName));

		// Check if we have just a file, or if the file has directories we need to create.
		if(strchr(lpFileName, '/') == 0 && strchr(lpFileName, '\\') == 0)
		{
			pRoot->AddFile(lpFileName, i);
		}
		else
		{
			// Tokenize the file path and create the directories.
			CDirectoryFolder *pInsertFolder = pRoot;

			hlChar lpTemp[56] = "";
			hlChar *lpToken = strtok(lpFileName, "/\\");
			while(lpToken != 0)
			{
				strlcpy(lpTemp, lpToken, sizeof(lpTemp));

				lpToken = strtok(0, "/\\");

				if(lpToken != 0)
				{
					// Check if the directory exists.
					CDirectoryItem *pItem = pInsertFolder->GetItem(lpTemp);
					if(pItem == 0 || pItem->GetType() == HL_ITEM_FILE)
					{
						// It doesn't, create it.
						pInsertFolder = pInsertFolder->AddFolder(lpTemp);
					}
					else
					{
						// It does, use it.
						pInsertFolder = static_cast<CDirectoryFolder *>(pItem);
					}
				}
			}

			// The file name is the last token, add it.
			pInsertFolder->AddFile(lpTemp, i);
		}
	}

	return pRoot;
}
예제 #3
0
hlVoid CDirectoryFolder::Sort(HLSortField eField, HLSortOrder eOrder, hlBool bRecurse)
{
    std::sort(this->pDirectoryItemVector->begin(), this->pDirectoryItemVector->end(), CCompareDirectoryItems(eField, eOrder));

    if(bRecurse)
    {
        for(hlUInt i = 0; i < this->pDirectoryItemVector->size(); i++)
        {
            CDirectoryItem *pItem = (*this->pDirectoryItemVector)[i];
            if(pItem->GetType() == HL_ITEM_FOLDER)
            {
                static_cast<CDirectoryFolder *>(pItem)->Sort(eField, eOrder, bRecurse);
            }
        }
    }
}
예제 #4
0
hlVoid CSGAFile::CSGADirectory<TSGADirectoryHeader, TSGASection, TSGAFolder, TSGAFile, TSGAFileHeader>::CreateFolder(CDirectoryFolder *pParent, hlUInt uiFolderIndex)
{
	const hlChar* lpName = this->lpStringTable + this->lpFolders[uiFolderIndex].uiNameOffset;
	if(*lpName != '\0')
	{
		// Strip parent folder names.
		const hlChar* lpTemp = strrchr(lpName, '/');
		if(lpTemp != 0)
		{
			lpName = lpTemp + 1;
		}
		lpTemp = strrchr(lpName, '\\');
		if(lpTemp != 0)
		{
			lpName = lpTemp + 1;
		}
		// Check if folder exists.
		CDirectoryItem *pItem = pParent->GetItem(lpName);
		if(pItem == 0 || pItem->GetType() == HL_ITEM_FILE)
		{
			// It doesn't, create it.
			pParent = pParent->AddFolder(lpName);
		}
		else
		{
			// It does, use it.
			pParent = static_cast<CDirectoryFolder *>(pItem);
		}
	}
	for(hlUInt i = this->lpFolders[uiFolderIndex].uiFolderStartIndex; i < this->lpFolders[uiFolderIndex].uiFolderEndIndex; i++)
	{
		CreateFolder(pParent, i);
	}
	for(hlUInt i = this->lpFolders[uiFolderIndex].uiFileStartIndex; i < this->lpFolders[uiFolderIndex].uiFileEndIndex; i++)
	{
		const hlChar* lpName = this->lpStringTable + this->lpFiles[i].uiNameOffset;
		pParent->AddFile(lpName, i);
	}
}
예제 #5
0
CDirectoryFolder *CSGAFile::CSGADirectory<TSGADirectoryHeader, TSGASection, TSGAFolder, TSGAFile, TSGAFileHeader>::CreateRoot()
{
	CDirectoryFolder *pRoot = new CDirectoryFolder(&File);

	for(hlUInt i = 0; i < this->pDirectoryHeader->uiSectionCount; i++)
	{
		CDirectoryFolder* pSection;
		// Check if folder exists.
		CDirectoryItem *pItem = pRoot->GetItem(this->lpSections[i].lpAlias);
		if(pItem == 0 || pItem->GetType() == HL_ITEM_FILE)
		{
			// It doesn't, create it.
			pSection = pRoot->AddFolder(this->lpSections[i].lpAlias);
		}
		else
		{
			// It does, use it.
			pSection = static_cast<CDirectoryFolder *>(pItem);
		}
		this->CreateFolder(pSection, this->lpSections[i].uiFolderRootIndex);
	}

	return pRoot;
}
예제 #6
0
파일: VPKFile.cpp 프로젝트: Noclip21/Test
CDirectoryFolder *CVPKFile::CreateRoot()
{
	CDirectoryFolder *pRoot = new CDirectoryFolder(this);

	const hlChar *lpLastPath = 0;
	CDirectoryFolder *pLastInsertFolder = 0;

	// Loop through each file in the VPK file.
	for(CDirectoryItemList::const_iterator i = this->pDirectoryItems->begin(); i != this->pDirectoryItems->end(); ++i)
	{
		const VPKDirectoryItem *pDirectoryItem = *i;

		CDirectoryFolder *pInsertFolder;
		if(pDirectoryItem->lpPath == lpLastPath)
		{
			pInsertFolder = pLastInsertFolder;
		}
		else
		{
			pInsertFolder = pRoot;

			if(*pDirectoryItem->lpPath != '\0' && strcmp(pDirectoryItem->lpPath, " ") != 0)
			{
				// Tokenize the file path and create the directories.
				hlChar *lpPath = new hlChar[strlen(pDirectoryItem->lpPath) + 1];
				strcpy(lpPath, pDirectoryItem->lpPath);
				hlChar *lpToken = strtok(lpPath, "/\\");
				while(lpToken != 0)
				{
					// Check if the directory exists.
					CDirectoryItem *pItem = pInsertFolder->GetItem(lpToken);
					if(pItem == 0 || pItem->GetType() == HL_ITEM_FILE)
					{
						// It doesn't, create it.
						pInsertFolder = pInsertFolder->AddFolder(lpToken);
					}
					else
					{
						// It does, use it.
						pInsertFolder = static_cast<CDirectoryFolder *>(pItem);
					}
					lpToken = strtok(0, "/\\");
				}
				delete []lpPath;
			}

			lpLastPath = pDirectoryItem->lpPath;
			pLastInsertFolder = pInsertFolder;
		}

		hlChar *lpFileName = new hlChar[strlen(pDirectoryItem->lpName) + 1 + strlen(pDirectoryItem->lpExtention) + 1];
		strcpy(lpFileName, pDirectoryItem->lpName);
		strcat(lpFileName, ".");
		strcat(lpFileName, pDirectoryItem->lpExtention);

		pInsertFolder->AddFile(lpFileName, -1, const_cast<VPKDirectoryItem *>(pDirectoryItem));

		delete []lpFileName;
	}

	return pRoot;
}
예제 #7
0
CDirectoryFolder *CXZPFile::CreateRoot()
{
	CDirectoryFolder *pRoot = new CDirectoryFolder(this);

	if(this->pHeader->uiDirectoryItemCount != 0)
	{
		// Loop through each file in the XZP file.
		for(hlUInt i = 0; i < this->pHeader->uiDirectoryEntryCount; i++)
		{
			// Find it's info (file name).
			for(hlUInt j = 0; j < this->pHeader->uiDirectoryItemCount; j++)
			{
				if(this->lpDirectoryEntries[i].uiFileNameCRC == this->lpDirectoryItems[j].uiFileNameCRC)
				{
					hlChar lpFileName[256];
					strncpy(lpFileName, (hlChar *)this->lpDirectoryItems + this->lpDirectoryItems[j].uiNameOffset - this->pHeader->uiDirectoryItemOffset, sizeof(lpFileName));
					lpFileName[sizeof(lpFileName) - 1] = '\0';

					// Check if we have just a file, or if the file has directories we need to create.
					if(strchr(lpFileName, '/') == 0 && strchr(lpFileName, '\\') == 0)
					{
						pRoot->AddFile(lpFileName, i);
					}
					else
					{
						// Tokenize the file path and create the directories.
						CDirectoryFolder *pInsertFolder = pRoot;

						hlChar lpTemp[256] = "";
						hlChar *lpToken = strtok(lpFileName, "/\\");
						while(lpToken != 0)
						{
							strcpy(lpTemp, lpToken);

							lpToken = strtok(0, "/\\");

							if(lpToken != 0)
							{
								// Check if the directory exists.
								CDirectoryItem *pItem = pInsertFolder->GetItem(lpTemp);
								if(pItem == 0 || pItem->GetType() == HL_ITEM_FILE)
								{
									// It doesn't, create it.
									pInsertFolder = pInsertFolder->AddFolder(lpTemp);
								}
								else
								{
									// It does, use it.
									pInsertFolder = static_cast<CDirectoryFolder *>(pItem);
								}
							}
						}

						// The file name is the last token, add it.
						pInsertFolder->AddFile(lpTemp, i);
					}
					break;
				}
			}
		}
	}
	else
	{
		// No file name information, just file name CRCs.
		for(hlUInt i = 0; i < this->pHeader->uiDirectoryEntryCount; i++)
		{
			hlChar lpTemp[16] = "";
			const char *lpLookup[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
			for(hlByte *lpCRC = (hlByte *)&this->lpDirectoryEntries[i].uiFileNameCRC; lpCRC < (hlByte *)&this->lpDirectoryEntries[i].uiFileNameCRC + sizeof(hlUInt); lpCRC++)
			{
				strcat(lpTemp, lpLookup[(hlByte)(*lpCRC >> 4)]);
				strcat(lpTemp, lpLookup[(hlByte)(*lpCRC & 0x0F)]);

			}

			pRoot->AddFile(lpTemp, i);
		}
	}

	return pRoot;
}
예제 #8
0
CDirectoryFolder *CVBSPFile::CreateRoot()
{
	CDirectoryFolder *pRoot = new CDirectoryFolder(this);

	hlChar lpFileName[256];

	if(this->pHeader->lpLumps[HL_VBSP_LUMP_ENTITIES].uiLength != 0)
	{
		this->GetFileName(lpFileName, sizeof(lpFileName) - 4);
		if(*lpFileName == '\0')
		{
			pRoot->AddFile("entities.ent", HL_VBSP_LUMP_ENTITIES);
		}
		else
		{
			strcat(lpFileName, ".ent");
			pRoot->AddFile(lpFileName, HL_VBSP_LUMP_ENTITIES);
		}
	}

	if(this->pHeader->lpLumps[HL_VBSP_LUMP_PAKFILE].uiLength != 0)
	{
		this->GetFileName(lpFileName, sizeof(lpFileName) - 4);
		if(*lpFileName == '\0')
		{
			pRoot->AddFile("pakfile.zip", HL_VBSP_LUMP_PAKFILE);
		}
		else
		{
			strcat(lpFileName, ".zip");
			pRoot->AddFile(lpFileName, HL_VBSP_LUMP_PAKFILE);
		}
	}

	CDirectoryFolder *pLumpFolder = pRoot->AddFolder("lumps");
	for(hlUInt i = 0; i < HL_VBSP_LUMP_COUNT; i++)
	{
		if(this->pHeader->lpLumps[i].uiLength > 0)
		{
			hlChar lpTemp[256];
			this->GetFileName(lpTemp, sizeof(lpTemp) - 10);
			if(*lpTemp == '\0')
			{
				sprintf(lpFileName, "lump_l_%d.lmp", i);
			}
			else
			{
				sprintf(lpFileName, "%s_l_%d.lmp", lpTemp, i);
			}
			pLumpFolder->AddFile(lpFileName, HL_VBSP_LUMP_COUNT + i);
		}
	}

	if(this->pEndOfCentralDirectoryRecord != 0)
	{
		hlUInt uiTest, uiOffset = 0;
		while(uiOffset < this->pEndOfCentralDirectoryRecord->uiCentralDirectorySize - sizeof(uiTest))
		{
			uiTest = *(hlUInt *)((hlByte *)this->pFileHeaderView->GetView() + uiOffset);

			switch(uiTest)
			{
				case HL_VBSP_ZIP_FILE_HEADER_SIGNATURE:
				{
					ZIPFileHeader *pFileHeader = static_cast<ZIPFileHeader *>((hlVoid *)((hlByte *)this->pFileHeaderView->GetView() + uiOffset));

					hlChar *lpFileName = new hlChar[pFileHeader->uiFileNameLength + 1];
					memcpy(lpFileName, (hlByte *)pFileHeader + sizeof(ZIPFileHeader), pFileHeader->uiFileNameLength);
					lpFileName[pFileHeader->uiFileNameLength] = '\0';

					// Check if we have just a file, or if the file has directories we need to create.
					if(strchr(lpFileName, '/') == 0 && strchr(lpFileName, '\\') == 0)
					{
						pRoot->AddFile(lpFileName, HL_ID_INVALID, pFileHeader);
					}
					else
					{
						// Tokenize the file path and create the directories.
						CDirectoryFolder *pInsertFolder = pRoot;

						hlChar lpTemp[256] = "";
						hlChar *lpToken = strtok(lpFileName, "/\\");
						while(lpToken != 0)
						{
							strcpy(lpTemp, lpToken);

							lpToken = strtok(0, "/\\");

							if(lpToken != 0)
							{
								// Check if the directory exists.
								CDirectoryItem *pItem = pInsertFolder->GetItem(lpTemp);
								if(pItem == 0 || pItem->GetType() == HL_ITEM_FILE)
								{
									// It doesn't, create it.
									pInsertFolder = pInsertFolder->AddFolder(lpTemp);
								}
								else
								{
									// It does, use it.
									pInsertFolder = static_cast<CDirectoryFolder *>(pItem);
								}
							}
						}

						// The file name is the last token, add it.
						pInsertFolder->AddFile(lpTemp, HL_ID_INVALID, pFileHeader);
					}

					delete []lpFileName;

					uiOffset += sizeof(ZIPFileHeader) + pFileHeader->uiFileNameLength + pFileHeader->uiExtraFieldLength + pFileHeader->uiFileCommentLength;
					break;
				}
				default:
				{
					uiOffset = this->pEndOfCentralDirectoryRecord->uiCentralDirectorySize;
					break;
				}
			}
		}
	}

	return pRoot;
}
예제 #9
0
CDirectoryFolder *CZIPFile::CreateRoot()
{
	CDirectoryFolder *pRoot = new CDirectoryFolder(this);

	hlUInt uiTest, uiOffset = 0;
	while(uiOffset < this->pEndOfCentralDirectoryRecord->uiCentralDirectorySize - sizeof(uiTest))
	{
		uiTest = *(hlUInt *)((hlByte *)this->pFileHeaderView->GetView() + uiOffset);

		switch(uiTest)
		{
			case HL_ZIP_FILE_HEADER_SIGNATURE:
			{
				ZIPFileHeader *pFileHeader = static_cast<ZIPFileHeader *>((hlVoid *)((hlByte *)this->pFileHeaderView->GetView() + uiOffset));

				hlChar *lpFileName = new hlChar[pFileHeader->uiFileNameLength + 1];
				memcpy(lpFileName, (hlByte *)pFileHeader + sizeof(ZIPFileHeader), pFileHeader->uiFileNameLength);
				lpFileName[pFileHeader->uiFileNameLength] = '\0';

				// Check if we have just a file, or if the file has directories we need to create.
				if(strchr(lpFileName, '/') == 0 && strchr(lpFileName, '\\') == 0)
				{
					pRoot->AddFile(lpFileName, HL_ID_INVALID, pFileHeader);
				}
				else
				{
					// Tokenize the file path and create the directories.
					CDirectoryFolder *pInsertFolder = pRoot;

					hlChar lpTemp[256] = "";
					hlChar *lpToken = strtok(lpFileName, "/\\");
					while(lpToken != 0)
					{
						strcpy(lpTemp, lpToken);

						lpToken = strtok(0, "/\\");

						if(lpToken != 0)
						{
							// Check if the directory exists.
							CDirectoryItem *pItem = pInsertFolder->GetItem(lpTemp);
							if(pItem == 0 || pItem->GetType() == HL_ITEM_FILE)
							{
								// It doesn't, create it.
								pInsertFolder = pInsertFolder->AddFolder(lpTemp);
							}
							else
							{
								// It does, use it.
								pInsertFolder = static_cast<CDirectoryFolder *>(pItem);
							}
						}
					}

					// The file name is the last token, add it.
					pInsertFolder->AddFile(lpTemp, HL_ID_INVALID, pFileHeader);
				}

				delete []lpFileName;

				uiOffset += sizeof(ZIPFileHeader) + pFileHeader->uiFileNameLength + pFileHeader->uiExtraFieldLength + pFileHeader->uiFileCommentLength;
				break;
			}
			default:
			{
				uiOffset = this->pEndOfCentralDirectoryRecord->uiCentralDirectorySize;
				break;
			}
		}
	}

	return pRoot;
}