【问题标题】:Unzip with zlib without using SetCurrentDirectory在不使用 SetCurrentDirectory 的情况下使用 zlib 解压缩
【发布时间】:2013-03-04 03:29:24
【问题描述】:

我正在使用zlib 解压缩 zip 文件的列表。这是简单的方法。但是SetCurrentDirectory 函数调用会影响我的其他线程。有没有办法使用 zlib 解压到特定目录。

SetCurrentDirectory("c:\\docs\\stuff");
HZIP hz = OpenZip("c:\\stuff.zip",0);
ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index;
for (int i=0; i<numitems; i++)
{ GetZipItem(hz,i,&ze);
   UnzipItem(hz,i,ze.name);
 }
 CloseZip(hz);

【问题讨论】:

标签: c++ zip


【解决方案1】:

您所拥有的是一个包装器,可以轻松使用 zlib 库。您已将问题标记为 C++,您正在使用 C++ 的包装器,同时您正在使用利用此包装器的全局帮助器 API。

我建议您直接使用 TUnzip 包装器(以 UnzipItemInternal 的实现为例)。 TUnzip 类有一个很好的方法允许设置基目录ZRESULT TUnzip::SetUnzipBaseDir(const TCHAR *dir)。调用它来设置目录

【讨论】:

  • 其实我不知道这不是 zlib。但我无法更改库,因为我正在对现有项目进行一些更改。无论如何,它帮助您的 cmets 找到了答案。谢谢。
【解决方案2】:

找到了解决办法。

void unZipPackage(std::wstring zip_file,std::wstring dest_dir){ 

    HZIP hz = OpenZip(zip_file.c_str(),0);  
    ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index;
    for (int i=0; i<numitems; i++)
    { 
        GetZipItem(hz,i,&ze);               
        wchar_t dest[MAX_PATH];
        swprintf(dest,MAX_PATH,L"%s\\%s",dest_dir.c_str(),ze.name);     
        UnzipItem(hz,i,dest);       
    }   
    CloseZip(hz);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    相关资源
    最近更新 更多