/* 显现目录下所以文件 */ void FileListWidget::ShowFiles(QStringList filelist) { clear(); if(filelist.size()>0) { int i; for(i=0;i<filelist.size();i++) { qDebug()<<filelist[i]; AddFileItem(filelist[i]); } } }
int CDLNAManager::AddDMSRecFile(wstring filePath) { map<wstring, wstring>::iterator itr; itr = recFileList.find(filePath); if( itr != recFileList.end() ){ return NO_ERR; } wstring objectID; if( AddFileItem(this->recFolderObjectID, filePath, objectID) == NO_ERR ){ recFileList.insert(pair<wstring, wstring>(filePath, objectID)); return NO_ERR; }else{ return ERR_FALSE; } }
int CDLNAManager::AddFolderItem(wstring folderPath, wstring parentObjectID) { wstring searchKey = folderPath; searchKey += L"\\*"; WIN32_FIND_DATA findData; HANDLE find; //指定フォルダのファイル一覧取得 find = FindFirstFile( searchKey.c_str(), &findData); if ( find == INVALID_HANDLE_VALUE ) { return FALSE; } do{ if( (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 ){ wstring filePath; Format(filePath, L"%s\\%s", folderPath.c_str(), findData.cFileName); wstring objectID; AddFileItem(parentObjectID, filePath, objectID); }else{ if(CompareNoCase(findData.cFileName, L".") != 0 && CompareNoCase(findData.cFileName, L"..") != 0 ){ wstring subFolderPath; Format(subFolderPath, L"%s\\%s", folderPath.c_str(), findData.cFileName); DLNA_DMS_CONTAINER_META_INFO info; info.title = findData.cFileName; info.uploadFolderPath = subFolderPath; info.uploadSupportFlag = 0; wstring objectID; if( this->dms.CreateContainer(parentObjectID, &info, objectID) == NO_ERR){ AddFolderItem(subFolderPath, objectID); } } } }while(FindNextFile(find, &findData)); FindClose(find); return NO_ERR; }
int ZipArchiveWriter::AddFileItem(const std::string& sourceFile, const std::string& itemPath, int compressFlag) { if (sourceFile.empty() || itemPath.empty()) return -1; if (compressFlag != 0 && compressFlag != Z_DEFLATED) return -1; IStreamBase* inputStream = new FileStream(sourceFile); if (inputStream) { int ret = AddFileItem(inputStream, ReplaceWin32PathSep(itemPath), compressFlag); delete inputStream; inputStream = nullptr; return ret; } return -1; }
int ZipArchiveWriter::AddFileItem(void* sourceBuf, int srclen, const std::string& itemPath, int compressFlag) { if (!sourceBuf || srclen <= 0) return -1; if (compressFlag != 0 && compressFlag != Z_DEFLATED) return -1; IStreamBase* inputStream = new BufferStream((unsigned char*)sourceBuf, (UINT64)srclen); if (inputStream) { int ret = AddFileItem(inputStream, ReplaceWin32PathSep(itemPath), compressFlag); delete inputStream; inputStream = nullptr; return ret; } return -1; }
/** * @brief WM_INITDIALOG handler of Preview dialog. * @param hwnd - window handle. * @param hwndFocus - system-defined focus window. * @param lParam - user-defined parameter. * @return true to setup focus to system-defined control. */ static BOOL PreviewDlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) { lParam; hwndFocus; if (g_pResManager->m_hBigAppIcon) SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)g_pResManager->m_hBigAppIcon); if (g_pResManager->m_hSmallAppIcon) SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)g_pResManager->m_hSmallAppIcon); CenterWindow(hwnd, GetParent(hwnd)); g_hImageList = ImageList_LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_IMAGETOOLBAR), 16, 0, RGB(0xC0, 0xC0, 0xC0)); HWND hwndImgToolbar = GetDlgItem(hwnd, IDC_IMAGE_COMMANDS); LONG lStyle = GetWindowLong(hwndImgToolbar, GWL_STYLE); SetWindowLong(hwndImgToolbar, GWL_STYLE, lStyle | CCS_NODIVIDER | CCS_NOPARENTALIGN | CCS_NORESIZE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS); SendMessage(hwndImgToolbar, TB_SETIMAGELIST, 0, (LPARAM)g_hImageList); SendMessage(hwndImgToolbar, TB_ADDBUTTONS, countof(g_arrButtons), (LPARAM)g_arrButtons); HWND hwndFileList = GetDlgItem(hwnd, IDC_FILESLIST); ListView_SetExtendedListViewStyle(hwndFileList, LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP); RECT rcList; GetClientRect(hwndFileList, &rcList); rcList.right -= GetSystemMetrics(SM_CXHSCROLL); TCHAR szColumnTitle[64]; LVCOLUMN lvc; ZeroMemory(&lvc, sizeof(lvc)); lvc.mask = LVCF_TEXT | LVCF_WIDTH; lvc.pszText = szColumnTitle; lvc.cx = rcList.right / 2; LoadString(g_hInstance, IDS_COLUMN_FILE, szColumnTitle, countof(szColumnTitle)); ListView_InsertColumn(hwndFileList, CID_FILE_NAME, &lvc); lvc.cx = rcList.right / 4; LoadString(g_hInstance, IDS_COLUMN_TYPE, szColumnTitle, countof(szColumnTitle)); ListView_InsertColumn(hwndFileList, CID_FILE_TYPE, &lvc); lvc.cx = rcList.right / 4; LoadString(g_hInstance, IDS_COLUMN_SIZE, szColumnTitle, countof(szColumnTitle)); ListView_InsertColumn(hwndFileList, CID_FILE_SIZE, &lvc); g_hFile = INVALID_HANDLE_VALUE; g_hBitmap = NULL; g_eFileViewType = FVT_NONE; if (g_dwFlags & BTF_DETAILEDMODE) { TCHAR szFindFileTemplate[MAX_PATH]; PathCombine(szFindFileTemplate, g_szInternalReportFolder, _T("*")); WIN32_FIND_DATA FindData; HANDLE hFindFile = FindFirstFile(szFindFileTemplate, &FindData); if (hFindFile != INVALID_HANDLE_VALUE) { BOOL bMore = TRUE; while (bMore) { if ((FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { TCHAR szFilePath[MAX_PATH]; PathCombine(szFilePath, g_szInternalReportFolder, FindData.cFileName); AddFileItem(hwndFileList, szFilePath); } bMore = FindNextFile(hFindFile, &FindData); } FindClose(hFindFile); } } else AddFileItem(hwndFileList, g_szInternalReportFilePath); size_t nFileCount = g_arrLogLinks.GetCount(); for (size_t nFilePos = 0; nFilePos < nFileCount; ++nFilePos) { CLogLink* pLogLink = g_arrLogLinks[nFilePos]; _ASSERTE(pLogLink != NULL); PCTSTR pszFilePath = pLogLink->GetLogFileName(); AddFileItem(hwndFileList, pszFilePath); } HWND hwndSplitter = GetDlgItem(hwnd, IDC_SPLITTER); g_Splitter.Attach(hwndSplitter); RECT rect; GetClientRect(hwndFileList, &rect); // Set splitter position according to initial dialog layout. g_Splitter.SetSplitterPos(rect.bottom); g_Splitter.SetPanel(0, hwndFileList); HWND hwndFileView = GetDlgItem(hwnd, IDC_FILEVIEW); g_Splitter.SetPanel(1, hwndFileView); g_LayoutMgr.InitLayout(hwnd, g_arrPreviewLayout, countof(g_arrPreviewLayout)); // LVM_SETIMAGELIST resets header control image list g_FilesListOrder.InitList(hwndFileList); return TRUE; }
void CRemoteFileDialog::FillFileList() { CAutoFlag af(m_bFilling, TRUE); if (m_pConnection) { m_pConnection->GetCurrentDirectory(m_sCurFolder); m_bRoot = (m_sCurFolder == _T("/")); if (m_bRoot) { m_sCurFolder = _T("(root)"); } UpdateData(FALSE); m_lcFiles.DeleteAllItems(); m_lcFiles.UpdateWindow(); m_lcFiles.SetRedraw(FALSE); m_mapItems.RemoveAll(); CFtpFileFind ff(m_pConnection); int nID = 0; BOOL bContinue = ff.FindFile(); while (bContinue) { bContinue = ff.FindNextFile(); if (!ff.IsDots()) { if (ff.IsDirectory()) { AddFileItem(ff.GetFileName(), RFDT_FOLDER, nID++, 0, NULL, m_silLarge.GetFolderImageIndex()); } else if (!FolderSelect()) // check extension matches filter { BOOL bMatch = m_sFilterExt.IsEmpty() || m_sFilterExt == _T(".*"); if (!bMatch) { TCHAR szExt[_MAX_EXT] = _T("*"); CString sFilename = ff.GetFileName(); _tsplitpath(sFilename, NULL, NULL, NULL, &szExt[1]); CStringArray aFilterExt; Misc::Split(m_sFilterExt, _T(';'), aFilterExt); bMatch = (Misc::Find(aFilterExt, szExt) != -1); } if (bMatch) { FILETIME tLastMod; ff.GetLastWriteTime(&tLastMod); AddFileItem(ff.GetFileName(), RFDT_FILE, nID++, (DWORD)ff.GetLength(), &tLastMod); } } } } ff.Close(); // resort m_lcFiles.SortItems(SortProc, (DWORD)&m_mapItems); m_lcFiles.SetRedraw(TRUE); // attempt to select a match int nSel = FindMatch(m_sFilenames); if (nSel != -1) { m_lcFiles.SetItemState(nSel, LVIS_SELECTED, LVIS_SELECTED); m_lcFiles.EnsureVisible(nSel, FALSE); } m_toolbar.GetToolBarCtrl().EnableButton(ID_UPONELEVEL, !m_bRoot && !(m_dwOptions & RFD_NONAVIGATE)); UpdateOKButton(); } }
bool CFileSelectList::AddFileItem(LPITEMIDLIST pFullIDLS,int nOption) { bool res = false; SHFILEINFO fileInfo={0}; if(SHGetFileInfo((LPCTSTR)pFullIDLS,0,&fileInfo,sizeof(fileInfo),SHGFI_PIDL |SHGFI_DISPLAYNAME|SHGFI_ATTRIBUTES|SHGFI_ICON|SHGFI_SMALLICON) != 0) { if(fileInfo.dwAttributes & SFGAO_FILESYSTEM) { bool bIsFile = false; if(fileInfo.dwAttributes & SFGAO_FOLDER)//判断是否是文件系统对象文件夹,排除zip文件 { if(fileInfo.dwAttributes & SFGAO_STREAM) { int nSysID = GetWindowsSystemID(); if(nSysID == WINDOWS_XP || nSysID == WINDOWS_VISTA || nSysID == WINDOWS_2003) { bIsFile = true;//zip文件 } } } else { bIsFile = true; } if(!bIsFile) //是文件夹,但不是.zip文件 { IShellFolder *pIParentFolder,*pICurFolder; LPITEMIDLIST pLocalIDLS; if(nOption & UNIFOLDER_PIG)//作为整体归档 { goto PIG_FILE; } else//归档下面的文件 { if(S_OK == SHBindToParent(pFullIDLS,IID_IShellFolder,(void**)&pIParentFolder,(LPCITEMIDLIST*)&pLocalIDLS)) { if(S_OK == pIParentFolder->BindToObject(pLocalIDLS,NULL,IID_IShellFolder,(void**)&pICurFolder)) { IEnumIDList* pIEnum; SHCONTF enumFlag = (nOption&FOLDER_RECURSIVEG_PIG)?(SHCONTF_FOLDERS|SHCONTF_NONFOLDERS):SHCONTF_NONFOLDERS; if(S_OK == pICurFolder->EnumObjects(NULL,enumFlag,&pIEnum)) { for(HRESULT call_res = pIEnum->Next(1,&pLocalIDLS,NULL);call_res == S_OK;call_res = pIEnum->Next(1,&pLocalIDLS,NULL)) { LPITEMIDLIST pFullChildIDLST = ILCombine(pFullIDLS,pLocalIDLS); if(pFullChildIDLST != NULL) { AddFileItem(pFullChildIDLST,nOption); ILFree(pFullChildIDLST); } CoTaskMemFree(pLocalIDLS); } pIEnum->Release(); } pICurFolder->Release(); } pIParentFolder->Release(); } } } else //is file { PIG_FILE: TCHAR tcbufPath[MAX_PATH]; if(SHGetPathFromIDList(pFullIDLS,tcbufPath)) { if(!IsAlreayIn(FilePath2Url(CString(tcbufPath)))) { CString strPathFolder,strFName,strDriver,strExt; SplitFilePath(CString(tcbufPath),strPathFolder,strDriver,strFName,strExt); LVITEM lvit = {0}; lvit.mask = LVIF_IMAGE|LVIF_TEXT; lvit.iItem = GetItemCount(); lvit.pszText = (LPWSTR)(LPCTSTR)strFName; lvit.cchTextMax = strFName.GetLength(); int iImg; if(!m_iSys2Self.Lookup(fileInfo.iIcon,iImg)) { //CImageList *pImgLs = GetImageList(LVSIL_SMALL); iImg = GetImageList(LVSIL_SMALL)->Add(fileInfo.hIcon); m_iSys2Self.SetAt(fileInfo.iIcon,iImg); } lvit.iImage = iImg; int iItem = InsertItem(&lvit); //SetItem(iItem,1,LVIF_TEXT,strPathFolder+L"\\",0,0,0,0); SetItemText(iItem,1,tcbufPath); ItemDataType* pItemData = new ItemDataType; pItemData->strItemUrl = FilePath2Url(tcbufPath); SetItemData(iItem,(DWORD_PTR)pItemData); } } } } DestroyIcon(fileInfo.hIcon); } return res; }
/* 新建文件夹槽函数 */ void FileListWidget::AddNewFolder() { AddFileItem(tr("未命名/")); EditFileName(); }
void CFolderListCtrl::RefreshFileList() { std::vector<CFLCItemData *>arrListCache(m_nItemCount); int i; for (i=0;i<m_nItemCount;i++) { arrListCache[i] = reinterpret_cast<CFLCItemData *>(GetItemData(i)); arrListCache[i]->m_bFoundOnRefresh = false; } SCStringVector::iterator itExt = m_Properties.m_vsExt.begin(); CSCADString sPath; struct _tfinddata_t fd; int nLargeIconInd = 0; int nSmallIconInd = 0; int nItemCount = m_nItemCount; for( ; itExt != m_Properties.m_vsExt.end(); ++itExt ) { sPath = m_sFolderPath + _T("\\") + *itExt; intptr_t hFindHandle = _tfindfirst( sPath, &fd ); if( hFindHandle == -1 ) continue; AddFileTypeIcons(fd, nLargeIconInd, nSmallIconInd); do { bool bFileFound = false; CSCADString sFileName; if( m_sFolderPath.GetLength() && ( m_sFolderPath[m_sFolderPath.GetLength()-1] == _T('\\') || m_sFolderPath[m_sFolderPath.GetLength()-1] == _T('/') ) ) sFileName = m_sFolderPath+ fd.name; else sFileName = m_sFolderPath + ( _T("\\") ) + fd.name; for (int k=0; k<nItemCount;k++) { if (arrListCache[k]->m_sFilePath == sFileName) { bFileFound = true; arrListCache[k]->m_bFoundOnRefresh = true; if (fd.time_write != arrListCache[k]->m_tModified) { arrListCache[k]->m_bProcessed = false; if (m_strSelectedPath.CompareNoCase(arrListCache[k]->m_sFilePath)==0) { CSCAD3DMdlSettings::Get3DS()->SetViewFilePath( arrListCache[k]->m_sFilePath, arrListCache[k]->m_sExt ); } break; } } } if (!bFileFound) { AddFileItem(fd, nLargeIconInd, nSmallIconInd,*itExt); } } while( _tfindnext( hFindHandle, &fd ) != -1 ); _findclose( hFindHandle ); } m_nImageBalance = 0; for (i=0;i<m_nItemCount;i++) { CFLCItemData *pData = reinterpret_cast<CFLCItemData *>(GetItemData(i)); if (!pData->m_bFoundOnRefresh) { delete pData; CListCtrl::DeleteItem(i); m_nItemCount--; } else { if (!pData->m_bProcessed) m_nImageBalance++; } } SortItems( m_flciColumns[m_nCurColumn].m_fnCmp, m_bSortAscending ); ASSERT(m_nItemCount == GetItemCount()); UpdateFileCount(); SetRedrawItemPos( 0, true ); }
BOOL CFolderListCtrl::SetCurFolder( const CSCADString& sFolderPath, bool bForce) { if( !bForce && !m_sFolderPath.CompareNoCase( sFolderPath ) ) return TRUE; Timer.Start(); m_DirChangeListener.SetDir(sFolderPath, m_hWnd); /* SCDefProjInfo proj_info; SCADDefProj::GetInfo( m_Properties.m_DefProj, proj_info ); SCMdl3DSetCameraPos( proj_info.m_ptViewDir, proj_info.m_ptUpOrient ); */ // ReSharper disable once CppEntityAssignedButNoRead extern SCDefProjType ThumbProjection; ThumbProjection = m_Properties.m_DefProj; if(CSCAD3DMdlSettings::Get3DS()) { CSCAD3DMdlSettings::Get3DS()->CancelDraw(); CSCAD3DMdlSettings::Get3DS()->SetStartDrawPos( 0 ); } CreateImageList(); DeleteAllItemsData(); DeleteAllItems(); m_sFolderPath = sFolderPath; m_nItemCount = 0; m_nImageBalance = 0; m_nSelectedItem = -1; SetSelectionMark( 0 ); int i; for( i = m_imlLargeIcons.GetImageCount() - 1; i >= 0; i-- ) m_imlLargeIcons.Remove( i ); for( i = m_imlSmallIcons.GetImageCount() - 1; i >= 0; i-- ) m_imlSmallIcons.Remove( i ); if( _taccess( sFolderPath, 0 ) == -1 ) return TRUE; SCStringVector::iterator itExt = m_Properties.m_vsExt.begin(); CSCADString sPath; struct _tfinddata_t fd; int nLargeIconInd = 0; int nSmallIconInd = 0; for( ; itExt != m_Properties.m_vsExt.end(); ++itExt ) { sPath = m_sFolderPath + _T("\\") + *itExt; intptr_t hFindHandle = _tfindfirst( sPath, &fd ); if( hFindHandle == -1 ) continue; AddFileTypeIcons(fd, nLargeIconInd, nSmallIconInd); do { AddFileItem(fd, nLargeIconInd, nSmallIconInd, *itExt); } while( _tfindnext( hFindHandle, &fd ) != -1 ); _findclose( hFindHandle ); } SortItems( m_flciColumns[m_nCurColumn].m_fnCmp, m_bSortAscending ); m_nImageBalance = m_nItemCount; SetRedrawItemPos( 0, true ); if( AfxGetMainWnd() ) { CSCADViewerStatBar &theStatusBar = static_cast<CScadViewerFrame*>(AfxGetMainWnd())->GetStatusBar(); theStatusBar.SetFileCount( m_nItemCount ); } UpdateFileCount(); return TRUE; }