ReactOS  0.4.15-dev-1068-g467feb9
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 (LPCWSTR filename)
 
static CStringA DoGetAnsiName (LPCWSTR filename)
 
static CStringW DoGetBaseName (LPCWSTR filename)
 
static CStringA DoGetNameInZip (const CStringW &basename, const CStringW &filename)
 
static BOOL DoReadAllOfFile (LPCWSTR filename, CSimpleArray< BYTE > &contents, zip_fileinfo *pzi)
 
static void DoAddFilesFromItem (CSimpleArray< CStringW > &files, LPCWSTR 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 220 of file CZipCreator.cpp.

Function Documentation

◆ create_zip_function()

static unsigned __stdcall create_zip_function ( void arg)
static

Definition at line 183 of file CZipCreator.cpp.

184 {
185  CZipCreator *pCreator = reinterpret_cast<CZipCreator *>(arg);
186  return pCreator->m_pimpl->JustDoIt();
187 }
struct CZipCreatorImpl * m_pimpl
Definition: CZipCreator.hpp:16

Referenced by CZipCreator::runThread().

◆ DoAddFilesFromItem()

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

Definition at line 127 of file CZipCreator.cpp.

128 {
129  if (!PathIsDirectoryW(item))
130  {
131  files.Add(item);
132  return;
133  }
134 
136  StringCbCopyW(szPath, sizeof(szPath), item);
137  PathAppendW(szPath, L"*");
138 
140  HANDLE hFind = FindFirstFileW(szPath, &find);
141  if (hFind == INVALID_HANDLE_VALUE)
142  return;
143 
144  do
145  {
146  if (wcscmp(find.cFileName, L".") == 0 ||
147  wcscmp(find.cFileName, L"..") == 0)
148  {
149  continue;
150  }
151 
152  StringCbCopyW(szPath, sizeof(szPath), item);
153  PathAppendW(szPath, find.cFileName);
154 
155  if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
156  DoAddFilesFromItem(files, szPath);
157  else
158  files.Add(szPath);
159  } while (FindNextFileW(hFind, &find));
160 
161  FindClose(hFind);
162 }
BOOL WINAPI FindNextFileW(IN HANDLE hFindFile, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:382
BOOL WINAPI PathIsDirectoryW(LPCWSTR lpszPath)
Definition: path.c:1702
BOOL Add(const T &t)
Definition: atlsimpcoll.h:58
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
BOOL WINAPI PathAppendW(LPWSTR lpszPath, LPCWSTR lpszAppend)
Definition: path.c:121
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
static const WCHAR L[]
Definition: oid.c:1250
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
static ATOM item
Definition: dde.c:856
LPCWSTR szPath
Definition: env.c:35
static TAGID TAGID find
Definition: db.cpp:153
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
static void DoAddFilesFromItem(CSimpleArray< CStringW > &files, LPCWSTR item)
HANDLE WINAPI FindFirstFileW(IN LPCWSTR lpFileName, OUT LPWIN32_FIND_DATAW lpFindFileData)
Definition: find.c:320
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502

Referenced by CZipCreatorImpl::JustDoIt().

◆ DoGetAnsiName()

static CStringA DoGetAnsiName ( LPCWSTR  filename)
static

Definition at line 37 of file CZipCreator.cpp.

38 {
39  CHAR buf[MAX_PATH];
41  return buf;
42 }
#define WideCharToMultiByte
Definition: compat.h:111
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define CP_ACP
Definition: compat.h:109
char CHAR
Definition: xmlstorage.h:175
const char * filename
Definition: ioapi.h:135
smooth NULL
Definition: ftsmooth.c:416
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34

Referenced by DoGetNameInZip().

◆ DoGetBaseName()

static CStringW DoGetBaseName ( LPCWSTR  filename)
static

Definition at line 44 of file CZipCreator.cpp.

45 {
46  WCHAR szBaseName[MAX_PATH];
47  StringCbCopyW(szBaseName, sizeof(szBaseName), filename);
48  PathRemoveFileSpecW(szBaseName);
49  PathAddBackslashW(szBaseName);
50  return szBaseName;
51 }
BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
Definition: path.c:624
const char * filename
Definition: ioapi.h:135
LPWSTR WINAPI PathAddBackslashW(LPWSTR lpszPath)
Definition: path.c:289
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166

Referenced by CZipCreatorImpl::JustDoIt().

◆ DoGetNameInZip()

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

Definition at line 54 of file CZipCreator.cpp.

55 {
56  CStringW basenameI = basename, filenameI = filename;
57  basenameI.MakeUpper();
58  filenameI.MakeUpper();
59 
60  CStringW ret;
61  if (filenameI.Find(basenameI) == 0)
62  ret = filename.Mid(basename.GetLength());
63  else
64  ret = filename;
65 
66  ret.Replace(L'\\', L'/');
67 
68  return DoGetAnsiName(ret);
69 }
static void basename(LPCWSTR path, LPWSTR name)
Definition: profile.c:38
static CStringA DoGetAnsiName(LPCWSTR filename)
Definition: CZipCreator.cpp:37
const char * filename
Definition: ioapi.h:135
CStringT & MakeUpper()
Definition: cstringt.h:600
int ret
static const WCHAR L[]
Definition: oid.c:1250

Referenced by CZipCreatorImpl::JustDoIt().

◆ DoGetZipName()

static CStringW DoGetZipName ( LPCWSTR  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  {
27  CStringW str;
28  str.Format(L" (%u).zip", i++);
29 
30  ret = szPath;
31  ret += str;
32  }
33 
34  return ret;
35 }
const char * filename
Definition: ioapi.h:135
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
void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
Definition: path.c:818
const WCHAR * str
BOOL WINAPI PathFileExistsW(LPCWSTR lpszPath)
Definition: path.c:1756
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:34
int ret
static const WCHAR L[]
Definition: oid.c:1250
LPCWSTR szPath
Definition: env.c:35
unsigned int UINT
Definition: ndis.h:50
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166

Referenced by CZipCreatorImpl::JustDoIt().

◆ DoReadAllOfFile()

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

Definition at line 72 of file CZipCreator.cpp.

74 {
75  contents.RemoveAll();
76 
81  {
82  DPRINT1("%S: cannot open\n", filename);
83  return FALSE;
84  }
85 
86  FILETIME ft, ftLocal;
87  ZeroMemory(pzi, sizeof(*pzi));
88  if (GetFileTime(hFile, NULL, NULL, &ft))
89  {
90  SYSTEMTIME st;
91  FileTimeToLocalFileTime(&ft, &ftLocal);
92  FileTimeToSystemTime(&ftLocal, &st);
93  pzi->tmz_date.tm_sec = st.wSecond;
94  pzi->tmz_date.tm_min = st.wMinute;
95  pzi->tmz_date.tm_hour = st.wHour;
96  pzi->tmz_date.tm_mday = st.wDay;
97  pzi->tmz_date.tm_mon = st.wMonth - 1;
98  pzi->tmz_date.tm_year = st.wYear;
99  }
100 
101  const DWORD cbBuff = 0x7FFF;
102  LPBYTE pbBuff = reinterpret_cast<LPBYTE>(CoTaskMemAlloc(cbBuff));
103  if (!pbBuff)
104  {
105  DPRINT1("Out of memory\n");
107  return FALSE;
108  }
109 
110  for (;;)
111  {
112  DWORD cbRead;
113  if (!ReadFile(hFile, pbBuff, cbBuff, &cbRead, NULL) || !cbRead)
114  break;
115 
116  for (DWORD i = 0; i < cbRead; ++i)
117  contents.Add(pbBuff[i]);
118  }
119 
120  CoTaskMemFree(pbBuff);
122 
123  return TRUE;
124 }
#define CloseHandle
Definition: compat.h:487
BOOL Add(const T &t)
Definition: atlsimpcoll.h:58
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
WORD wMonth
Definition: winbase.h:884
#define TRUE
Definition: types.h:120
uInt tm_mday
Definition: zip.h:94
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
#define ZeroMemory
Definition: winbase.h:1648
const char * filename
Definition: ioapi.h:135
BOOL WINAPI FileTimeToLocalFileTime(IN CONST FILETIME *lpFileTime, OUT LPFILETIME lpLocalFileTime)
Definition: time.c:221
#define FILE_SHARE_READ
Definition: compat.h:136
WORD wYear
Definition: winbase.h:883
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 char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
WORD wMinute
Definition: winbase.h:888
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:523
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
unsigned long DWORD
Definition: ntddk_ex.h:95
uInt tm_mon
Definition: zip.h:95
WORD wSecond
Definition: winbase.h:889
#define GENERIC_READ
Definition: compat.h:135
uInt tm_year
Definition: zip.h:96
_In_ HANDLE hFile
Definition: mswsock.h:90
WORD wDay
Definition: winbase.h:886
uInt tm_sec
Definition: zip.h:91
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43
WORD wHour
Definition: winbase.h:887
#define ReadFile(a, b, c, d, e)
Definition: compat.h:490
#define DPRINT1
Definition: precomp.h:8
#define CreateFileW
Definition: compat.h:489
tm_zip tmz_date
Definition: zip.h:101
uInt tm_hour
Definition: zip.h:93
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426
BOOL WINAPI GetFileTime(IN HANDLE hFile, OUT LPFILETIME lpCreationTime OPTIONAL, OUT LPFILETIME lpLastAccessTime OPTIONAL, OUT LPFILETIME lpLastWriteTime OPTIONAL)
Definition: fileinfo.c:896
uInt tm_min
Definition: zip.h:92

Referenced by CZipCreatorImpl::JustDoIt().