// MakePhotoLog.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#pragma pack(1)
typedef struct __tag_file_info
{
DWORD length; //文件长度
DWORD crc32; //暂未使用
char name[38];//文件名
char res[4];
} file_info; //Total = 50
#pragma pack()
long GetLocalFileSize(const char* szFileName)
{
struct stat f_stat;
if (stat(szFileName, &f_stat) == -1) {
return -1;
}
return (long)f_stat.st_size;
}
BOOL IsDirectory(CString strPath)
{
WIN32_FIND_DATA wfd;
HANDLE hFind = FindFirstFile(strPath, &wfd);
BOOL bRet = ((hFind!=INVALID_HANDLE_VALUE) && (wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY));
FindClose(hFind);
return bRet;
}
int main(int argc, char *argv[])
{
WIN32_FIND_DATA wfd;
HANDLE hFind;
CString strPath;
CString strFileName;
CString strFind;
CString strJpgFile;
if (argc<2)
{
printf("Usage:%s <photo-log path>\r\n",argv[0]);
return -1;
}
strPath = argv[1];
if (!IsDirectory(strPath))
{
printf("\"%s\" not found\r\n",argv[1]);
return -1;
}
PathAddBackslash(strPath.GetBuffer(strPath.GetLength()+2));
strPath.ReleaseBuffer();
strFileName = strPath;
strFileName += "photo_log.dat";
FILE* fp = fopen("photo_log.dat","w+b");
if (fp==NULL)
{
printf("open \"%s\" error \r\n",(LPCTSTR)strFileName);
return -1;
}
strFind = strPath + "*.jpg";
hFind = FindFirstFile(strFind, &wfd);
if (hFind == INVALID_HANDLE_VALUE)
{
printf ("Invalid File Handle. GetLastError reports %d\n", GetLastError ());
return -1;
}
BOOL bRet = TRUE;
file_info fi;
int nSucced = 0;
while(bRet)
{
strJpgFile = strPath + wfd.cFileName;
if (strlen(wfd.cFileName)>32)
{
continue;
}
memset(&fi,0,sizeof(fi));
fi.length = wfd.nFileSizeLow;
strcpy(fi.name,wfd.cFileName);
if (fwrite(&fi,1,sizeof(fi),fp) == sizeof(fi))
{
nSucced++;
printf("%d. make photo-log(%s) succed\r\n", nSucced,(LPCTSTR)strJpgFile );
}
else{
printf("make photo-log(%s) failed\r\n", (LPCTSTR)strJpgFile );
break;
}
bRet = FindNextFile(hFind,&wfd);
}
printf("make photo-log(%d) succed\r\n",nSucced);
FindClose(hFind);
if (fp!=NULL)
{
fclose(fp);
}
return 0;
}