diff options
author | (no author) <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10> | 2010-04-10 15:54:56 +0000 |
---|---|---|
committer | (no author) <(no author)@4f64403b-2f21-0410-a795-97e2b3489a10> | 2010-04-10 15:54:56 +0000 |
commit | ce94b1c354101242da5f408b822c667f669e5abe (patch) | |
tree | 7a3a6e42202b320bd5ba0eec65a3079b5f9a1bff /updater/unzipfile.cpp | |
parent | 6eeecd465296d56cb91646706eed1cca38a28794 (diff) |
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
Diffstat (limited to 'updater/unzipfile.cpp')
-rw-r--r-- | updater/unzipfile.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
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 <unzip.h> +#include <iowin32.h> + +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); + } +} |