コード例 #1
0
CDirectoryFolder *CWADFile::CreateRoot()
{
	CDirectoryFolder *pRoot = new CDirectoryFolder(this);

	// Loop through each lump in the WAD file.
	for(hlUInt i = 0; i < this->pHeader->uiLumpCount; i++)
	{
		hlChar lpName[64];
		sprintf(lpName, "%s.bmp", this->lpLumps[i].lpName);

		// Add the lump as a bitmap.
		pRoot->AddFile(lpName, i);
	}

	return pRoot;
}
コード例 #2
0
ファイル: SGAFile.cpp プロジェクト: BrianGiannini/HLLib
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;
}
コード例 #3
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;
}
コード例 #4
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;
}
コード例 #5
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;
}
コード例 #6
0
ファイル: VBSPFile.cpp プロジェクト: BrianGiannini/HLLib
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;
}
コード例 #7
0
ファイル: ZIPFile.cpp プロジェクト: NSGod/SourceFinagler
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;
}