#include <common/finddata.hpp>

void FindData::destroyFind(void)
{							
	if(INVALID_HANDLE_VALUE==mhFindHandle)return;
	::FindClose(mhFindHandle);
	mhFindHandle=INVALID_HANDLE_VALUE;
}

WORD FindData::findFirst(const String &searchFileName,DWORD searchAttributes)
{
	destroyFind();
	zeroInit();
	if(searchFileName.isNull())return FALSE;
	fileName(searchFileName);
	attributes(searchAttributes);
	if(INVALID_HANDLE_VALUE==(mhFindHandle=::FindFirstFile((LPSTR)searchFileName,&((WIN32_FIND_DATA&)*this))))return FALSE;
	return TRUE;
}

void FindData::altFileName(String altFileName)
{
	WORD nameLength(altFileName.length());

	if(altFileName.isNull())return;
	if(nameLength>=sizeof(WIN32_FIND_DATA::cAlternateFileName))altFileName.length(sizeof(WIN32_FIND_DATA::cAlternateFileName)-1);
	::strcpy(WIN32_FIND_DATA::cAlternateFileName,(LPSTR)altFileName);
}

FindData &FindData::operator=(const FindData &someFindData)
{
	attributes(someFindData.attributes());
	creationTime(someFindData.creationTime());
	lastAccessTime(someFindData.lastAccessTime());
	lastModifyTime(someFindData.lastModifyTime());
	sizeHigh(someFindData.sizeHigh());
	sizeLow(someFindData.sizeLow());
	fileName(someFindData.fileName());
	altFileName(someFindData.altFileName());
	return *this;
}

WORD FindData::operator==(const FindData &someFindData)const
{
	return (attributes()==someFindData.attributes()&&
					creationTime()==someFindData.creationTime()&&
					lastAccessTime()==someFindData.lastAccessTime()&&
					sizeHigh()==someFindData.sizeHigh()&&
					fileName()==someFindData.fileName()&&
					altFileName()==someFindData.altFileName());
}




