*
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
#ifndef IZIPSTREAM_H__
|
||||
#define IZIPSTREAM_H__
|
||||
|
||||
#include "../../IDataStream.h"
|
||||
#include "../../LString.h"
|
||||
#include <assert.h>
|
||||
#include "../../minizip/unzip.h"
|
||||
#include "../../minizip/zip.h"
|
||||
|
||||
namespace LifeCore
|
||||
{
|
||||
class IZipStream : public IDataStream
|
||||
{
|
||||
private:
|
||||
size_t stmLength;
|
||||
unzFile source;
|
||||
zipFile dest;
|
||||
zip_fileinfo destInfo;
|
||||
unz_file_info fileInfo;
|
||||
int openMode;
|
||||
public:
|
||||
~IZipStream(){}
|
||||
void Close()
|
||||
{
|
||||
if(openMode == FA_READ)
|
||||
{
|
||||
if(source)
|
||||
{
|
||||
unzCloseCurrentFile(source);
|
||||
unzClose(source);
|
||||
}
|
||||
}
|
||||
else //write
|
||||
{
|
||||
if(dest)
|
||||
{
|
||||
zipCloseFileInZip(dest);
|
||||
zipClose(dest, "ONOTOLE NEGODUE");
|
||||
}
|
||||
}
|
||||
openMode = 0;
|
||||
}
|
||||
IZipStream(unzFile& file, String& entry, int fileAccessMode, const String& archivePath)
|
||||
{
|
||||
source = file;
|
||||
openMode = fileAccessMode;
|
||||
if (fileAccessMode == FA_READ)
|
||||
{
|
||||
tchar fileName[256] = {0};
|
||||
unzLocateFile(file, entry.c_str(), 1);
|
||||
unzGetCurrentFileInfo(file,&fileInfo,fileName,256,NULL,0,NULL, 0);
|
||||
stmLength = fileInfo.uncompressed_size;
|
||||
unzOpenCurrentFile(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
dest = zipOpen(archivePath.c_str(), 2);
|
||||
destInfo.tmz_date.tm_sec = destInfo.tmz_date.tm_min = destInfo.tmz_date.tm_hour =
|
||||
destInfo.tmz_date.tm_mday = destInfo.tmz_date.tm_mon = destInfo.tmz_date.tm_year = 0;
|
||||
destInfo.dosDate = 0;
|
||||
destInfo.internal_fa = 0;
|
||||
destInfo.external_fa = 0;
|
||||
|
||||
#ifdef _UNICODE
|
||||
char tmp[64] = {0};
|
||||
wcstombs(tmp,entry.c_str(),entry.length());
|
||||
zipOpenNewFileInZip(dest, tmp,&destInfo,NULL,0,NULL, 0, NULL, 0, 0);
|
||||
#else
|
||||
zipOpenNewFileInZip(dest, entry.c_str(),&destInfo,NULL,0,NULL, 0, NULL, 0, 0);
|
||||
#endif
|
||||
}
|
||||
//g_openMode = mode;
|
||||
}
|
||||
size_t Read(void* pBuffer, size_t countBytes)
|
||||
{
|
||||
return unzReadCurrentFile(source, pBuffer, countBytes);
|
||||
}
|
||||
size_t Write(const void* pBuffer, size_t countBytes)
|
||||
{
|
||||
zipWriteInFileInZip(dest, pBuffer,countBytes);
|
||||
return countBytes;
|
||||
}
|
||||
void Seek(size_t position)
|
||||
{
|
||||
printf("100500&%i\n", position);
|
||||
printf("Unimplemented SEEK operation in IZipStream");
|
||||
}
|
||||
size_t Tell()
|
||||
{
|
||||
printf("Unimplemented TELL operation in IZipStream");
|
||||
return 0;
|
||||
}
|
||||
size_t Length()
|
||||
{
|
||||
return stmLength;
|
||||
}
|
||||
bool CanRead()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool CanWrite()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user