Code:
case SCAN:
{
//if the scan was stopped, restart it
if(!ContinueScan)
ContinueScan = true;
//initialize the scan for the first time
//(only changes drives once)
if(initScan == false){
_chdir("C:\\");
if((hFind = FindFirstFile("*.*",&ffData)) == INVALID_HANDLE_VALUE){
SetDlgItemText(Hwnd,TEST2,"INVALID_HANDLE_VALUE (complete failure)");
}
else
initScan = true;
}
//checks if hThread has an assignment, prevents multiple
//threads from being made
if((StartScan && hThread == NULL) || ContinueScan)
hThread = _beginthread(&SystemScan,0,NULL);
StartScan = false;
}
break;
/* on down to the called thread */
void SystemScan(void* pArgv)
{
while(ContinueScan || StartScan)
{
buffer = _getcwd(lBuffer,MAX_PATH); //gets current directory
//if cFileName is '.' or '..' get the next file
if((strcmp(ffData.cFileName, ".") == 0 || strcmp(ffData.cFileName, "..") == 0))
FindNextFile(hFind,&ffData);
//if cFileName != '.' or '..' then check if it's directory or not
if(!(strcmp(ffData.cFileName, ".") == 0 || strcmp(ffData.cFileName, "..") == 0)){
if(ffData.dwFileAttributes != FILE_ATTRIBUTE_DIRECTORY){
/* THIS IS WHERE FILE CHECKING WILL OCCUR */
if(strncmp(ffData.cFileName,"test.dll",MAX_PATH) == 0){
SetDlgItemText(Hwnd,TEST2,"FILE FOUND!"); //file found
SetDlgItemText(Hwnd,TESTING,ffData.cFileName); //show the file found
ContinueScan = false; //stop scanning
break; //break so "FILE FOUND" appears
}
SetDlgItemText(Hwnd,TESTING,ffData.cFileName); //show current file
SetDlgItemText(Hwnd,TEST2,buffer); //show current directory
FindNextFile(hFind,&ffData); //move on to the next file
}
if(ffData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){
pbuffer = _getcwd(lBuffer,MAX_PATH); //get new parent
//at time of execution this is the current directory, becomes parent after
SetDlgItemText(Hwnd,TEST2,pbuffer); //display current parent
strcat(buffer,"\\"); //get read to open next directory
strcat(buffer,ffData.cFileName); //next child path
_chdir(buffer); //change to next child directory
hFind = FindFirstFile("*.*",&ffData); //get the first file
}
}
else
SetDlgItemText(Hwnd,TESTING,"strcmp returned 0 (complete failure)");
if(FindNextFile(hFind,&ffData) == 0){
if(GetLastError() == ERROR_NO_MORE_FILES){
if(_chdir("..") == 0) //go back to parent
{
pbuffer = _getcwd(lBuffer,MAX_PATH); //get parent
SetDlgItemText(Hwnd,TEST2,pbuffer); //show parent
/* THIS IS WRONG WITH THE WAY IT CHOOSES THE NEXT DIRECTORY*/
n = 0; //reset count down the list
hFind = FindFirstFile("*.*",&ffData);
while(n < pass){
while(strcmp(ffData.cFileName, ".") == 0 || strcmp(ffData.cFileName, "..") == 0){
FindNextFile(hFind,&ffData);
}
FindNextFile(hFind,&ffData);
n++;
}
}
else
SetDlgItemText(Hwnd,TEST2,"change directory failure");
}
else
SetDlgItemText(Hwnd,TEST2,"unkown ERROR");
}
}
FindClose(hFind);
}