Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. void BuildDatabase(HWND hWnd, TCHAR* path)
  2. {
  3. TCHAR buffer[MAX_PATH_LEN];
  4. StrCpy(buffer, path); //Copy the path of item (include drive letter path)
  5. StrCat(buffer, _T("\\*")); //Add to find all item in directory
  6.  
  7. WIN32_FIND_DATA ffd; //Contains information about the file that is found by Find first file and Find next file
  8. HANDLE hFind = FindFirstFileW(buffer, &ffd);
  9.  
  10. //If the function fails or fails to locate files from the search string
  11. if (hFind == INVALID_HANDLE_VALUE)
  12. return;
  13.  
  14. TCHAR* folderPath;
  15.  
  16. do
  17. {
  18. folderPath = new TCHAR[wcslen(path) + wcslen(ffd.cFileName) + 2];
  19.  
  20. //Set path
  21. StrCpy(folderPath, path);
  22. if (wcslen(path) != 3)
  23. StrCat(folderPath, _T("\\"));
  24. StrCat(folderPath, ffd.cFileName);
  25.  
  26. DWORD fileAttribute = ffd.dwFileAttributes;
  27. if ((fileAttribute & FILE_ATTRIBUTE_DIRECTORY)) //Get only directory and folder
  28. {
  29. if ((_tcscmp(ffd.cFileName, _T(".")) != 0) && (_tcscmp(ffd.cFileName, _T("..")) != 0)) //Ignore . (curr dir) and .. (parent dir))
  30. BuildDatabase(hWnd, folderPath);
  31. }
  32. else if (((ffd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) != FILE_ATTRIBUTE_SYSTEM))
  33. {
  34.  
  35. if (!StrCmpI(PathFindExtension(folderPath), _T(".lnk")))
  36. {
  37. TCHAR shortcutPath[MAX_PATH_LEN];
  38. if (ResolveIt(hWnd, folderPath, shortcutPath, MAX_PATH_LEN) == S_OK)
  39. StrCpy(folderPath, shortcutPath);
  40. }
  41. if (!StrCmpI(PathFindExtension(folderPath), _T(".exe")))
  42. {
  43. WinApp* winApp = new WinApp;
  44. winApp->AppName = new TCHAR[wcslen(ffd.cFileName) - 2];
  45. winApp->AppPath = new TCHAR[wcslen(folderPath) + 1];
  46. StrNCpy(winApp->AppName, ffd.cFileName, wcslen(ffd.cFileName) - 3);
  47. StrCpy(winApp->AppPath, folderPath);
  48. if (isDuplicate(winApp))
  49. delete winApp;
  50. else g_AppsList.push_back(winApp);
  51. }
  52. }
  53. } while (FindNextFileW(hFind, &ffd));
  54.  
  55. FindClose(hFind);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement