static void del_alldatefile(char diskno,char *date)
{
	WIN32_FIND_DATA filedata;
	HANDLE filehandle;
	char lpDir[MAX_PATH];
	char lpFileName[MAX_PATH];
	
	sprintf(lpDir,"%c:\\%s\\*.*",diskno,date);

	filehandle = FindFirstFile(lpDir,&filedata);
	if(filehandle == INVALID_HANDLE_VALUE)
	{
		sprintf(lpDir,"%c:\\%s",diskno,date);
		RemoveDirectory(lpDir);
		return;
	}
	sprintf(lpDir,"%c:\\%s\\",diskno,date);
	do
	{
		sprintf(lpFileName,"%s\\%s",lpDir,filedata.cFileName);
		DeleteFile(lpFileName);
	}while(FindNextFile(filehandle,&filedata));
	FindClose(filehandle);

	sprintf(lpDir,"%c:\\%s",diskno,date);
	RemoveDirectory(lpDir);
}
////////////////////////////////////////////////////////////////////
static BOOL __inline CheckIsDirIsMe(char *szDir)
{
	int i;
	if(strlen(szDir) != 8) return FALSE;
	for(i=0;i<8;i++)
	{
		if( !isdigit(szDir[i]))
			return FALSE;
	}
	return TRUE;
/*
	if((!isdigit(szDir[0])) || (!isdigit(szDir[1]))
		||(!isdigit(szDir[2])) || (!isdigit(szDir[3])))
		return FALSE;
	if(szDir[4]!='_')
		return FALSE;
	if((!isdigit(szDir[5])) || (!isdigit(szDir[6])))
		return FALSE;
	if(szDir[7]!='_')
		return FALSE;
	if((!isdigit(szDir[8])) || (!isdigit(szDir[9])))
		return FALSE;
	return TRUE;
*/
}
////////////////////////////////////////////////////////////////////
static void finddevOldestDate(char diskno,char *lpOldDate)
{
	WIN32_FIND_DATA filedata;
	HANDLE filehandle;
	char lpDir[10];

	sprintf(lpOldDate,"%04d%02d%02d",9999,99,99);
	
	sprintf(lpDir,"%c:\\*.*",diskno);

	filehandle = FindFirstFile(lpDir,&filedata);
	if(filehandle == INVALID_HANDLE_VALUE) return;
	//sprintf(lpDir,"%c:\\",diskno);
	do
	{
		if((filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			&&( strcmp(filedata.cFileName,".")  != 0)
			&&( strcmp(filedata.cFileName,"..") != 0)
			&& (CheckIsDirIsMe(filedata.cFileName)))
		{
			if(strncmp(filedata.cFileName,lpOldDate,8) < 0)
			{
				strcpy(lpOldDate,filedata.cFileName);
			}
		}
	}while(FindNextFile(filehandle,&filedata));
	FindClose(filehandle);
}
////////////////////////////////////////////////////////////////////
/*
* 找出最早一天文件的日期
*/
static void findolddate(DISK_ADMIN *pDiskAdmin,char *lpOldDate)
{
	int i;
	char lpTempDate[MAX_PATH];
	char lpFileDate[MAX_PATH];
	lpOldDate[0]= '\0';

	sprintf(lpTempDate,"%04d%02d%02d",9999,99,99);
	sprintf(lpFileDate,"%04d%02d%02d",9999,99,99);
	for(i=0;i<pDiskAdmin->totaldevs;i++)
	{
		finddevOldestDate(pDiskAdmin->devlist[i],lpTempDate);
		if(strncmp(lpTempDate,lpFileDate,8) < 0)
		{
			strcpy(lpFileDate,lpTempDate);
		}
	}
	strcpy(lpOldDate,lpFileDate);
}
////////////////////////////////////////////////////////////////////
static void delete_file(DISK_ADMIN *pDiskAdmin)
{
	int i;
	char lpOldDate[MAX_PATH];

	findolddate(pDiskAdmin,lpOldDate);
	
	for(i=0;i<pDiskAdmin->totaldevs;i++)
	{
		del_alldatefile(pDiskAdmin->devlist[i],lpOldDate);
	}
}
////////////////////////////////////////////////////////////////////
static DWORD CALLBACK s_thread_overlaydisk(DISK_ADMIN *pDiskAdmin)
{
	delete_file(pDiskAdmin);
	return 0;
}

void CNetViewXCtrl::findfile_indev(char devn,DISK_SEARCHINFO *pInfo)
{
	char lpDir[MAX_PATH];
	char lpFileDate[MAX_PATH];
	char date[20];

	WIN32_FIND_DATA filedata;
	HANDLE filehandle = INVALID_HANDLE_VALUE;

	sprintf(date,"%04d%02d%02d",pInfo->year,pInfo->month,pInfo->day);

	sprintf(lpDir,"%c:\\*.*",devn);
	filehandle = FindFirstFile(lpDir,&filedata);

	if(filehandle == INVALID_HANDLE_VALUE) return;
	sprintf(lpDir,"%c:\\",devn);
	do
	{
		if((filedata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			&&( strcmp(filedata.cFileName,".")  != 0)
			&&( strcmp(filedata.cFileName,"..") != 0)
			&& (CheckIsDirIsMe(filedata.cFileName)) )
		{
			if(strncmp(filedata.cFileName,date,8) == 0)
			{
				sprintf(lpFileDate,"%s\\%s",lpDir,filedata.cFileName);

				findfile_indir(lpFileDate,filedata.cFileName,
					pInfo);
			}
		}
	}while(FindNextFile(filehandle,&filedata));
	FindClose(filehandle);
}

void CNetViewXCtrl::findfile_indir(char *dir,char *pDate,DISK_SEARCHINFO *pInfo)
{
	int curtime,stime,etime;
	FILE *fpIndex = NULL;
	char lpDate[20],filetime[20];
	char lpFileName[MAX_PATH];
	char lpindex[MAX_PATH];
	FLATFISH_RECINDEX pIndexItem;
	struct _stat  pstat;

	sprintf(lpindex,"%s\\index",dir);
	fpIndex = fopen(lpindex,"rb");
	if(fpIndex == NULL) return;

	stime = pInfo->hours * 100 + pInfo->minutes;
	etime = pInfo->hourd * 100 + pInfo->minuted;
	for(;;)
	{
		if(fread(&pIndexItem,sizeof(FLATFISH_RECINDEX),1,fpIndex) != 1)
			break;
		curtime = pIndexItem.hour * 100 + pIndexItem.minute;
		if(curtime >= stime && curtime <= etime)
		{
			if(m_recordtype == 0)
			{
#ifdef USER_CUSTOMFILENAME
                sprintf(lpFileName,"%s\\\\%s",
					dir,
					pIndexItem.filename);
#else

				sprintf(lpFileName,"%s\\\\%s_%d_%02d%02d%02d.asf",
					dir,
					pIndexItem.sername,pIndexItem.ch+1,
					pIndexItem.hour,pIndexItem.minute,pIndexItem.second);
#endif
			}
			else
			{
#ifdef USER_CUSTOMFILENAME
                sprintf(lpFileName,"%s\\\\%s",
					dir,
					pIndexItem.filename);
#else
/*
#ifdef MP4_FILEEXPAND
				sprintf(lpFileName,"%s\\\\%s_%d_%02d%02d%02d.%s",
					dir,
					pIndexItem.sername,pIndexItem.ch+1,
					pIndexItem.hour,pIndexItem.minute,pIndexItem.second,
                    MP4_FILEEXPAND);
#else
				sprintf(lpFileName,"%s\\\\%s_%d_%02d%02d%02d.mp4",
					dir,
					pIndexItem.sername,pIndexItem.ch+1,
					pIndexItem.hour,pIndexItem.minute,pIndexItem.second);
#endif*/
				//改为可以同时检索MP4和264类型文件
				sprintf(lpFileName,"%s\\\\%s_%d_%02d%02d%02d.%s",
					dir,
					pIndexItem.sername,pIndexItem.ch+1,
					pIndexItem.hour,pIndexItem.minute,pIndexItem.second,
                    "MP4");
				if((_stat(lpFileName,&pstat) != 0))
				{
					sprintf(lpFileName,"%s\\\\%s_%d_%02d%02d%02d.%s",
						dir,
						pIndexItem.sername,pIndexItem.ch+1,
						pIndexItem.hour,pIndexItem.minute,pIndexItem.second,
						"264");
				}
#endif
			}
			if((_stat(lpFileName,&pstat) != 0)) continue;

			if(pDate)
            {
                lpDate[0] = pDate[0];
			    lpDate[1] = pDate[1];
			    lpDate[2] = pDate[2];
			    lpDate[3] = pDate[3];
			    lpDate[4] = '-';
			    lpDate[5] = pDate[4];
			    lpDate[6] = pDate[5];
			    lpDate[7] = '-';
			    lpDate[8] = pDate[6];
			    lpDate[9] = pDate[7];
			    lpDate[10]= '\0';
            }
            else
            {
                sprintf(lpDate,"%04d-%02d-%02d",pIndexItem.year,pIndexItem.month,pIndexItem.day);
            }

			sprintf(filetime,"%02d:%02d:%02d",
				pIndexItem.hour,pIndexItem.minute,pIndexItem.second);
			FireSearchRet(pIndexItem.sername,lpDate,
				filetime,(pstat.st_size)>>10,lpFileName);
			//pcallback(pIndexItem.url,pIndexItem.ch,
			//	lpDate,filetime,(pstat.st_size)>>10,lpFileName);
		}
	}
	if(fpIndex) fclose(fpIndex);
}
