Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void BuildDatabase(HWND hWnd, TCHAR* path)
- {
- TCHAR buffer[MAX_PATH_LEN];
- StrCpy(buffer, path); //Copy the path of item (include drive letter path)
- StrCat(buffer, _T("\\*")); //Add to find all item in directory
- WIN32_FIND_DATA ffd; //Contains information about the file that is found by Find first file and Find next file
- HANDLE hFind = FindFirstFileW(buffer, &ffd);
- //If the function fails or fails to locate files from the search string
- if (hFind == INVALID_HANDLE_VALUE)
- return;
- TCHAR* folderPath;
- do
- {
- folderPath = new TCHAR[wcslen(path) + wcslen(ffd.cFileName) + 2];
- //Set path
- StrCpy(folderPath, path);
- if (wcslen(path) != 3)
- StrCat(folderPath, _T("\\"));
- StrCat(folderPath, ffd.cFileName);
- DWORD fileAttribute = ffd.dwFileAttributes;
- if ((fileAttribute & FILE_ATTRIBUTE_DIRECTORY)) //Get only directory and folder
- {
- if ((_tcscmp(ffd.cFileName, _T(".")) != 0) && (_tcscmp(ffd.cFileName, _T("..")) != 0)) //Ignore . (curr dir) and .. (parent dir))
- BuildDatabase(hWnd, folderPath);
- }
- else if (((ffd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) != FILE_ATTRIBUTE_SYSTEM))
- {
- if (!StrCmpI(PathFindExtension(folderPath), _T(".lnk")))
- {
- TCHAR shortcutPath[MAX_PATH_LEN];
- if (ResolveIt(hWnd, folderPath, shortcutPath, MAX_PATH_LEN) == S_OK)
- StrCpy(folderPath, shortcutPath);
- }
- if (!StrCmpI(PathFindExtension(folderPath), _T(".exe")))
- {
- WinApp* winApp = new WinApp;
- winApp->AppName = new TCHAR[wcslen(ffd.cFileName) - 2];
- winApp->AppPath = new TCHAR[wcslen(folderPath) + 1];
- StrNCpy(winApp->AppName, ffd.cFileName, wcslen(ffd.cFileName) - 3);
- StrCpy(winApp->AppPath, folderPath);
- if (isDuplicate(winApp))
- delete winApp;
- else g_AppsList.push_back(winApp);
- }
- }
- } while (FindNextFileW(hFind, &ffd));
- FindClose(hFind);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement