bool cFileCtrl::parseBinFile()
{
FILE * sm= NULL;
if(NULL == (sm = fopen("packUI","w+r")))
{
CreateFile("packUI",0,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL);
fwrite("",sizeof(char),0,sm);
}
fclose(sm);
FILE * uifile = NULL;
char workPath[256];
GetCurrentDirectory( 256, workPath);
sprintf( workPath, "%s%s", workPath, "//packUI");
if( (uifile = fopen( workPath, "r+b" )) == NULL )
printf( "The file packUI was not opened/n");
else
{
fseek(uifile,0L,SEEK_END);
}
ifstream binfile("packUI.bin",ios::binary);
if (binfile.rdbuf() == NULL)
{
printf( "The file packUI.bin was not opened/n");
return false;
}
else
{
binfile.seekg(0,ios::end);//流结束地址值
long length = binfile.tellg();
char* allc = (char*)malloc(length+1);
memset(allc, 0, length+1);
binfile.seekg(0,ios::beg);//流开始地址值
int tt = 0;
char* p = allc;
while(!binfile.eof())
{
char buf[128];
ZeroMemory( buf, 128);
binfile.read(buf,128);
tt = binfile.gcount();
memcpy(p, buf, tt);
p += tt;
}
fwrite( allc, sizeof(byte), length, uifile);
free(allc);
}
fclose(uifile);
return true;
}