将文件解压缩到我指定的目录中 [英] Unzip a file into a directory I specified
问题描述
这是我尝试过的,但它不起作用:
ZRESULT TUnzip :: Open( void * z, unsigned int len,DWORD flags)
{
if (uf!= 0 || currentfile!= - 1 )
return ZR_NOTINITED;
GetCurrentDirectory(MAX_PATH,rootdir);
_tcscat(rootdir,_T( \\ temp)); // 添加临时目录,但无法正常工作
_tcscat(rootdir,_T( \\);
if (flags == ZIP_HANDLE)
{
DWORD type = GetFileType(z);
if ( type!= FILE_TYPE_DISK)
return ZR_SEEK;
}
ZRESULT e;
LUFILE * f = lufopen(z, len,flags,& e);
if (f == NULL)
return e;
uf = unzOpenInternal(f);
// 返回ZR_OK;
return zopenerror; // +++ 1.2
}
This is what I tried, but it is not working: 这篇关于将文件解压缩到我指定的目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
GetFolderPath 你得到了正确的。
请记住:出于安全原因你不能到处写...
ZRESULT TUnzip::Open(void *z,unsigned int len,DWORD flags)
{
if (uf!=0 || currentfile!=-1)
return ZR_NOTINITED;
GetCurrentDirectory(MAX_PATH,rootdir);
_tcscat(rootdir,_T("\\temp")); //add temp dir, but can not work
_tcscat(rootdir,_T("\\");
if (flags==ZIP_HANDLE)
{
DWORD type = GetFileType(z);
if (type!=FILE_TYPE_DISK)
return ZR_SEEK;
}
ZRESULT e;
LUFILE *f = lufopen(z,len,flags,&e);
if (f==NULL)
return e;
uf = unzOpenInternal(f);
//return ZR_OK;
return zopenerror; //+++1.2
}
you need to specify a full path.
With GetFolderPath you get the right one.
Remember: you cant write everywhere for security reasons...