Skip to content

Commit e968f67

Browse files
committed
Allow custom codepage for filenames and use Unicode API
1 parent dd576e2 commit e968f67

File tree

3 files changed

+78
-47
lines changed

3 files changed

+78
-47
lines changed

src/cZipArchive.cls

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Attribute VB_PredeclaredId = False
1313
Attribute VB_Exposed = False
1414
'=========================================================================
1515
'
16-
' cZipArchive (c) 2017-2019 by wqweto@gmail.com
16+
' cZipArchive (c) 2017-2022 by wqweto@gmail.com
1717
'
1818
' A single-class pure VB6 library for zip archives management
1919
'
@@ -116,9 +116,9 @@ Private Const BCRYPT_CHAINING_MODE As String = "ChainingMode"
116116
Private Const BCRYPT_CHAIN_MODE_ECB As String = "ChainingModeECB"
117117
Private Const BCRYPT_ALG_HANDLE_HMAC_FLAG As Long = 8
118118
'--- for GetStdHandle
119-
Private Const STD_INPUT_HANDLE As Long = -10&
120-
Private Const STD_OUTPUT_HANDLE As Long = -11&
121-
Private Const STD_ERROR_HANDLE As Long = -12&
119+
Private Const STD_INPUT_HANDLE As Long = -10
120+
Private Const STD_OUTPUT_HANDLE As Long = -11
121+
Private Const STD_ERROR_HANDLE As Long = -12
122122

123123
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
124124
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileW" (ByVal lpFileName As Long, ByVal lpFindFileData As Long) As Long
@@ -136,15 +136,15 @@ Private Declare Function LocalFileTimeToFileTime Lib "kernel32" (lpLocalFileTime
136136
Private Declare Function SystemTimeToVariantTime Lib "oleaut32" (lpSystemTime As SYSTEMTIME, pvTime As Date) As Long
137137
Private Declare Function VariantTimeToSystemTime Lib "oleaut32" (ByVal vTime As Date, lpSystemTime As SYSTEMTIME) As Long
138138
Private Declare Function VirtualAlloc Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
139-
Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
139+
Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleW" (ByVal lpModuleName As Long) As Long
140140
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
141-
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, Optional ByVal Msg As Long, Optional ByVal wParam As Long, Optional ByVal lParam As Long) As Long
141+
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcW" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, Optional ByVal Msg As Long, Optional ByVal wParam As Long, Optional ByVal lParam As Long) As Long
142142
Private Declare Sub CoTaskMemFree Lib "ole32" (ByVal pv As Long)
143143
Private Declare Function MultiByteToWideChar Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, lpMultiByteStr As Any, ByVal cbMultiByte As Long, lpWideCharStr As Any, ByVal cchWideChar As Long) As Long
144144
Private Declare Function WideCharToMultiByte Lib "kernel32" (ByVal CodePage As Long, ByVal dwFlags As Long, ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, ByVal lpUsedDefaultChar As Long) As Long
145145
Private Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
146-
Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableA" (ByVal lpName As String, ByVal lpBuffer As String, ByVal nSize As Long) As Long
147-
Private Declare Function SetEnvironmentVariable Lib "kernel32" Alias "SetEnvironmentVariableA" (ByVal lpName As String, ByVal lpValue As String) As Long
146+
Private Declare Function GetEnvironmentVariable Lib "kernel32" Alias "GetEnvironmentVariableW" (ByVal lpName As Long, ByVal lpBuffer As Long, ByVal nSize As Long) As Long
147+
Private Declare Function SetEnvironmentVariable Lib "kernel32" Alias "SetEnvironmentVariableW" (ByVal lpName As Long, ByVal lpValue As Long) As Long
148148
Private Declare Function PathMatchSpecW Lib "shlwapi" (ByVal pszFileParam As Long, ByVal pszSpec As Long) As Long
149149
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
150150
#If ImplCompress Then
@@ -170,7 +170,7 @@ Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
170170
Private Declare Function BCryptFinishHash Lib "bcrypt" (ByVal hHash As Long, pbOutput As Any, ByVal cbOutput As Long, ByVal dwFlags As Long) As Long
171171
#End If ' ImplCrypto
172172
#If ImplUseShared = 0 Then
173-
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Long, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Args As Any) As Long
173+
Private Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageW" (ByVal dwFlags As Long, lpSource As Long, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As Long, ByVal nSize As Long, Args As Any) As Long
174174
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesW" (ByVal lpFileName As Long) As Long
175175
Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryW" (ByVal lpPathName As Long, ByVal lpSecurityAttributes As Long) As Long
176176
Private Declare Function CryptBinaryToString Lib "crypt32" Alias "CryptBinaryToStringW" (ByVal pbBinary As Long, ByVal cbBinary As Long, ByVal dwFlags As Long, ByVal pszString As Long, ByRef pcchString As Long) As Long
@@ -263,6 +263,7 @@ Private m_bCancel As Boolean
263263
Private m_lFileCount As Long
264264
Private m_uFiles() As UcsFileInfo
265265
Private m_lCurrentFile As Long
266+
Private m_lCodePage As Long
266267
#If ImplDecompress Then
267268
Private m_sComment As String
268269
Private m_vArchiveFile As Variant
@@ -441,7 +442,7 @@ End Type
441442
'=========================================================================
442443

443444
Public Property Get SemVersion() As String
444-
SemVersion = "0.2.8"
445+
SemVersion = "0.2.9"
445446
End Property
446447

447448
Public Property Get ThunkBuildDate() As String
@@ -464,6 +465,14 @@ Public Property Get FileInfo(ByVal FileIdx As Long) As Variant
464465
End If
465466
End Property
466467

468+
Public Property Get CodePage() As Long
469+
CodePage = m_lCodePage
470+
End Property
471+
472+
Public Property Let CodePage(ByVal lValue As Long)
473+
m_lCodePage = lValue
474+
End Property
475+
467476
#If ImplDecompress Then
468477

469478
Public Property Get Comment() As String
@@ -582,7 +591,7 @@ Public Function CompressArchive( _
582591
If bSkip Then
583592
GoTo SkipFile
584593
End If
585-
lComprLevel = LimitLong(lComprLevel, 0, 9)
594+
lComprLevel = Clamp(lComprLevel, 0, 9)
586595
uBuf.Greedy = (lComprLevel <= 4)
587596
uBuf.MaxMatch = At(Array(0, 2, 6, 12, 24, 8, 16, 32, 64, 1000), lComprLevel)
588597
uBuf.NiceLen = At(Array(0, 8, 10, 14, 24, 30, 65, 130, 200, 32768), lComprLevel)
@@ -596,7 +605,7 @@ Public Function CompressArchive( _
596605
uLocal.USize = 0
597606
uLocal.CSize = 0
598607
If UseUtf8 = vbUseDefault Then
599-
uLocal.Flags = IIf(pvFromOemString(pvToOemString(.FileName)) <> .FileName, ucsZcfUseUtf8, 0)
608+
uLocal.Flags = IIf(pvFromOemString(pvToOemString(.FileName, m_lCodePage), m_lCodePage) <> .FileName, ucsZcfUseUtf8, 0)
600609
Else
601610
uLocal.Flags = IIf(UseUtf8 = vbTrue, ucsZcfUseUtf8, 0)
602611
End If
@@ -978,7 +987,7 @@ End Function
978987
Private Sub pvOutputLocalHeader(uFile As UcsVfsFileType, uHdr As UcsLocalHeaderType, FileName As String, baExtra() As Byte)
979988
Dim baFName() As Byte
980989

981-
baFName = pvToOemString(Replace(FileName, "\", "/"), IIf((uHdr.Flags And ucsZcfUseUtf8) <> 0, CP_UTF8, CP_OEMCP))
990+
baFName = pvToOemString(Replace(FileName, "\", "/"), IIf((uHdr.Flags And ucsZcfUseUtf8) <> 0, CP_UTF8, m_lCodePage))
982991
uHdr.LenFname = UBound(baFName) + 1
983992
uHdr.LenExt = UBound(baExtra) + 1
984993
Debug.Assert VarPtr(uHdr.FDate) + 2 - VarPtr(uHdr.Signature) + VarPtr(uHdr.LenExt) + 2 - VarPtr(uHdr.Crc32) = LNG_LEN_LOCAL
@@ -1000,7 +1009,7 @@ Private Sub pvOutputCentralHeader(uFile As UcsVfsFileType, uHdr As UcsCentralHea
10001009
Dim baFName() As Byte
10011010
Dim baComment() As Byte
10021011

1003-
lCodePage = IIf((uHdr.Flags And ucsZcfUseUtf8) <> 0, CP_UTF8, CP_OEMCP)
1012+
lCodePage = IIf((uHdr.Flags And ucsZcfUseUtf8) <> 0, CP_UTF8, m_lCodePage)
10041013
baFName = pvToOemString(Replace(FileName, "\", "/"), lCodePage)
10051014
baComment = pvToOemString(Comment, lCodePage)
10061015
uHdr.LenFname = UBound(baFName) + 1
@@ -1028,7 +1037,7 @@ End Sub
10281037
Private Sub pvOutputEndHeader(uFile As UcsVfsFileType, uHdr As UcsEndHeaderType, Comment As String)
10291038
Dim baComment() As Byte
10301039

1031-
baComment = pvToOemString(Comment)
1040+
baComment = pvToOemString(Comment, m_lCodePage)
10321041
uHdr.LenCom = UBound(baComment) + 1
10331042
Debug.Assert VarPtr(uHdr.LenCom) + 2 - VarPtr(uHdr.Signature) = LNG_LEN_END
10341043
pvVfsWrite uFile, VarPtr(uHdr.Signature), LNG_LEN_END
@@ -1053,7 +1062,7 @@ Private Sub pvToDosDateTime(dDate As Date, nDate As Integer, nTime As Integer)
10531062
Call FileTimeToDosDateTime(uFileTime, VarPtr(nDate), VarPtr(nTime))
10541063
End Sub
10551064

1056-
Private Function pvToOemString(sText As String, Optional ByVal lCodePage As Long = CP_OEMCP) As Byte()
1065+
Private Function pvToOemString(sText As String, ByVal lCodePage As Long) As Byte()
10571066
Dim baRetVal() As Byte
10581067
Dim lSize As Long
10591068

@@ -1094,7 +1103,7 @@ Public Function OpenArchive(ArchiveFile As Variant) As Boolean
10941103
uArchiveFile = pvVfsOpen(ArchiveFile)
10951104
lIdx = pvVfsSeek(uArchiveFile, 0, FILE_END)
10961105
If lIdx >= LNG_LEN_END Then
1097-
For lIdx = 0 To LimitLong(lIdx - LNG_LEN_END, , MAX_END_SEEK)
1106+
For lIdx = 0 To Clamp(lIdx - LNG_LEN_END, , MAX_END_SEEK)
10981107
pvVfsSeek uArchiveFile, -LNG_LEN_END - lIdx, FILE_END
10991108
Debug.Assert VarPtr(uEndHdr.LenCom) + 2 - VarPtr(uEndHdr.Signature) = LNG_LEN_END
11001109
pvVfsRead uArchiveFile, VarPtr(uEndHdr), LNG_LEN_END
@@ -1108,7 +1117,7 @@ Public Function OpenArchive(ArchiveFile As Variant) As Boolean
11081117
If uEndHdr.LenCom > 0 Then
11091118
ReDim baComment(0 To uEndHdr.LenCom - 1) As Byte
11101119
pvVfsRead uArchiveFile, VarPtr(baComment(0)), uEndHdr.LenCom
1111-
sArchiveComment = pvFromOemString(baComment)
1120+
sArchiveComment = pvFromOemString(baComment, m_lCodePage)
11121121
End If
11131122
'--- note: redim one more (last ignored)
11141123
ReDim uFiles(0 To uEndHdr.Entries) As UcsFileInfo
@@ -1213,12 +1222,13 @@ Private Function pvLoadFileInfo(uArchiveFile As UcsVfsFileType, uCentral As UcsC
12131222
.Attributes = uCentral.AttribX
12141223
.Offset = uCentral.Offset
12151224
.Flags = uCentral.Flags
1216-
lCodePage = IIf((.Flags And ucsZcfUseUtf8) <> 0, CP_UTF8, CP_OEMCP)
1225+
lCodePage = IIf((.Flags And ucsZcfUseUtf8) <> 0, CP_UTF8, m_lCodePage)
12171226
Debug.Assert uCentral.LenFname > 0
12181227
If uCentral.LenFname > 0 Then
12191228
ReDim baFName(0 To uCentral.LenFname - 1) As Byte
12201229
pvVfsRead uArchiveFile, VarPtr(baFName(0)), uCentral.LenFname
12211230
.FileName = pvToWinFileName(baFName, lCodePage)
1231+
MsgBox .FileName
12221232
Else
12231233
If pvSetError(MODULE_NAME & "." & FUNC_NAME, ERR_INVALID_ARCHIVE & ". " & Replace(ERR_ENTRY_NO_FILENAME, "%1", lEntry), CanContinue:=True) Then
12241234
GoTo QH
@@ -1988,20 +1998,20 @@ Private Function pvVfsOpen(File As Variant) As UcsVfsFileType
19881998
End If
19891999
pvVfsOpen.Data.nFileSizeLow = pvVfsOpen.BufferSize
19902000
pvVfsOpen.Data.dwFileAttributes = vbArchive
1991-
pvVfsOpen.Data.ftLastWriteTime = pvToFileTime(Now)
2001+
pvVfsOpen.Data.ftLastWriteTime = pvToFileTime(VBA.Now)
19922002
ElseIf IsObject(File) Then
19932003
pvVfsOpen.FileName = STR_STREAM
19942004
Set pvVfsOpen.Stream = File
19952005
If Not pvVfsOpen.Stream Is Nothing Then
19962006
pvVfsOpen.Data.nFileSizeLow = pvVfsOpen.Stream.VfsSetFilePointer(0, FILE_END)
19972007
End If
19982008
pvVfsOpen.Data.dwFileAttributes = vbArchive
1999-
pvVfsOpen.Data.ftLastWriteTime = pvToFileTime(Now)
2009+
pvVfsOpen.Data.ftLastWriteTime = pvToFileTime(VBA.Now)
20002010
Else
20012011
pvVfsOpen.FileName = File
20022012
If Right$(File, 1) = ":" Then
20032013
pvVfsOpen.Data.dwFileAttributes = vbArchive
2004-
pvVfsOpen.Data.ftLastWriteTime = pvToFileTime(Now)
2014+
pvVfsOpen.Data.ftLastWriteTime = pvToFileTime(VBA.Now)
20052015
ElseIf Right$(File, 1) <> "\" Then
20062016
hFind = FindFirstFile(StrPtr(File), VarPtr(pvVfsOpen.Data))
20072017
Else
@@ -2081,7 +2091,7 @@ End Sub
20812091

20822092
Private Function pvVfsRead(uFile As UcsVfsFileType, ByVal lPtr As Long, ByVal lSize As Long) As Long
20832093
If Not IsEmpty(uFile.BufferArray) Then
2084-
pvVfsRead = LimitLong(lSize, 0, uFile.BufferSize - (uFile.BufferPtr - uFile.BufferBase))
2094+
pvVfsRead = Clamp(lSize, 0, uFile.BufferSize - (uFile.BufferPtr - uFile.BufferBase))
20852095
Call CopyMemory(ByVal lPtr, ByVal uFile.BufferPtr, pvVfsRead)
20862096
uFile.BufferPtr = uFile.BufferPtr + pvVfsRead
20872097
ElseIf Not uFile.Stream Is Nothing Then
@@ -2113,7 +2123,7 @@ Private Function pvVfsWrite(uFile As UcsVfsFileType, ByVal lPtr As Long, ByVal l
21132123
lOffset = uFile.BufferPtr - uFile.BufferBase
21142124
If lOffset + lSize > uFile.BufferSize Then
21152125
If lOffset + lSize <= MAX_STEP Then
2116-
uFile.BufferSize = LimitLong(2 ^ Int(Log(lOffset + lSize) / Log(2) + 1), 8192)
2126+
uFile.BufferSize = Clamp(2 ^ Int(Log(lOffset + lSize) / Log(2) + 1), 8192)
21172127
Else
21182128
uFile.BufferSize = (lOffset + lSize + MAX_STEP - 1) And -MAX_STEP
21192129
End If
@@ -2203,7 +2213,7 @@ End Function
22032213

22042214
'= common ================================================================
22052215

2206-
Private Function pvFromOemString(baBuffer() As Byte, Optional ByVal lCodePage As Long = CP_OEMCP) As String
2216+
Private Function pvFromOemString(baBuffer() As Byte, ByVal lCodePage As Long) As String
22072217
Dim lSize As Long
22082218

22092219
If UBound(baBuffer) >= 0 Then
@@ -2277,9 +2287,9 @@ Private Function pvInitRelocTable(uRtbl As UcsZlibRelocTableType) As Long
22772287
.MemNonce = lpThunk + vSplit(ucsIdx_MemNonce)
22782288
.MemXor = lpThunk + vSplit(ucsIdx_MemXor)
22792289
.ZipCrypt = lpThunk + vSplit(ucsIdx_ZipCrypt)
2280-
.MallocImpl = GetProcAddress(GetModuleHandle("ole32"), "CoTaskMemAlloc")
2281-
.ReallocImpl = GetProcAddress(GetModuleHandle("ole32"), "CoTaskMemRealloc")
2282-
.FreeImpl = GetProcAddress(GetModuleHandle("ole32"), "CoTaskMemFree")
2290+
.MallocImpl = GetProcAddress(GetModuleHandle(StrPtr("ole32")), "CoTaskMemAlloc")
2291+
.ReallocImpl = GetProcAddress(GetModuleHandle(StrPtr("ole32")), "CoTaskMemRealloc")
2292+
.FreeImpl = GetProcAddress(GetModuleHandle(StrPtr("ole32")), "CoTaskMemFree")
22832293
.LenCodes = lpThunk + vSplit(ucsIdx_LenCodes)
22842294
.DistCodes = lpThunk + vSplit(ucsIdx_DistCodes)
22852295
.MirrorBytes = lpThunk + vSplit(ucsIdx_MirrorBytes)
@@ -2295,13 +2305,13 @@ Private Function pvGetThunkAddress() As Long
22952305

22962306
If lpThunk = 0 Then
22972307
sBuffer = String$(50, 0)
2298-
Call GetEnvironmentVariable("_ZIP_THUNK_" & GetCurrentProcessId() & "_" & STR_THUNK_BUILDDATE, sBuffer, Len(sBuffer) - 1)
2308+
Call GetEnvironmentVariable(StrPtr("_ZIP_THUNK_" & GetCurrentProcessId() & "_" & STR_THUNK_BUILDDATE), StrPtr(sBuffer), Len(sBuffer) - 1)
22992309
lpThunk = Val(sBuffer)
23002310
If lpThunk = 0 Then
23012311
baThunk = FromBase64Array(STR_THUNK1 & STR_THUNK2)
23022312
lpThunk = VirtualAlloc(0, UBound(baThunk) + 1, MEM_COMMIT, PAGE_EXECUTE_READWRITE)
23032313
Call CopyMemory(ByVal lpThunk, baThunk(0), UBound(baThunk) + 1)
2304-
Call SetEnvironmentVariable("_ZIP_THUNK_" & GetCurrentProcessId() & "_" & STR_THUNK_BUILDDATE, lpThunk)
2314+
Call SetEnvironmentVariable(StrPtr("_ZIP_THUNK_" & GetCurrentProcessId() & "_" & STR_THUNK_BUILDDATE), StrPtr(lpThunk))
23052315
End If
23062316
End If
23072317
pvGetThunkAddress = lpThunk
@@ -2380,8 +2390,8 @@ End Function
23802390
Private Function GetSystemMessage(ByVal lLastDllError As Long) As String
23812391
Dim lSize As Long
23822392

2383-
GetSystemMessage = Space$(2000)
2384-
lSize = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_INSERTS, 0&, lLastDllError, 0&, GetSystemMessage, Len(GetSystemMessage), 0&)
2393+
GetSystemMessage = String$(2000, 0)
2394+
lSize = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM Or FORMAT_MESSAGE_IGNORE_INSERTS, 0, lLastDllError, 0, StrPtr(GetSystemMessage), Len(GetSystemMessage), 0)
23852395
If lSize > 2 Then
23862396
If Mid$(GetSystemMessage, lSize - 1, 2) = vbCrLf Then
23872397
lSize = lSize - 2
@@ -2427,16 +2437,16 @@ Private Function At(vArray As Variant, ByVal lIdx As Long) As Variant
24272437
QH:
24282438
End Function
24292439

2430-
Private Function LimitLong( _
2440+
Private Function Clamp( _
24312441
ByVal lValue As Long, _
24322442
Optional ByVal Min As Long = -2147483647, _
24332443
Optional ByVal Max As Long = 2147483647) As Long
24342444
If lValue < Min Then
2435-
LimitLong = Min
2445+
Clamp = Min
24362446
ElseIf lValue > Max Then
2437-
LimitLong = Max
2447+
Clamp = Max
24382448
Else
2439-
LimitLong = lValue
2449+
Clamp = lValue
24402450
End If
24412451
End Function
24422452

@@ -2466,7 +2476,7 @@ Public Function FromUtf8Array(baText() As Byte) As String
24662476
Dim lSize As Long
24672477

24682478
If UBound(baText) >= 0 Then
2469-
FromUtf8Array = String$(2 * UBound(baText), 0)
2479+
FromUtf8Array = String$(2 * (UBound(baText) + 1), 0)
24702480
lSize = MultiByteToWideChar(CP_UTF8, 0, baText(0), UBound(baText) + 1, ByVal StrPtr(FromUtf8Array), Len(FromUtf8Array))
24712481
FromUtf8Array = Left$(FromUtf8Array, lSize)
24722482
End If
@@ -2515,6 +2525,7 @@ End Function
25152525
Private Sub Class_Initialize()
25162526
pvInitRelocTable m_uRtbl
25172527
m_lCurrentFile = -1
2528+
m_lCodePage = CP_OEMCP
25182529
End Sub
25192530

25202531
#If ImplCrypto Then

test/vbzip/cVbZip.cls

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Public Function Init(vArgs As Variant) As Boolean
6060

6161
On Error GoTo EH
6262
Set m_oArchive = New cZipArchive
63-
Set m_oOpt = GetOpt(vArgs, "mem:m:o:p:si")
63+
Set m_oOpt = GetOpt(vArgs, "mcp:mem:m:o:p:si")
6464
With m_oOpt
6565
.Item("command") = .Item("arg1")
6666
.Item("zip") = .Item("arg2")
@@ -69,11 +69,14 @@ Public Function Init(vArgs As Variant) As Boolean
6969
.Item("file" & lIdx) = .Item("arg" & lIdx + 2)
7070
Next
7171
If Not .Item("-nologo") Then
72-
ConsoleError "VbZip " & m_oArchive.SemVersion & " (c) 2017-2019 by wqweto@gmail.com (" & m_oArchive.ThunkBuildDate & ")" & vbCrLf & vbCrLf
72+
ConsoleError "VbZip " & m_oArchive.SemVersion & " (c) 2017-2022 by wqweto@gmail.com (" & m_oArchive.ThunkBuildDate & ")" & vbCrLf & vbCrLf
7373
End If
7474
If LenB(.Item("zip")) <> 0 Then
7575
ConsoleError "Archive: " & .Item("zip") & vbCrLf
7676
End If
77+
If .Exists("-mcp") Then
78+
m_oArchive.CodePage = Val(.Item("-mcp"))
79+
End If
7780
Select Case LCase$(.Item("command"))
7881
Case "a"
7982
If LenB(.Item("zip")) = 0 Then
@@ -213,7 +216,8 @@ Public Function Init(vArgs As Variant) As Boolean
213216
" -p PASSWORD password used to encrypt/decrypt files" & vbCrLf & _
214217
" -mem METHOD encryption method" & vbCrLf & _
215218
" -so output to stdout" & vbCrLf & _
216-
" -si NAME input from stdin zip to NAME in archive" & vbCrLf
219+
" -si NAME input from stdin zip to NAME in archive" & vbCrLf & _
220+
" -mcp CPAGE codepage for archive filenames [default: 437]" & vbCrLf
217221
Else
218222
ConsoleError "Invalid command: " & .Item("command") & vbCrLf
219223
End If

0 commit comments

Comments
 (0)