ReactOS 0.4.16-dev-340-g0540c21
CZipCreator.cpp File Reference
#include "precomp.h"
#include "atlsimpcoll.h"
#include "minizip/zip.h"
#include "minizip/iowin32.h"
#include <process.h>
Include dependency graph for CZipCreator.cpp:

Go to the source code of this file.

Classes

struct  CZipCreatorImpl
 

Enumerations

enum  CZC_ERROR { CZCERR_ZEROITEMS = 1 , CZCERR_NOFILES , CZCERR_CREATE , CZCERR_READ }
 

Functions

static CStringW DoGetZipName (PCWSTR filename)
 
static CStringW DoGetBaseName (PCWSTR filename)
 
static CStringA DoGetNameInZip (const CStringW &basename, const CStringW &filename, UINT nCodePage)
 
static BOOL DoReadAllOfFile (PCWSTR filename, CSimpleArray< BYTE > &contents, zip_fileinfo *pzi)
 
static void DoAddFilesFromItem (CSimpleArray< CStringW > &files, PCWSTR item)
 
static unsigned __stdcall create_zip_function (void *arg)
 

Enumeration Type Documentation

◆ CZC_ERROR

Enumerator
CZCERR_ZEROITEMS 
CZCERR_NOFILES 
CZCERR_CREATE 
CZCERR_READ 

Definition at line 213 of file CZipCreator.cpp.

214{
219};
@ CZCERR_NOFILES
@ CZCERR_ZEROITEMS
@ CZCERR_READ
@ CZCERR_CREATE

Function Documentation

◆ create_zip_function()

static unsigned __stdcall create_zip_function ( void arg)
static

Definition at line 176 of file CZipCreator.cpp.

177{
178 CZipCreator *pCreator = reinterpret_cast<CZipCreator *>(arg);
179 return pCreator->m_pimpl->JustDoIt();
180}
struct CZipCreatorImpl * m_pimpl
Definition: CZipCreator.hpp:16
void * arg
Definition: msvc.h:10

Referenced by CZipCreator::runThread().

◆ DoAddFilesFromItem()

static void DoAddFilesFromItem ( CSimpleArray< CStringW > &  files,
PCWSTR  item 
)
static

Definition at line 120 of file CZipCreator.cpp.

121{
123 {
124 files.Add(item);
125 return;
126 }
127
129 StringCbCopyW(szPath, sizeof(szPath), item);
130 PathAppendW(szPath, L"*");
131
133 HANDLE hFind = FindFirstFileW(szPath, &find);
134 if (hFind == INVALID_HANDLE_VALUE)
135 return;
136
137 do
138 {
139 if (wcscmp(find.cFileName, L".") == 0 ||
140 wcscmp(find.cFileName, L"..") == 0)
141 {
142 continue;
143 }
144
145 StringCbCopyW(szPath, sizeof(szPath), item);
146 PathAppendW(szPath, find.cFileName);
147
148 if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
150 else
151 files.Add(szPath);
152 } while (FindNextFileW(hFind, &find));
153
154 FindClose(hFind);
155}
static void DoAddFilesFromItem(CSimpleArray< CStringW > &files, PCWSTR item)
static TAGID TAGID find
Definition: db.cpp:155
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
Definition: path.c:1723
LPCWSTR szPath
Definition: env.c:37
static ATOM item
Definition: dde.c:856
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define L(x)
Definition: ntvdm.h:50
#define PathAppendW
Definition: pathcch.h:309
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DoAddFilesFromItem(), and CZipCreatorImpl::JustDoIt().

◆ DoGetBaseName()

static CStringW DoGetBaseName ( PCWSTR  filename)
static

Definition at line 37 of file CZipCreator.cpp.

38{
39 WCHAR szBaseName[MAX_PATH];
40 StringCbCopyW(szBaseName, sizeof(szBaseName), filename);
41 PathRemoveFileSpecW(szBaseName);
42 PathAddBackslashW(szBaseName);
43 return szBaseName;
44}
BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
Definition: path.c:629
const char * filename
Definition: ioapi.h:137
#define PathAddBackslashW
Definition: pathcch.h:301

Referenced by CZipCreatorImpl::JustDoIt().

◆ DoGetNameInZip()

static CStringA DoGetNameInZip ( const CStringW basename,
const CStringW filename,
UINT  nCodePage 
)
static

Definition at line 47 of file CZipCreator.cpp.

48{
49 CStringW basenameI = basename, filenameI = filename;
50 basenameI.MakeUpper();
51 filenameI.MakeUpper();
52
54 if (filenameI.Find(basenameI) == 0)
55 ret = filename.Mid(basename.GetLength());
56 else
57 ret = filename;
58
59 ret.Replace(L'\\', L'/');
60
61 return CStringA(CW2AEX<MAX_PATH>(ret, nCodePage));
62}
CStringT & MakeUpper()
Definition: cstringt.h:685
static void basename(LPCWSTR path, LPWSTR name)
Definition: profile.c:38
CAtlStringA CStringA
Definition: atlstr.h:131
int ret

Referenced by CZipCreatorImpl::JustDoIt().

◆ DoGetZipName()

static CStringW DoGetZipName ( PCWSTR  filename)
static

Definition at line 15 of file CZipCreator.cpp.

16{
20
22 ret += L".zip";
23
24 UINT i = 2;
25 while (PathFileExistsW(ret))
26 {
28 str.Format(L" (%u).zip", i++);
29
30 ret = szPath;
31 ret += str;
32 }
33
34 return ret;
35}
void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
Definition: path.c:823
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
Definition: path.c:1777
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT
Definition: ndis.h:50
const WCHAR * str

Referenced by CZipCreatorImpl::JustDoIt().

◆ DoReadAllOfFile()

static BOOL DoReadAllOfFile ( PCWSTR  filename,
CSimpleArray< BYTE > &  contents,
zip_fileinfo pzi 
)
static

Definition at line 65 of file CZipCreator.cpp.

67{
68 contents.RemoveAll();
69
74 {
75 DPRINT1("%S: cannot open\n", filename);
76 return FALSE;
77 }
78
79 FILETIME ft, ftLocal;
80 ZeroMemory(pzi, sizeof(*pzi));
81 if (GetFileTime(hFile, NULL, NULL, &ft))
82 {
83 SYSTEMTIME st;
84 FileTimeToLocalFileTime(&ft, &ftLocal);
85 FileTimeToSystemTime(&ftLocal, &st);
86 pzi->tmz_date.tm_sec = st.wSecond;
87 pzi->tmz_date.tm_min = st.wMinute;
88 pzi->tmz_date.tm_hour = st.wHour;
89 pzi->tmz_date.tm_mday = st.wDay;
90 pzi->tmz_date.tm_mon = st.wMonth - 1;
91 pzi->tmz_date.tm_year = st.wYear;
92 }
93
94 const DWORD cbBuff = 0x7FFF;
95 LPBYTE pbBuff = reinterpret_cast<LPBYTE>(CoTaskMemAlloc(cbBuff));
96 if (!pbBuff)
97 {
98 DPRINT1("Out of memory\n");
100 return FALSE;
101 }
102
103 for (;;)
104 {
105 DWORD cbRead;
106 if (!ReadFile(hFile, pbBuff, cbBuff, &cbRead, NULL) || !cbRead)
107 break;
108
109 for (DWORD i = 0; i < cbRead; ++i)
110 contents.Add(pbBuff[i]);
111 }
112
113 CoTaskMemFree(pbBuff);
115
116 return TRUE;
117}
#define DPRINT1
Definition: precomp.h:8
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define GENERIC_READ
Definition: compat.h:135
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:896
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
BOOL WINAPI FileTimeToLocalFileTime(IN CONST FILETIME *lpFileTime, OUT LPFILETIME lpLocalFileTime)
Definition: time.c:221
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43
static const char * contents
Definition: parser.c:511
_In_ HANDLE hFile
Definition: mswsock.h:90
WORD wYear
Definition: winbase.h:930
WORD wMonth
Definition: winbase.h:931
WORD wHour
Definition: winbase.h:934
WORD wSecond
Definition: winbase.h:936
WORD wMinute
Definition: winbase.h:935
WORD wDay
Definition: winbase.h:933
int tm_hour
Definition: zip.h:93
int tm_min
Definition: zip.h:92
int tm_sec
Definition: zip.h:91
int tm_mon
Definition: zip.h:95
int tm_year
Definition: zip.h:96
int tm_mday
Definition: zip.h:94
tm_zip tmz_date
Definition: zip.h:101
unsigned char * LPBYTE
Definition: typedefs.h:53
#define ZeroMemory
Definition: winbase.h:1737

Referenced by CZipCreatorImpl::JustDoIt().