void CSharedDirsTreeCtrl::OnLvnBegindrag(NMHDR* pNMHDR, LRESULT* pResult) { LPNMTREEVIEW lpnmtv = (LPNMTREEVIEW)pNMHDR; *pResult = 0; CDirectoryItem* pToDrag = (CDirectoryItem*)lpnmtv->itemNew.lParam; if (pToDrag == NULL || pToDrag->m_eItemType != SDI_UNSHAREDDIRECTORY || FileSystemTreeIsShared(pToDrag->m_strFullPath)) return; ASSERT( m_pDraggingItem == NULL ); delete m_pDraggingItem; m_pDraggingItem = pToDrag->CloneContent(); // to be safe we store a copy, as items can be deleted when collapsing the tree etc CImageList* piml = NULL; POINT ptOffset; RECT rcItem; if ((piml = CreateDragImage(lpnmtv->itemNew.hItem)) == NULL) return; /* get the bounding rectangle of the item being dragged (rel to top-left of control) */ if (GetItemRect(lpnmtv->itemNew.hItem, &rcItem, TRUE)) { CPoint ptDragBegin; int nX, nY; /* get offset into image that the mouse is at */ /* item rect doesn't include the image */ ptDragBegin = lpnmtv->ptDrag; ImageList_GetIconSize(piml->GetSafeHandle(), &nX, &nY); ptOffset.x = (ptDragBegin.x - rcItem.left) + (nX - (rcItem.right - rcItem.left)); ptOffset.y = (ptDragBegin.y - rcItem.top) + (nY - (rcItem.bottom - rcItem.top)); /* convert the item rect to screen co-ords, for use later */ MapWindowPoints(NULL, &rcItem); } else { GetWindowRect(&rcItem); ptOffset.x = ptOffset.y = 8; } if (piml->BeginDrag(0, ptOffset)) { CPoint ptDragEnter = lpnmtv->ptDrag; ClientToScreen(&ptDragEnter); piml->DragEnter(NULL, ptDragEnter); } delete piml; /* set the focus here, so we get a WM_CANCELMODE if needed */ SetFocus(); /* redraw item being dragged, otherwise it remains (looking) selected */ InvalidateRect(&rcItem, TRUE); UpdateWindow(); /* Hide the mouse cursor, and direct mouse input to this window */ SetCapture(); }
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; }
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); } } } }
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; }
// search tree for a given filter HTREEITEM CDirectoryItem::FindItem(CDirectoryItem* pContentToFind) const { if (pContentToFind == NULL){ ASSERT( false ); return NULL; } if (pContentToFind->m_eItemType == m_eItemType && pContentToFind->m_strFullPath == m_strFullPath && pContentToFind->m_nCatFilter == m_nCatFilter) return m_htItem; POSITION pos = liSubDirectories.GetHeadPosition(); while (pos != NULL){ CDirectoryItem* pCurrent = liSubDirectories.GetNext(pos); HTREEITEM htResult; if ( (htResult = pCurrent->FindItem(pContentToFind)) != NULL) return htResult; } return NULL; }
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); } }
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; }
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; }
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; }
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; }
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; }