void CTreeFileCtrl::DisplayDrives(HTREEITEM hParent, BOOL bUseSetRedraw) { CWaitCursor c; //Speed up the job by turning off redraw if (bUseSetRedraw) SetRedraw(FALSE); //Remove any items currently in the tree DeleteAllItems(); //Enumerate the drive letters and add them to the tree control DWORD dwDrives = GetLogicalDrives(); DWORD dwMask = 1; for (int i=0; i<32; i++) { if (dwDrives & dwMask) { CString sDrive; sDrive.Format(_T("%c:\\"), i + _T('A')); InsertFileItem(sDrive, sDrive, hParent); } dwMask <<= 1; } if (bUseSetRedraw) SetRedraw(TRUE); }
void CfsclientwDlg::dir(const char* folder) { vector<file_info> vf; if (m_dwM->dir(vf, folder) < 0) { return; } CEdit * pe = (CEdit *)GetDlgItem(IDC_EDIT_FILE); pe->SetWindowText(folder); //enableButton("download", 0); CListCtrl * pl = (CListCtrl *)GetDlgItem(IDC_FLIST); pl->DeleteAllItems(); char buf[256]; int64 total_size = 0; for (size_t i = 0; i < vf.size(); i++) { InsertFileItem(pl, (int)i, vf[i], buf); total_size += vf[i].filesize; } char c; float f = size2float(total_size, c); sprintf(buf, " Files: %d, size: %.2f %c", vf.size(), f, c); pe = (CEdit*)GetDlgItem(IDC_EDIT_STATUS); pe->SetWindowText(buf); }
void CFileAndFolder::OnViewCachedDrives() { CWaitCursor c; if (m_CachedDrives.GetCount() == 0) { DisplayDrives(TVI_ROOT, FALSE); return; } POSITION pos = m_CachedDrives.GetHeadPosition(); for (pos = m_CachedDrives.GetHeadPosition(); pos != NULL; ) { CString string = m_CachedDrives.GetAt(pos); CString drive,desc; drive = string.Left(3); desc = string.Mid(4); InsertFileItem(desc,drive,TVI_ROOT); m_CachedDrives.GetNext(pos); } }
void CFileAndFolder::DisplayDrives(HTREEITEM hParent, BOOL bUseSetRedraw) { CWaitCursor c; //Remove any items currently in the tree m_Tree.DeleteAllItems(); //Enumerate the drive letters and add them to the tree control DWORD dwDrives = GetLogicalDrives(); DWORD dwMask = 1; m_CachedDrives.RemoveAll(); for (int i=0; i<32; i++) { if (dwDrives & dwMask) { CString sDrive,desc; sDrive.Format(_T("%c:\\"), i + _T('A')); char volname[100]; char fsname[100]; DWORD sn,maxcl,flags; memset(volname,0,100); BOOL x = GetVolumeInformation( sDrive,volname,99,&sn,&maxcl,&flags,fsname,99); if (volname) { desc = CString("(") + sDrive + ") " + volname; } else desc = sDrive; InsertFileItem(desc, sDrive, hParent); m_CachedDrives.AddTail(sDrive + "," + desc); } dwMask <<= 1; } WriteCachedDrives(); }
void FolderTree::DisplayDrives(HTREEITEM hParent, bool bUseSetRedraw) { //CWaitCursor c; //Speed up the job by turning off redraw if (bUseSetRedraw) SetRedraw(false); //Enumerate the drive letters and add them to the tree control DWORD dwDrives = GetLogicalDrives(); DWORD dwMask = 1; for (int i=0; i<32; i++) { if (dwDrives & dwMask) { tstring sDrive; sDrive = (wchar_t)('A' + i); sDrive += _T(":\\"); //check if this drive is one of the types to hide if (CanDisplayDrive(sDrive)) { FolderTreeItemInfo* pItem = new FolderTreeItemInfo; pItem->m_sFQPath = sDrive; pItem->m_sRelativePath = sDrive; //Insert the item into the view InsertFileItem(hParent, pItem, m_bShowSharedUsingDifferentIcon && IsShared(sDrive), GetIconIndex(sDrive), GetSelIconIndex(sDrive), true); } } dwMask <<= 1; } if (bUseSetRedraw) SetRedraw(true); }
void FolderTree::DisplayPath(const tstring &sPath, HTREEITEM hParent, bool bUseSetRedraw /* = true */) { //CWaitCursor c; //Speed up the job by turning off redraw if (bUseSetRedraw) SetRedraw(false); //Remove all the items currently under hParent HTREEITEM hChild = GetChildItem(hParent); while (hChild) { DeleteItem(hChild); hChild = GetChildItem(hParent); } //Should we display the root folder if (m_bShowRootedFolder && (hParent == TVI_ROOT)) { FolderTreeItemInfo* pItem = new FolderTreeItemInfo; pItem->m_sFQPath = m_sRootFolder; pItem->m_sRelativePath = m_sRootFolder; m_hRootedFolder = InsertFileItem(TVI_ROOT, pItem, false, GetIconIndex(m_sRootFolder), GetSelIconIndex(m_sRootFolder), true); Expand(m_hRootedFolder, TVE_EXPAND); return; } //find all the directories underneath sPath int nDirectories = 0; tstring sFile; if (sPath[sPath.size()-1] != _T('\\')) sFile = sPath + _T("\\"); else sFile = sPath; WIN32_FIND_DATA fData; HANDLE hFind; hFind = FindFirstFile((sFile + _T("*")).c_str(), &fData); if(hFind != INVALID_HANDLE_VALUE) { do { tstring filename = fData.cFileName; if((fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (filename != _T(".")) && (filename != _T(".."))) { ++nDirectories; tstring path = sFile + filename; TCHAR szPath[_MAX_PATH]; TCHAR szFname[_MAX_FNAME]; TCHAR szExt[_MAX_EXT]; _tsplitpath(path.c_str(), NULL, NULL, szFname, szExt); _tmakepath(szPath, NULL, NULL, szFname, szExt); FolderTreeItemInfo* pItem = new FolderTreeItemInfo; pItem->m_sFQPath = path; pItem->m_sRelativePath = szPath; InsertFileItem(hParent, pItem, m_bShowSharedUsingDifferentIcon && IsShared(path), GetIconIndex(path), GetSelIconIndex(path), true); } } while (FindNextFile(hFind, &fData)); } FindClose(hFind); //Now sort the items we just added TVSORTCB tvsortcb; tvsortcb.hParent = hParent; tvsortcb.lpfnCompare = CompareByFilenameNoCase; tvsortcb.lParam = 0; SortChildrenCB(&tvsortcb); //We want to add them before sorting checkRemovedDirs(sFile, hParent); //If no items were added then remove the "+" indicator from hParent if(nDirectories == 0) SetHasPlusButton(hParent, FALSE); //Turn back on the redraw flag if(bUseSetRedraw) SetRedraw(true); }
void FolderTree::Refresh() { //Just in case this will take some time //CWaitCursor wait; SetRedraw(FALSE); //Get the item which is currently selected HTREEITEM hSelItem = GetSelectedItem(); tstring sItem; bool bExpanded = false; if (hSelItem) { sItem = ItemToPath(hSelItem); bExpanded = IsExpanded(hSelItem); } theSharedEnumerator.Refresh(); //Remove all nodes that currently exist Clear(); //Display the folder items in the tree if (m_sRootFolder.empty()) { //Should we insert a "My Computer" node if (m_bShowMyComputer) { FolderTreeItemInfo* pItem = new FolderTreeItemInfo; pItem->m_bNetworkNode = false; int nIcon = 0; int nSelIcon = 0; //Get the localized name and correct icons for "My Computer" LPITEMIDLIST lpMCPidl; if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &lpMCPidl))) { SHFILEINFO sfi; if (SHGetFileInfo((LPCTSTR)lpMCPidl, 0, &sfi, sizeof(sfi), SHGFI_PIDL | SHGFI_DISPLAYNAME)) pItem->m_sRelativePath = sfi.szDisplayName; nIcon = GetIconIndex(lpMCPidl); nSelIcon = GetSelIconIndex(lpMCPidl); //Free up the pidl now that we are finished with it //ASSERT(m_pMalloc); m_pMalloc->Free(lpMCPidl); m_pMalloc->Release(); } //Add it to the tree control m_hMyComputerRoot = InsertFileItem(TVI_ROOT, pItem, false, nIcon, nSelIcon, false); SetHasSharedChildren(m_hMyComputerRoot); } //Display all the drives if (!m_bShowMyComputer) DisplayDrives(TVI_ROOT, false); //Display homegroup /*if (m_bDisplayNetwork) { FolderTreeItemInfo* pItem = new FolderTreeItemInfo; //pItem-> = true; int nIcon = 0; int nSelIcon = 0; //Get the localized name and correct icons for "Network Neighborhood" LPITEMIDLIST lpNNPidl; //SHGetKnownFolderIDList(FOLDERID_HomeGroup, 0, NULL, &lpNNPidl); if (SUCCEEDED(SHGetKnownFolderIDList(FOLDERID_HomeGroup, 0, NULL, &lpNNPidl))) { SHFILEINFO sfi; if (SHGetFileInfo((LPCTSTR)lpNNPidl, 0, &sfi, sizeof(sfi), SHGFI_PIDL | SHGFI_DISPLAYNAME)) pItem->m_sRelativePath = sfi.szDisplayName; nIcon = GetIconIndex(lpNNPidl); nSelIcon = GetSelIconIndex(lpNNPidl); //Free up the pidl now that we are finished with it //ASSERT(m_pMalloc); m_pMalloc->Free(lpNNPidl); m_pMalloc->Release(); } //Add it to the tree control m_hHomegroupRoot = InsertFileItem(TVI_ROOT, pItem, false, nIcon, nSelIcon, false, shared); SetHasSharedChildren(m_hHomegroupRoot, shared); //checkRemovedDirs(Util::emptyStringT, TVI_ROOT, shared); }*/ //Also add network neighborhood if requested to do so if (m_bDisplayNetwork) { FolderTreeItemInfo* pItem = new FolderTreeItemInfo; pItem->m_bNetworkNode = true; int nIcon = 0; int nSelIcon = 0; //Get the localized name and correct icons for "Network Neighborhood" LPITEMIDLIST lpNNPidl; if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_NETWORK, &lpNNPidl))) { SHFILEINFO sfi; if (SHGetFileInfo((LPCTSTR)lpNNPidl, 0, &sfi, sizeof(sfi), SHGFI_PIDL | SHGFI_DISPLAYNAME)) pItem->m_sRelativePath = sfi.szDisplayName; nIcon = GetIconIndex(lpNNPidl); nSelIcon = GetSelIconIndex(lpNNPidl); //Free up the pidl now that we are finished with it //ASSERT(m_pMalloc); m_pMalloc->Free(lpNNPidl); m_pMalloc->Release(); } //Add it to the tree control m_hNetworkRoot = InsertFileItem(TVI_ROOT, pItem, false, nIcon, nSelIcon, false); SetHasSharedChildren(m_hNetworkRoot); //checkRemovedDirs(Util::emptyStringT, TVI_ROOT, shared); } } else { DisplayPath(m_sRootFolder, TVI_ROOT, false); } //Reselect the initially selected item if (hSelItem) SetSelectedPath(sItem, bExpanded); //Turn back on the redraw flag SetRedraw(true); }
bool FolderTree::EnumNetwork(HTREEITEM hParent) { //What will be the return value from this function bool bGotChildren = false; //Check if the item already has a network resource and use it. FolderTreeItemInfo* pItem = (FolderTreeItemInfo*) GetItemData(hParent); NETRESOURCE* pNetResource = pItem->m_pNetResource; //Setup for the network enumeration HANDLE hEnum; DWORD dwResult = WNetOpenEnum(pNetResource ? RESOURCE_GLOBALNET : RESOURCE_CONTEXT, m_dwNetworkItemTypes, 0, pNetResource ? pNetResource : NULL, &hEnum); //Was the read sucessful if (dwResult != NO_ERROR) { //TRACE(_T("Cannot enumerate network drives, Error:%d\n"), dwResult); return FALSE; } //Do the network enumeration DWORD cbBuffer = 16384; bool bNeedMoreMemory = true; bool bSuccess = false; LPNETRESOURCE lpnrDrv = NULL; DWORD cEntries = 0; while (bNeedMoreMemory && !bSuccess) { //Allocate the memory and enumerate lpnrDrv = (LPNETRESOURCE) new BYTE[cbBuffer]; cEntries = 0xFFFFFFFF; dwResult = WNetEnumResource(hEnum, &cEntries, lpnrDrv, &cbBuffer); if (dwResult == ERROR_MORE_DATA) { //Free up the heap memory we have used delete [] lpnrDrv; cbBuffer *= 2; } else if (dwResult == NO_ERROR) bSuccess = true; else bNeedMoreMemory = false; } //Enumeration successful? if (bSuccess) { //Scan through the results for (DWORD i=0; i<cEntries; i++) { tstring sNameRemote; if(lpnrDrv[i].lpRemoteName != NULL) sNameRemote = lpnrDrv[i].lpRemoteName; else sNameRemote = lpnrDrv[i].lpComment; //Remove leading back slashes if (sNameRemote.size() > 0 && sNameRemote[0] == _T('\\')) sNameRemote = sNameRemote.substr(1); if (sNameRemote.size() > 0 && sNameRemote[0] == _T('\\')) sNameRemote = sNameRemote.substr(1); //Setup the item data for the new item pItem = new FolderTreeItemInfo; pItem->m_pNetResource = new NETRESOURCE; memzero(pItem->m_pNetResource, sizeof(NETRESOURCE)); *pItem->m_pNetResource = lpnrDrv[i]; if (lpnrDrv[i].lpLocalName) pItem->m_pNetResource->lpLocalName = _tcsdup(lpnrDrv[i].lpLocalName); if (lpnrDrv[i].lpRemoteName) pItem->m_pNetResource->lpRemoteName = _tcsdup(lpnrDrv[i].lpRemoteName); if (lpnrDrv[i].lpComment) pItem->m_pNetResource->lpComment = _tcsdup(lpnrDrv[i].lpComment); if (lpnrDrv[i].lpProvider) pItem->m_pNetResource->lpProvider = _tcsdup(lpnrDrv[i].lpProvider); if (lpnrDrv[i].lpRemoteName) pItem->m_sFQPath = lpnrDrv[i].lpRemoteName; else pItem->m_sFQPath = sNameRemote; pItem->m_sRelativePath = sNameRemote; pItem->m_bNetworkNode = true; //Display a share and the appropiate icon if (lpnrDrv[i].dwDisplayType == RESOURCEDISPLAYTYPE_SHARE) { //Display only the share name int nPos = pItem->m_sRelativePath.find(_T('\\')); if (nPos >= 0) pItem->m_sRelativePath = pItem->m_sRelativePath.substr(nPos+1); //Now add the item into the control InsertFileItem(hParent, pItem, m_bShowSharedUsingDifferentIcon, GetIconIndex(pItem->m_sFQPath), GetSelIconIndex(pItem->m_sFQPath), false); } else if (lpnrDrv[i].dwDisplayType == RESOURCEDISPLAYTYPE_SERVER) { //Now add the item into the control tstring sServer = _T("\\\\"); sServer += pItem->m_sRelativePath; InsertFileItem(hParent, pItem, false, GetIconIndex(sServer), GetSelIconIndex(sServer), false); } else { //Now add the item into the control //Just use the generic Network Neighborhood icons for everything else LPITEMIDLIST lpNNPidl; int nIcon = 0xFFFF; int nSelIcon = nIcon; if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_NETWORK, &lpNNPidl))) { nIcon = GetIconIndex(lpNNPidl); nSelIcon = GetSelIconIndex(lpNNPidl); //Free up the pidl now that we are finished with it //ASSERT(m_pMalloc); m_pMalloc->Free(lpNNPidl); m_pMalloc->Release(); } InsertFileItem(hParent, pItem, false, nIcon, nSelIcon, false); } bGotChildren = true; } } /* else TRACE(_T("Cannot complete network drive enumeration, Error:%d\n"), dwResult); */ //Clean up the enumeration handle WNetCloseEnum(hEnum); //Free up the heap memory we have used delete [] lpnrDrv; //Return whether or not we added any items return bGotChildren; }
void CFileAndFolder::DisplayPath(const CString& sPath, HTREEITEM hParent, BOOL bUseSetRedraw) { CWaitCursor c; //Speed up the job by turning off redraw // if (bUseSetRedraw) // SetRedraw(FALSE); //Remove all the items currently under hParent HTREEITEM hChild = m_Tree.GetChildItem(hParent); while (hChild) { m_Tree.DeleteItem(hChild); hChild = m_Tree.GetChildItem(hParent); } //Find all the directories and files underneath sPath CSortedArray<CString, CString&> DirectoryPaths; CSortedArray<CString, CString&> FilePaths; CFileFind find; CString sFile; if (sPath.GetAt(sPath.GetLength()-1) == _T('\\')) sFile = sPath + _T("*.*"); else sFile = sPath + _T("\\*.*"); BOOL bFind = find.FindFile(sFile); while (bFind) { bFind = find.FindNextFile(); if (find.IsDirectory()) { if (!find.IsDots()) { CString sPath = find.GetFilePath(); DirectoryPaths.Add(sPath); } } else { if (!find.IsHidden() && m_bShowFiles) { CString sPath = find.GetFilePath(); FilePaths.Add(sPath); } } } //Now sort the 2 arrays prior to added to the tree control DirectoryPaths.SetCompareFunction(CompareByFilenameNoCase); FilePaths.SetCompareFunction(CompareByFilenameNoCase); DirectoryPaths.Sort(); FilePaths.Sort(); //Now add all the directories to the tree control for (int i=0; i<DirectoryPaths.GetSize(); i++) { CString& sPath = DirectoryPaths.ElementAt(i); TCHAR path_buffer[_MAX_PATH]; TCHAR fname[_MAX_FNAME]; TCHAR ext[_MAX_EXT]; _tsplitpath(sPath, NULL, NULL, fname, ext); _tmakepath(path_buffer, NULL, NULL, fname, ext); InsertFileItem(path_buffer, sPath, hParent); } //And the files to the tree control (if required) for (i=0; i<FilePaths.GetSize(); i++) { CString& sPath = FilePaths.ElementAt(i); TCHAR path_buffer[_MAX_PATH]; TCHAR fname[_MAX_FNAME]; TCHAR ext[_MAX_EXT]; _tsplitpath(sPath, NULL, NULL, fname, ext); _tmakepath(path_buffer, NULL, NULL, fname, ext); InsertFileItem(path_buffer, sPath, hParent); } //Turn back on the redraw flag // if (bUseSetRedraw) // SetRedraw(TRUE); }