82 struct tar_header header;
86 int getoct(
char *p,
int width) {
92 if (c ==
' ')
continue;
94 result = result * 8 + (c -
'0');
100 int untar(
gzFile in,
const char *dest) {
113 sword::SWLog::getSystemLog()->logError(gzerror(in, &err));
119 sword::SWLog::getSystemLog()->logError(
"gzread: incomplete block read");
124 if (getheader == 1) {
130 if ((len == 0) || (
buffer.header.name[0]== 0))
break;
132 tartime = (time_t)getoct(
buffer.header.mtime,12);
134 if (!fname.endsWith(
"/") && !fname.endsWith(
"\\")) fname +=
'/';
135 fname +=
buffer.header.name;
137 switch (
buffer.header.typeflag) {
139 sword::SWBuf dummyFile = fname +
"dummyFile";
140 sword::FileMgr::createParent(dummyFile);
145 remaining = getoct(
buffer.header.size,12);
147 outFD = sword::FileMgr::createPathAndFile(fname);
151 sword::FileMgr::closeFile(outFD);
158 getheader = (remaining) ? 0 : 1;
168 if (sword::FileMgr::write(outFD, &
buffer,
sizeof(
char)*bytes) != (
int) bytes) {
169 sword::SWLog::getSystemLog()->logError(
"error writing %s skipping...", fname.c_str());
170 sword::FileMgr::closeFile(outFD);
171 sword::FileMgr::removeFile(fname);
175 if (remaining == 0) {
181 sword::FileMgr::closeFile(outFD);
184 FILETIME ftm,ftLocal;
188 localt = *localtime(&tartime);
190 hFile = CreateFileW((
const wchar_t *)
sword::utf8ToWChar(fname).getRawData(), GENERIC_READ | GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, 0,
NULL);
192 st.wYear = (WORD)localt.tm_year+1900;
193 st.wMonth = (WORD)localt.tm_mon;
194 st.wDayOfWeek = (WORD)localt.tm_wday;
195 st.wDay = (WORD)localt.tm_mday;
196 st.wHour = (WORD)localt.tm_hour;
197 st.wMinute = (WORD)localt.tm_min;
198 st.wSecond = (WORD)localt.tm_sec;
199 st.wMilliseconds = 0;
200 SystemTimeToFileTime(&st,&ftLocal);
201 LocalFileTimeToFileTime(&ftLocal,&ftm);
202 SetFileTime(hFile,&ftm,
NULL,&ftm);
205 struct utimbuf settime;
206 settime.actime = settime.modtime = tartime;
207 utime(fname.c_str(), &settime);
273 char *
buf = (
char *)calloc(1, 1024);
274 char *chunkbuf =
buf;
275 unsigned long chunklen;
276 unsigned long len = 0;
277 while((chunklen =
getChars(chunk, 1023))) {
278 memcpy(chunkbuf, chunk, chunklen);
282 else buf = (
char *)
realloc(buf, len + 1024);
287 zlen = (long) (len*1.001)+15;
337 char *
zbuf = (
char *)calloc(1, 1024);
338 char *chunkbuf =
zbuf;
340 unsigned long zlen = 0;
341 while((chunklen = (
int)
getChars(chunk, 1023))) {
342 memcpy(chunkbuf, chunk, chunklen);
346 else zbuf = (
char *)
realloc(zbuf, zlen + 1024);
347 chunkbuf = zbuf +
zlen;
352 unsigned long blen = zlen*20;
353 char *
buf =
new char[blen];
356 switch (uncompress((
Bytef*)buf, &blen, (
Bytef*)zbuf, zlen)){
376 f = gzdopen(fd,
"rb");
382 return untar(f, destPath);
static char unTarGZ(int fd, const char *destPath)
#define SWORD_NAMESPACE_START
static SWLog * getSystemLog()
virtual void encode(void)
SWBuf utf8ToWChar(const char *buf)
virtual void decode(void)
virtual unsigned long getChars(char *buf, unsigned long len)
void logError(const char *fmt,...) const
#define SWORD_NAMESPACE_END
virtual unsigned long sendChars(char *buf, unsigned long len)
#define Z_DEFAULT_COMPRESSION