Здравствуйте, я попробывал код
Packer.cpp
#include "StdAfx.h"
#include "Packer.h"
#include "zip.h"
#include "unzip.h"
#include <sys/stat.h>
#include <time.h>
#include "zlib.h"
#pragma comment(lib, "zlib.lib")
#define READ_BUFFER_SIZE 65535
BOOL CPacker::Pack(std::vector<std::string>& _files, const char* _zipName)
{
BOOL result = false;
if ( 0 == _files.size())
return result;
STR_VEC::const_iterator Iter = _files.begin();
zipFile zipfile = zipOpen(_zipName, 0);
if (zipfile != NULL)
{
while (Iter != _files.end())
{
result = false;
const char* srcFullFileName = Iter->c_str();
const char* p = strrchr(srcFullFileName, '\\');
const char* srcFileName = (NULL == p) ? srcFullFileName : p + 1;
char read_buf[READ_BUFFER_SIZE];
FILE* file = fopen(srcFullFileName, "rb");
if (file != NULL)
{
zip_fileinfo zfileinfo = {0};
struct _stat file_stat = {0};
_fstat(_fileno(file), &file_stat);
struct tm* file_time = localtime(&file_stat.st_mtime);
tm_zip* zip_time = &zfileinfo.tmz_date;
memcpy(zip_time, file_time, sizeof(tm_zip));
int compression = Z_BEST_COMPRESSION;
if ( ZIP_OK == zipOpenNewFileInZip(zipfile, srcFileName,
&zfileinfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, compression))
{
while(!feof(file))
{
result = false;
size_t count = fread( read_buf, sizeof(char), READ_BUFFER_SIZE, file );
if(!ferror(file))
{
if ( ZIP_OK == zipWriteInFileInZip(zipfile, read_buf, count))
{
result = true;
continue;
}
else
break;
}else
break;
}
result = result && (Z_OK == zipCloseFileInZip(zipfile));
}
result = result && (0 == fclose(file));
}
(result) ? Iter++ : Iter = _files.end();
}
result = result && (Z_OK == zipClose(zipfile, NULL));
}
return result;
}
BOOL CPacker::Unpack(const char* _zipName, const char* _dstFolder)
{
BOOL result = FALSE;
unzFile zipFile = unzOpen(_zipName);
if (NULL != zipFile)
{
if (UNZ_OK == unzGoToFirstFile(zipFile))
{
BOOL bContinue = TRUE;
while (bContinue)
{
result = FALSE;
unz_file_info fi;
char filename[MAX_PATH] = {0};
if (UNZ_OK == unzGetCurrentFileInfo(zipFile, &fi,
filename, sizeof(filename), 0, 0, 0, 0))
{
if (UNZ_OK == unzOpenCurrentFile(zipFile))
{
UINT dataLen = fi.uncompressed_size;
BYTE* fileData = new BYTE[dataLen];
if (!fileData)
break;
if(dataLen == unzReadCurrentFile(zipFile, fileData, dataLen))
{
char filePathName[MAX_PATH] = {0};
strcat(filePathName, _dstFolder);
strcat(filePathName, "\\");
strcat(filePathName, filename);
FILE* pFile = fopen(filePathName, "wb");
if (pFile)
{
result = (dataLen == fwrite(fileData, 1, dataLen, pFile));
result = result && (0 == fclose(pFile));
}
}
delete [] fileData;
}
result = result && (UNZ_OK == unzCloseCurrentFile(zipFile));
}
if (!result)
break;
if (UNZ_END_OF_LIST_OF_FILE == unzGoToNextFile(zipFile))
bContinue = FALSE;
}
}
result = result && (UNZ_OK == unzClose(zipFile));
}
return result;
}
#pragma once
#include <vector>
#include <string>
typedef std::vector<std::string> STR_VEC;
struct CPacker
{
//заархивировать файлы
BOOL Pack(STR_VEC& _files, const char* _zipName);
//разархивировать
BOOL Unpack(const char* _zipName, const char* _dstFolder);
};
myProject.cpp
#include "stdafx.h"
#include "myFirstProject.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
}
char* a = "myPrint";
myDecode(a);
return nRetCode;
}
myProject.h
#pragma once
#include "resource.h";
#include "stdio.h";
#include "stdlib.h";
#include "conio.h";
#include "Packer.h";
void myDecode(char* a){
printf("hello");
std::cout<<"Hello World\n"<<a;
CPacker *myPack = new CPacker();
myPack->Unpack("1.zip","1");
_getch();
}
и у меня выдает ошибку
1>Packer.obj : error LNK2019: unresolved external symbol _zipClose referenced in function "public: int __thiscall CPacker::Pack(class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &,char const *)" (?Pack@CPacker@@QAEHAAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@PBD@Z)
1>Packer.obj : error LNK2019: unresolved external symbol _zipCloseFileInZip referenced in function "public: int __thiscall CPacker::Pack(class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &,char const *)" (?Pack@CPacker@@QAEHAAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@PBD@Z)
1>Packer.obj : error LNK2019: unresolved external symbol _zipWriteInFileInZip referenced in function "public: int __thiscall CPacker::Pack(class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &,char const *)" (?Pack@CPacker@@QAEHAAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@PBD@Z)
1>Packer.obj : error LNK2019: unresolved external symbol _zipOpenNewFileInZip referenced in function "public: int __thiscall CPacker::Pack(class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &,char const *)" (?Pack@CPacker@@QAEHAAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@PBD@Z)
1>Packer.obj : error LNK2019: unresolved external symbol _zipOpen referenced in function "public: int __thiscall CPacker::Pack(class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > &,char const *)" (?Pack@CPacker@@QAEHAAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@PBD@Z)
1>Packer.obj : error LNK2019: unresolved external symbol _unzClose referenced in function "public: int __thiscall CPacker::Unpack(char const *,char const *)" (?Unpack@CPacker@@QAEHPBD0@Z)
1>Packer.obj : error LNK2019: unresolved external symbol _unzGoToNextFile referenced in function "public: int __thiscall CPacker::Unpack(char const *,char const *)" (?Unpack@CPacker@@QAEHPBD0@Z)
1>Packer.obj : error LNK2019: unresolved external symbol _unzCloseCurrentFile referenced in function "public: int __thiscall CPacker::Unpack(char const *,char const *)" (?Unpack@CPacker@@QAEHPBD0@Z)
1>Packer.obj : error LNK2019: unresolved external symbol _unzReadCurrentFile referenced in function "public: int __thiscall CPacker::Unpack(char const *,char const *)" (?Unpack@CPacker@@QAEHPBD0@Z)
1>Packer.obj : error LNK2019: unresolved external symbol _unzOpenCurrentFile referenced in function "public: int __thiscall CPacker::Unpack(char const *,char const *)" (?Unpack@CPacker@@QAEHPBD0@Z)
1>Packer.obj : error LNK2019: unresolved external symbol _unzGetCurrentFileInfo referenced in function "public: int __thiscall CPacker::Unpack(char const *,char const *)" (?Unpack@CPacker@@QAEHPBD0@Z)
1>Packer.obj : error LNK2019: unresolved external symbol _unzGoToFirstFile referenced in function "public: int __thiscall CPacker::Unpack(char const *,char const *)" (?Unpack@CPacker@@QAEHPBD0@Z)
1>Packer.obj : error LNK2019: unresolved external symbol _unzOpen referenced in function "public: int __thiscall CPacker::Unpack(char const *,char const *)" (?Unpack@CPacker@@QAEHPBD0@Z)
1>C:\Documents and Settings\Marica\Мои документы\Visual Studio 2008\Projects\myFirstProject\Debug\myFirstProject.exe : fatal error LNK1120: 13 unresolved externals
что мне нужно подправить чтобы исправить? чтобы можно было распаковать
11.09.08 19:15: Перенесено модератором из 'Исходники' — Odi$$ey