From ce94b1c354101242da5f408b822c667f669e5abe Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10> Date: Sat, 10 Apr 2010 15:54:56 +0000 Subject: Updated MiniZip to version 1.1 That added support for Unicode files and more compression options git-svn-id: https://server.scottellis.com.au/svn/mim_plugs@505 4f64403b-2f21-0410-a795-97e2b3489a10 --- updater/unzipfile.cpp | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 updater/unzipfile.cpp (limited to 'updater/unzipfile.cpp') diff --git a/updater/unzipfile.cpp b/updater/unzipfile.cpp new file mode 100644 index 0000000..1128698 --- /dev/null +++ b/updater/unzipfile.cpp @@ -0,0 +1,76 @@ +#include "common.h" +#include "utils.h" + +#include +#include + +bool extractCurrentFile(unzFile uf, TCHAR *path) +{ + int err = UNZ_OK; + unz_file_info64 file_info; + char filename_inzip[MAX_PATH]; + char buf[8192]; + + err = unzGetCurrentFileInfo64(uf, &file_info, filename_inzip, sizeof(filename_inzip), NULL, 0, buf,sizeof(buf)); + if (err != UNZ_OK) return false; + + err = unzOpenCurrentFile(uf); + if (err != UNZ_OK) return false; + + TCHAR save_file[MAX_PATH]; + TCHAR* p = mir_utf8decodeT(filename_inzip); + mir_sntprintf(save_file, SIZEOF(save_file), _T("%s\\%s"), path, p); + mir_free(p); + + for (p = save_file; *p; ++p) if (*p == '/') *p = '\\'; + + p = _tcsrchr(save_file, '\\'); if (p) *p = 0; + CreatePath(save_file); + if (p) *p = '\\'; + + HANDLE hFile = CreateFile(save_file, GENERIC_WRITE, FILE_SHARE_WRITE, 0, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); + + if (hFile != INVALID_HANDLE_VALUE) + { + for (;;) + { + err = unzReadCurrentFile(uf, buf, sizeof(buf)); + if (err <= 0) break; + + DWORD bytes; + if (!WriteFile(hFile, buf, err, &bytes, FALSE)) + { + err = UNZ_ERRNO; + break; + } + } + + FILETIME ftLocal, ftCreate, ftLastAcc, ftLastWrite; + GetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite); + DosDateTimeToFileTime(HIWORD(file_info.dosDate), LOWORD(file_info.dosDate), &ftLocal); + LocalFileTimeToFileTime(&ftLocal, &ftLastWrite); + SetFileTime(hFile, &ftCreate, &ftLastAcc, &ftLastWrite); + + CloseHandle(hFile); + + unzCloseCurrentFile(uf); /* don't lose the error */ + } + return true; +} + +void unzip_file(TCHAR* zipfile, TCHAR* dest) +{ + zlib_filefunc64_def ffunc; + fill_win32_filefunc64(&ffunc); + + unzFile uf = unzOpen2_64(zipfile, &ffunc); + if (uf) + { + do { + extractCurrentFile(uf, dest); + } + while (unzGoToNextFile(uf) == UNZ_OK); + unzClose(uf); + } +} -- cgit v1.2.3