|
@@ -7,13 +7,15 @@ bool CreateZipFromFile(string srcFileName, string zipFileName)
|
|
|
{
|
|
|
if (srcFileName.empty() || srcFileName.length() == 0 ||
|
|
|
zipFileName.empty() || zipFileName.length() == 0) {
|
|
|
- Dbg("压缩文件参数为空:");
|
|
|
+ //Dbg("压缩文件参数为空:");
|
|
|
+ Dbg("XZipZilb zip param is null");
|
|
|
return false;
|
|
|
}
|
|
|
int pos = srcFileName.find_last_of(SPLIT_SLASH);
|
|
|
|
|
|
if (pos < 0) {
|
|
|
- Dbg("文件路径不对:%s",srcFileName.c_str());
|
|
|
+ //Dbg("文件路径不对:%s",srcFileName.c_str());
|
|
|
+ Dbg("XZipZilb srcFileName path format is error:%s", srcFileName.c_str());
|
|
|
return false;
|
|
|
}
|
|
|
string strName(srcFileName.substr(pos + 1));
|
|
@@ -25,24 +27,28 @@ bool CreateZipFromFile(string srcFileName, string zipFileName)
|
|
|
zipFile newZipFile = zipOpen(zipFileName.c_str(), APPEND_STATUS_CREATE); //创建zip文件
|
|
|
if (newZipFile == NULL)
|
|
|
{
|
|
|
- Dbg("无法创建zip文件!");
|
|
|
+ //Dbg("无法创建zip文件!");
|
|
|
+ Dbg("XZipZilb can't create zip file: %s", zipFileName.c_str());
|
|
|
return false;
|
|
|
}
|
|
|
//压缩文件
|
|
|
if (!AddFileToZip(newZipFile, strName.c_str(), srcFileName.c_str()))
|
|
|
{
|
|
|
- Dbg("压缩失败: %s",zipFileName.c_str());
|
|
|
+ //Dbg("压缩失败: %s",zipFileName.c_str());
|
|
|
+ Dbg("XZipZilb zip fail: %s", zipFileName.c_str());
|
|
|
zipClose(newZipFile, NULL);
|
|
|
if (ExistsFileA(zipFileName.c_str())) {
|
|
|
if (remove(zipFileName.c_str()) != 0) {
|
|
|
- Dbg("删除临时压缩文件失败");
|
|
|
+ //Dbg("删除临时压缩文件失败");
|
|
|
+ Dbg("XZipZilb delete temp zip file is error");
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
//释放文件
|
|
|
zipClose(newZipFile, NULL);
|
|
|
- Dbg("压缩成功: %s", zipFileName.c_str());
|
|
|
+ //Dbg("压缩成功: %s", zipFileName.c_str());
|
|
|
+ Dbg("XZipZilb zip succ: %s", zipFileName.c_str());
|
|
|
return true;
|
|
|
|
|
|
}
|
|
@@ -74,10 +80,12 @@ bool AddFileToZip(zipFile zf, const char* fileNameInZip, const char* srcFile)
|
|
|
if (ret != ZIP_OK)
|
|
|
{
|
|
|
if (srcFile != NULL) {
|
|
|
- Dbg("在zip文件中创建新文件失败: %s", srcFile);
|
|
|
+ //Dbg("在zip文件中创建新文件失败: %s", srcFile);
|
|
|
+ Dbg("XZipZilb create file in zip fail: %s", srcFile);
|
|
|
}
|
|
|
else {
|
|
|
- Dbg("在zip文件中创建新目录失败: %s", new_file_name);
|
|
|
+ //Dbg("在zip文件中创建新目录失败: %s", new_file_name);
|
|
|
+ Dbg("XZipZilb create dir in zip fail: %s", new_file_name);
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
@@ -88,7 +96,8 @@ bool AddFileToZip(zipFile zf, const char* fileNameInZip, const char* srcFile)
|
|
|
srcfp = fopen(srcFile, "rb+");
|
|
|
if (srcfp == NULL)
|
|
|
{
|
|
|
- Dbg("打开要往zip压缩的文件失败: %s", srcFile);
|
|
|
+ //Dbg("打开要往zip压缩的文件失败: %s", srcFile);
|
|
|
+ Dbg("XZipZilb open src file to zip is fail: %s", srcFile);
|
|
|
zipCloseFileInZip(zf); //关闭zip中的新文件
|
|
|
return false;
|
|
|
}
|
|
@@ -113,7 +122,8 @@ bool AddFileToZip(zipFile zf, const char* fileNameInZip, const char* srcFile)
|
|
|
|
|
|
|
|
|
if (sumWrite != fileLen) {
|
|
|
- Dbg("文件写入zip压缩包失败,总长度不一致: %s", srcFile);
|
|
|
+ //Dbg("文件写入zip压缩包失败,总长度不一致: %s", srcFile);
|
|
|
+ Dbg("XZipZilb write to zip file is error ,sumWrite is not equal to fileLen, %s", srcFile);
|
|
|
fclose(srcfp);
|
|
|
zipCloseFileInZip(zf);
|
|
|
return false;//写文件失败
|