bool CBrowseDir::BrowseDir (const char *dir,const char *filespec) { _chdir(dir); //首先查找dir中符合要求的文件 long hFile; _finddata_t fileinfo; if ((hFile=_findfirst(filespec,&fileinfo)) != -1) { do { //检查是不是目录 //如果不是,则进行处理 if (!(fileinfo.attrib & _A_SUBDIR)) { char filename[_MAX_PATH]; strcpy(filename,dir); strcat(filename,fileinfo.name); if (!ProcessFile(filename)) return false; } } while (_findnext(hFile,&fileinfo) == 0); _findclose(hFile); } //查找dir中的子目录 //因为在处理dir中的文件时,派生类的ProcessFile有可能改变了 //当前目录,因此还要重新设置当前目录为dir。 //执行过_findfirst后,可能系统记录下了相关信息,因此改变目录 //对_findnext没有影响。 _chdir(dir); if ((hFile=_findfirst("*.*",&fileinfo)) != -1) { do { //检查是不是目录 //如果是,再检查是不是 . 或 .. //如果不是,进行迭代 if ((fileinfo.attrib & _A_SUBDIR)) { if (strcmp(fileinfo.name,".") != 0 && strcmp (fileinfo.name,"..") != 0) { char subdir[_MAX_PATH]; strcpy(subdir,dir); strcat(subdir,fileinfo.name); strcat(subdir,"\\"); ProcessDir(subdir,dir); if (!BrowseDir(subdir,filespec)) return false; } } } while (_findnext(hFile,&fileinfo) == 0); _findclose(hFile); } return true; }
DWORD WINAPI SongListThread(LPVOID param) { MSG msg; while (GetMessage(&msg, 0, 0, 0)) { switch (msg.message) { case ID_CMD_DIR: { wchar_t* dir = (wchar_t*)msg.wParam; songlist.scan = TRUE; BrowseDir(dir); songlist.scan = FALSE; SAFE_DELETE_ARRAY(dir); } break; case ID_CMD_FILE: { wchar_t* filename = (wchar_t*)msg.wParam; songlist.scan = TRUE; SongListFile(filename); songlist.scan = FALSE; SAFE_DELETE_ARRAY(filename); } break; case ID_CMD_CD: { CDROM* cdrom = (CDROM*)msg.wParam; songlist.scan = TRUE; GetCDTrack(cdrom); songlist.scan = FALSE; } break; } DispatchMessage(&msg); } songlist.quit = TRUE; SongListClear(); CloseHandle(songlist.thread); DeleteObject(songlist.bitmap); DeleteDC(songlist.imgplay.hdc); DeleteDC(songlist.imgpause.hdc); DeleteDC(songlist.bdc); ReleaseDC(songlist.hWnd, songlist.mdc); SetEvent(songlist.exit); return 1; }
void BrowseDir(const wchar_t* dir) { int len = wcslen(dir); DWORD size = 1024; TCHAR* path = new TCHAR[size]; ZeroMemory(path, size); StrCpy(path, dir); if (dir[len - 1] != '\\') StrCat(path, L"\\"); StrCat(path, L"*"); WIN32_FIND_DATA fd; HANDLE hfile = FindFirstFile(path, &fd); if (hfile == INVALID_HANDLE_VALUE) { FindClose(hfile); SAFE_DELETE_ARRAY(path); return; } TCHAR* temp = new TCHAR[size]; ZeroMemory(temp, size); BOOL finish = FALSE; while (!finish) { StrCpy(temp, dir); if (dir[len - 1] != '\\') StrCat(temp, L"\\"); StrCat(temp, fd.cFileName); BOOL directory = ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0); if (directory) { if (StrCmp(fd.cFileName, L".") == 0 || StrCmp(fd.cFileName, L"..") == 0) { finish = (FindNextFile(hfile, &fd) == FALSE); continue; } else BrowseDir(temp); } else SongListFile(temp); finish = (FindNextFile(hfile, &fd) == FALSE); } FindClose(hfile); SAFE_DELETE_ARRAY(temp); SAFE_DELETE_ARRAY(path); }
// 实现文件转储功能 // const char *dir; // 转储文件目录 // const char *filespec; // 转储文件规则 // const int nSaveNum; // 保存文件数目 bool CLogMgr::FileConveySave(const TCHAR *dir,const TCHAR *filespec,const int nSaveNum) { // 初始化 memset(m_szFileName, 0x00, sizeof(m_szFileName)); memset(m_szFileCreateTime, 0x00, sizeof(m_szFileCreateTime)); m_nSaveIndex = 0; bool bRes = false; // 设置遍历目录 bRes = SetInitDir(dir); if (!bRes) { // 转储失败 return false; } // 遍历文件,并且将多余的文件删除掉(即大于保存数的文件) bRes = BrowseDir(m_szInitDir, filespec); if (!bRes) { // 遍历失败 return false; } // 排序 if (m_nSaveIndex > nSaveNum) { sort(); // 循环删除多余旧文件 for(int i = 0; i < m_nSaveIndex - nSaveNum; i++) { _tunlink(m_szFileName[i]); } } return true; }
QByteArray QFileIOService::ExecuteRDSCommand(QRDSServer &rdsserver, quint8 command, const QMap<QString, QString> &map) { QByteArray ret; switch (command) { case QBrowseDirCommand: return BrowseDir(rdsserver, map); break; case QFileReadCommand: return FileRead(rdsserver, map); break; case QFileWriteCommand: return FileWrite(rdsserver, map); break; case QFileRenameCommand: return FileRename(rdsserver, map); break; case QFileRemoveFileCommand: return FileRemove(rdsserver, map, true); break; case QFileRemoveDirectoryCommand: return FileRemove(rdsserver, map, false); break; case QFileExistCommand: return Existence(rdsserver, map); break; case QFileCreateDirCommand: return CreateDir(rdsserver, map); break; case QFileGetRootDirCommand: return GetRootDir(rdsserver); break; } return ret; }
bool CBrowseDir::BeginBrowse(const char *filespec) { ProcessDir(m_szInitDir,NULL); return BrowseDir(m_szInitDir,filespec); }
void CBrowseDir::Browse(const char *filespec,FunctionPointor fun) { mFun = fun; BrowseDir(m_szInitDir,filespec); }
INT_PTR CALLBACK DialogProc( HWND hWnd, // handle to dialog box UINT msg, // message WPARAM wParam, // first message parameter LPARAM lParam) // second message parameter { switch (msg) { case WM_INITDIALOG: { DWORD common_control_lib_version= GetDllVersion(_T("comctl32.dll")); g_update_common_ctrls = common_control_lib_version < PACKVERSION(5,80); // anything below 5.80 is worth upgrading //{ // ::MessageBox(hWnd, _T("ExifPro requires Common Controls library (ComCtl32.dll) version 4.71 or higher.\n\n") // _T("This library can be found on the Microsoft download site either as a stand-alone \n") // _T("component or part of the Internet Explorer 4.0 or later install package."), // g_INSTALLER, MB_OK | MB_ICONERROR); // ::EndDialog(hWnd, IDCANCEL); // return false; //} } if (g_update_common_ctrls) { // hide it--comctl updater needs to restart ::ShowWindow(::GetDlgItem(hWnd, IDC_RUN), SW_HIDE); } { HICON icon= ::LoadIcon(g_instance_handle, MAKEINTRESOURCE(IDR_MAINFRAME)); ::SendMessage(hWnd, WM_SETICON, ICON_SMALL, LPARAM(icon)); ::SendMessage(hWnd, WM_SETICON, ICON_BIG, LPARAM(icon)); } { HDC dc= ::GetWindowDC(hWnd); int log_pixels_y= ::GetDeviceCaps(dc, LOGPIXELSY); ::ReleaseDC(hWnd, dc); // create title font { HFONT font= static_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT)); LOGFONT lf; ::GetObject(font, sizeof lf, &lf); lf.lfWeight = FW_BOLD; lf.lfHeight = -MulDiv(18, log_pixels_y, 96); lf.lfWidth = 0; lf.lfQuality = ANTIALIASED_QUALITY; _tcscpy_s(lf.lfFaceName, LF_FACESIZE, _T("Tahoma")); g_fntTitle = ::CreateFontIndirect(&lf); } // create license info font { HFONT font= static_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT)); LOGFONT lf; ::GetObject(font, sizeof lf, &lf); lf.lfWeight = FW_NORMAL; lf.lfHeight = -MulDiv(9, log_pixels_y, 96); lf.lfWidth = 0; //lf.lfQuality = ANTIALIASED_QUALITY; _tcscpy_s(lf.lfFaceName, LF_FACESIZE, _T("Small Fonts")); g_fntLicense = ::CreateFontIndirect(&lf); } } g_camera_image = ::ImageList_LoadImage(g_instance_handle, MAKEINTRESOURCE(IDB_CAMERA), 48, 0, CLR_NONE, IMAGE_BITMAP, LR_CREATEDIBSECTION); { TCHAR path[2 * MAX_PATH]= _T("c:\\Program Files"); ITEMIDLIST* idl= 0; if (g_IsWindows64) { if (HINSTANCE dll= ::LoadLibrary(_T("shell32.dll"))) { typedef HRESULT (STDAPICALLTYPE *FN_SHGetKnownFolderIDList)(REFKNOWNFOLDERID, DWORD, HANDLE, PIDLIST_ABSOLUTE*); FN_SHGetKnownFolderIDList SHGetKnownFolderIDListFn= reinterpret_cast<FN_SHGetKnownFolderIDList>(::GetProcAddress(dll, "SHGetKnownFolderIDList")); if (SHGetKnownFolderIDListFn) { if (SHGetKnownFolderIDListFn(FOLDERID_ProgramFilesX64, 0, HANDLE(0), &idl) == S_OK) { ::SHGetPathFromIDList(idl, path); IMallocPtr malloc; if (::SHGetMalloc(&malloc) == 0) malloc->Free(idl); } } ::FreeLibrary(dll); } if (idl == 0) { TCHAR buffer[MAX_PATH]; DWORD d= ::GetEnvironmentVariable(_T("ProgramW6432"), buffer, MAX_PATH); if (d > 0) _tcscpy_s(path, MAX_PATH, buffer); } } else if (::SHGetSpecialFolderLocation(hWnd, CSIDL_PROGRAM_FILES, &idl) == 0) { ::SHGetPathFromIDList(idl, path); IMallocPtr malloc; if (::SHGetMalloc(&malloc) == 0) malloc->Free(idl); } _tcscat_s(path, MAX_PATH * 2, _T("\\ExifPro ") EP_VER); ::SetDlgItemText(hWnd, IDC_FOLDER, path); if (pfnAutoCompleteFn) (*pfnAutoCompleteFn)(::GetDlgItem(hWnd, IDC_FOLDER), SHACF_FILESYSTEM); } ::CheckDlgButton(hWnd, IDC_RUN, 1); ::CheckDlgButton(hWnd, IDC_ADD_ICON, 1); ::CheckDlgButton(hWnd, IDC_PROGRAMS, 1); if (HWND edit= ::GetDlgItem(hWnd, IDC_FOLDER)) ::SendMessage(edit, EM_LIMITTEXT, MAX_PATH - 16, 0); ::SendMessage(hWnd, WM_NEXTDLGCTL, WPARAM(::GetDlgItem(hWnd, IDOK)), 1L); return false; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: { TCHAR path[MAX_PATH]= { 0 }; if (::GetDlgItemText(hWnd, IDC_FOLDER, path, MAX_PATH) > 0) { HCURSOR cursor= ::SetCursor(::LoadCursor(0, IDC_WAIT)); if (InstallExifPro(path, !!::IsDlgButtonChecked(hWnd, IDC_ADD_ICON), !!::IsDlgButtonChecked(hWnd, IDC_PROGRAMS))) { if (!g_update_common_ctrls) // if comctl updated it waits for a restart { // launch ExifPro? if (::IsDlgButtonChecked(hWnd, IDC_RUN)) { TCHAR exif[MAX_PATH * 2]= { 0 }; AppendFileName(path, g_EXIF_APP, exif); ::ShellExecute(0, _T("open"), exif, 0, 0, SW_SHOWNORMAL); } else { ::MessageBox(hWnd, _T("ExifPro was installed successfully."), g_INSTALLER, MB_ICONINFORMATION | MB_OK); } } ::EndDialog(hWnd, wParam); } } } return true; case IDCANCEL: ::EndDialog(hWnd, wParam); return TRUE; case IDC_BROWSE_DIR: BrowseDir(hWnd); break; case ID_LICENSE: ShowLicense(); break; } return TRUE; case WM_ERASEBKGND: if (HDC dc= HDC(wParam)) { RECT rect; ::GetClientRect(hWnd, &rect); RECT rectTop= rect; rectTop.bottom = 50; rect.top = rectTop.bottom; ::SetBkMode(dc, OPAQUE); ::SetBkColor(dc, RGB(255,255,255)); ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rectTop, 0, 0, 0); ::ImageList_Draw(g_camera_image, 0, dc, 14, 7, ILD_NORMAL); HGDIOBJ hOld= ::SelectObject(dc, g_fntTitle); ::SetTextColor(dc, RGB(0,0,0)); const TCHAR* title= _T("ExifPro ") EP_VER _T(" Installer"); ::ExtTextOut(dc, 74, 13, 0, 0, title, _tcslen(title), 0); ::SelectObject(dc, hOld); ::SetBkColor(dc, ::GetSysColor(COLOR_3DSHADOW)); RECT rectLine= rectTop; rectLine.top = rectLine.bottom - 1; ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rectLine, 0, 0, 0); ::SetBkColor(dc, ::GetSysColor(COLOR_3DFACE)); ::ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rect, 0, 0, 0); hOld = ::SelectObject(dc, g_fntLicense); ::SetTextColor(dc, RGB(0,0,0)); const TCHAR* info= _T("By installing this product, you are agreeing to be bound by the terms of the license."); ::ExtTextOut(dc, rect.left + 16, rect.bottom - 16, 0, 0, info, _tcslen(info), 0); ::SelectObject(dc, hOld); } return true; } return 0; }
int main( int argc, char* argv[] ){ DWORD res = 0, start = 0, version = 0; DOUBLE time = 0; if ( argc != 4 ){ printf( "usage example: transplant f:\\scannow\\ f:\\\n"); printf( " transplant f:\\scannow\\ all\n" ); return 0; } memset( DATAPATH, 0, 512 ); strcpy( DATAPATH, argv[1] ); strcpy( Options, argv[3] ); if ( strchr( Options, 'd') ) Display = TRUE; if ( strchr( Options, 'l') ) { if ( strchr( Options, 'f') ){ memset( DATAPATH, 0, 512); strcpy( DATAPATH, argv[1] ); strcat( DATAPATH, "scan_result.log"); g_log = fopen( DATAPATH, "w" ); } if ( strchr( Options, 'n') ){ memset( DATAPATH, 0, 512 ); strcpy( DATAPATH, argv[1] ); strcat( DATAPATH, "not_found.log"); g_log2 = fopen( DATAPATH, "w" ); } #if 1 memset( DATAPATH, 0, 512 ); strcpy( DATAPATH, argv[1] ); strcat( DATAPATH, "44444.log"); g_log4 = fopen( DATAPATH, "w" ); #endif } if ( strchr( Options, 'm') ){ memset( DATAPATH, 0, 512 ); strcpy( DATAPATH, argv[1] ); strcat( DATAPATH, "mistake.log"); gLog3 = CreateFile( DATAPATH, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); } version = RSGetEngineVersion(); printf( "Stream Engine V %d.%d\n", version>>8, version&0xff ); //printf( "%d\n", sizeof(struct _StreamObject) ); RSEngineInit(); //RSRegisterCallback( fun, &time ); strcpy( DATAPATH, argv[1] ); strcat( DATAPATH, "PeerArray.img" ); res = RSLoadLib( DATAPATH , 0 ); if ( res == 0 ){ printf( "LIB LOAD ERROR\n" ); return 0; } printf( "Virus Scanning ...\n" ); start = GetTickCount(); if ( strchr( Options, 'z' ) ){ ScanFileList( argv[2] ); }else{ if( strcmp( argv[2], "all" ) == 0 ){ BrowseDir( "L:\\", 0); BrowseDir( "K:\\", 0); BrowseDir( "J:\\", 0); BrowseDir( "I:\\", 0); BrowseDir( "H:\\", 0); BrowseDir( "g:\\", 0); BrowseDir( "f:\\", 0); BrowseDir( "e:\\", 0); BrowseDir( "d:\\", 0); BrowseDir( "c:\\", 0); }else{ memset( DATAPATH, 0, 512 ); strcpy( DATAPATH, argv[2] ); BrowseDir( DATAPATH, 0 ); } } time = ( GetTickCount() - start )/(1000.00); { if ( g_log ){ fprintf( g_log, "VirusFound = %d\n", VirusFound ); fprintf( g_log, "time used = %f\n", time ); fprintf( g_log, "file scaned = %d\n", total_file ); fprintf( g_log, "Max Time Used In Scaning A Single file is %d milliseconds\n", MaxTimeUsed); fclose( g_log ); } if ( g_log2 ) fclose( g_log2 ); if ( gLog3 != INVALID_HANDLE_VALUE ) CloseHandle( gLog3 ); if ( g_log4 ) fclose( g_log4 ); } RSUnloadLib(); printf("result = %d\n", gCount); //RSDeregisterCallback(); RSEngineUninit(); return 0; }
void BrowseDir( PCHAR pName, void* para ){ WIN32_FIND_DATAA info; HANDLE hFind; CHAR* name = NULL; CHAR* newdir = NULL; name = (CHAR*)malloc( BROWSE_BUFF_SIZE ); if ( name == NULL ){ BrowseDirErr = ERR_MEM_ALLOC; return; } memset( name, 0, BROWSE_BUFF_SIZE ); strcpy( name, pName ); strcat( name, "*.*" ); hFind = FindFirstFile( name, &info); if ( hFind == (HANDLE)-1 ){ BrowseDirErr = ERR_FILE_OPEN; free( name ); return; } total_dir ++; while ( FindNextFile( hFind, &info) ){ if ( !strcmp( info.cFileName, "..") ){ continue; } if ( info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ){ newdir = (CHAR*)malloc( BROWSE_BUFF_SIZE ); if( newdir == NULL ){ BrowseDirErr = ERR_MEM_ALLOC; break; } memset( newdir, 0, BROWSE_BUFF_SIZE ); strcpy( newdir, pName ); strcat( newdir, info.cFileName ); strcat( newdir, "\\" ); BrowseDir( newdir, para ); free( newdir ); newdir = NULL; continue; } memset( name, 0, 1024); strcpy( name, pName ); strcat( name, info.cFileName); total_file ++; NoName( name, 0, 0 ); } FindClose( hFind); free( name ); }
CString CWizBrowseDirectory::Do (CWnd* pFromWnd, LPCTSTR Title) { CString retStr; BrowseDir(retStr, pFromWnd, Title); return retStr; }
CString CBrowseDirectory::Do(LPCTSTR Title, CWnd* pFromWnd) { CString retStr; BrowseDir(retStr, pFromWnd, Title); return retStr; }