Skip to content

Commit 451362d

Browse files
committed
Add activeCodePage support and bump 1.0.17
1 parent f00d151 commit 451362d

File tree

3 files changed

+87
-56
lines changed

3 files changed

+87
-56
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,10 @@ Appends `supportedOS` tag.
135135
Parameters <os_type> [os_type #2] [os_type #3] ...
136136
os_type one of { vista, win7, win8, win81, win10 } or raw GUID as specified
137137
by Microsoft. Multiple OSes can be included in a manifest
138+
139+
#### ActiveCodePage
140+
141+
Appends `activeCodePage` tag for non-Unicode codepages. See https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests#activeCodePage for more information.
142+
143+
Parameters <locale>
144+
locale UTF-8, Legacy or locale name (e.g. en-US)

Src/Ummm.vbp

+4-5
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@ Path32=".."
1010
Command32=""
1111
Name="Ummm"
1212
HelpContextID="0"
13-
Description="Unattended MMM 1.0.16"
13+
Description="Unattended MMM 1.0.17"
1414
CompatibleMode="0"
1515
MajorVer=1
1616
MinorVer=0
17-
RevisionVer=16
17+
RevisionVer=17
1818
AutoIncrementVer=0
1919
ServerSupportFiles=0
2020
VersionComments="Unattended MMM"
21-
VersionCompanyName="Unicontsoft"
22-
VersionFileDescription="Unattended MMM 1.0.16"
23-
VersionLegalCopyright="Copyright (c) 2009-2021 by [email protected]"
21+
VersionFileDescription="Unattended MMM 1.0.17"
22+
VersionLegalCopyright="Copyright (c) 2009-2022 by [email protected] and contributors"
2423
CompilationType=0
2524
OptimizationType=0
2625
FavorPentiumPro(tm)=0

Src/mdUmmm.bas

+76-51
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Attribute VB_Name = "mdUmmm"
22
'=========================================================================
33
'
44
' Unattended Make My Manifest Project
5-
' Copyright (c) 2009-2021 [email protected]
5+
' Copyright (c) 2009-2022 [email protected]
66
'
77
'=========================================================================
88
Option Explicit
@@ -39,6 +39,9 @@ Private Declare Function ProgIDFromCLSID Lib "ole32.dll" (pCLSID As Any, lpszPro
3939
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
4040
Private Declare Sub CoTaskMemFree Lib "ole32" (ByVal pv As Long)
4141
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
42+
Private Declare Function CommandLineToArgvW Lib "shell32" (ByVal lpCmdLine As Long, pNumArgs As Long) As Long
43+
Private Declare Function LocalFree Lib "kernel32" (ByVal hMem As Long) As Long
44+
Private Declare Function ApiSysAllocString Lib "oleaut32" Alias "SysAllocString" (ByVal Ptr As Long) As Long
4245

4346
'=========================================================================
4447
' Constants and member variables
@@ -156,7 +159,7 @@ Private Function pvProcess(sFile As String) As String
156159
'--- on_off is true/false or 0/1
157160
pvDumpGdiScaling C_Bool(At(vRow, 1)), cOutput
158161
Case "dpiawareness"
159-
'--- dpiawareness elements
162+
'--- dpiawareness <elements>
160163
pvDumpDpiAwareness At(vRow, 1), cOutput
161164
Case "supportedos"
162165
'--- supportedos <os_types>
@@ -166,6 +169,10 @@ Private Function pvProcess(sFile As String) As String
166169
'--- longpathaware [on_off]
167170
'--- on_off is true/false or 0/1
168171
pvDumpLongPathAware C_Bool(At(vRow, 1)), cOutput
172+
Case "activecodepage"
173+
'--- activecodepage <locale>
174+
'--- locale can be UTF-8, Legacy or locale name (e.g. en-US)
175+
pvDumpActiveCodePage At(vRow, 1), cOutput
169176
End Select
170177
Next
171178
Case 0
@@ -536,27 +543,6 @@ EH:
536543
Resume Next
537544
End Function
538545

539-
Private Function pvDumpLongPathAware(ByVal bAware As Boolean, cOutput As Collection) As Boolean
540-
Const FUNC_NAME As String = "pvDumpLongPathAware"
541-
'--- note: longPathAware details from MS here:
542-
'--- https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN
543-
'--- Requires Windows 10, version 1607 or newer and HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled = 1
544-
On Error GoTo EH
545-
If bAware Then
546-
cOutput.Add " <application xmlns=""urn:schemas-microsoft-com:asm.v3"">"
547-
cOutput.Add " <windowsSettings xmlns:ws2=""http://schemas.microsoft.com/SMI/2016/WindowsSettings"">"
548-
cOutput.Add " <ws2:longPathAware>true</ws2:longPathAware>"
549-
cOutput.Add " </windowsSettings>"
550-
cOutput.Add " </application>"
551-
End If
552-
'--- success
553-
pvDumpLongPathAware = True
554-
Exit Function
555-
EH:
556-
PrintError FUNC_NAME
557-
Resume Next
558-
End Function
559-
560546
Private Function pvDumpGdiScaling(ByVal bEnable As Boolean, cOutput As Collection) As Boolean
561547
Const FUNC_NAME As String = "pvDumpGdiScaling"
562548

@@ -576,13 +562,13 @@ EH:
576562
Resume Next
577563
End Function
578564

579-
Private Function pvDumpDpiAwareness(ByVal sValues As String, cOutput As Collection) As Boolean
565+
Private Function pvDumpDpiAwareness(sValues As String, cOutput As Collection) As Boolean
580566
Const FUNC_NAME As String = "pvDumpDpiAwareness"
581567

582568
On Error GoTo EH
583569
cOutput.Add " <asmv3:application>"
584570
cOutput.Add " <asmv3:windowsSettings xmlns=""http://schemas.microsoft.com/SMI/2016/WindowsSettings"">"
585-
cOutput.Add Printf(" <dpiAwareness>%1</dpiAwareness>", sValues)
571+
cOutput.Add Printf(" <dpiAwareness>%1</dpiAwareness>", pvXmlEscape(sValues))
586572
cOutput.Add " </asmv3:windowsSettings>"
587573
cOutput.Add " </asmv3:application>"
588574
'--- success
@@ -593,6 +579,27 @@ EH:
593579
Resume Next
594580
End Function
595581

582+
Private Function pvDumpLongPathAware(ByVal bAware As Boolean, cOutput As Collection) As Boolean
583+
Const FUNC_NAME As String = "pvDumpLongPathAware"
584+
'--- note: longPathAware details from MS here:
585+
'--- https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file?redirectedfrom=MSDN
586+
'--- Requires Windows 10, version 1607 or newer and HKLM\SYSTEM\CurrentControlSet\Control\FileSystem LongPathsEnabled = 1
587+
On Error GoTo EH
588+
If bAware Then
589+
cOutput.Add " <application xmlns=""urn:schemas-microsoft-com:asm.v3"">"
590+
cOutput.Add " <windowsSettings xmlns:ws2=""http://schemas.microsoft.com/SMI/2016/WindowsSettings"">"
591+
cOutput.Add " <ws2:longPathAware>true</ws2:longPathAware>"
592+
cOutput.Add " </windowsSettings>"
593+
cOutput.Add " </application>"
594+
End If
595+
'--- success
596+
pvDumpLongPathAware = True
597+
Exit Function
598+
EH:
599+
PrintError FUNC_NAME
600+
Resume Next
601+
End Function
602+
596603
Private Function pvDumpSupportedOs(vRow As Variant, cOutput As Collection) As Boolean
597604
Const FUNC_NAME As String = "pvDumpSupportedOs"
598605
Dim lIdx As Long
@@ -634,6 +641,24 @@ EH:
634641
Resume Next
635642
End Function
636643

644+
Private Function pvDumpActiveCodePage(sLocale As String, cOutput As Collection) As Boolean
645+
Const FUNC_NAME As String = "pvDumpActiveCodePage"
646+
647+
'--- https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests#activeCodePage
648+
On Error GoTo EH
649+
cOutput.Add " <asmv3:application>"
650+
cOutput.Add " <asmv3:windowsSettings xmlns=""http://schemas.microsoft.com/SMI/2019/WindowsSettings"">"
651+
cOutput.Add Printf(" <activeCodePage>%1</activeCodePage>", pvXmlEscape(sLocale))
652+
cOutput.Add " </asmv3:windowsSettings>"
653+
cOutput.Add " </asmv3:application>"
654+
'--- success
655+
pvDumpActiveCodePage = True
656+
Exit Function
657+
EH:
658+
PrintError FUNC_NAME
659+
Resume Next
660+
End Function
661+
637662
Private Function pvGetFlags(ByVal lMask As Long, vFlags As Variant) As String
638663
Const FUNC_NAME As String = "pvGetFlags"
639664
Dim lIdx As Long
@@ -656,32 +681,33 @@ EH:
656681
End Function
657682

658683
Private Function pvSplitArgs(sText As String) As Variant
659-
Const FUNC_NAME As String = "pvSplitArgs"
660-
Dim oMatches As Object
661684
Dim vRetVal As Variant
685+
Dim lPtr As Long
686+
Dim lArgc As Long
662687
Dim lIdx As Long
688+
Dim lArgPtr As Long
663689

664-
On Error GoTo EH
665-
With CreateObject("VBScript.RegExp")
666-
.Global = True
667-
.Pattern = """([^""]*(?:""""[^""]*)*)""|([^ ]+)"
668-
Set oMatches = .Execute(sText)
669-
If oMatches.Count > 0 Then
670-
ReDim vRetVal(0 To oMatches.Count - 1) As String
671-
For lIdx = 0 To oMatches.Count - 1
672-
With oMatches(lIdx)
673-
vRetVal(lIdx) = Replace$(.SubMatches(0) & .SubMatches(1), """""", """")
674-
End With
675-
Next
676-
Else
677-
vRetVal = Split(vbNullString)
678-
End If
679-
End With
690+
If LenB(sText) <> 0 Then
691+
lPtr = CommandLineToArgvW(StrPtr(sText), lArgc)
692+
End If
693+
If lArgc > 0 Then
694+
ReDim vRetVal(0 To lArgc - 1) As String
695+
For lIdx = 0 To UBound(vRetVal)
696+
Call CopyMemory(lArgPtr, ByVal lPtr + 4 * lIdx, 4)
697+
vRetVal(lIdx) = SysAllocString(lArgPtr)
698+
Next
699+
Else
700+
vRetVal = Split(vbNullString)
701+
End If
702+
Call LocalFree(lPtr)
680703
pvSplitArgs = vRetVal
681-
Exit Function
682-
EH:
683-
PrintError FUNC_NAME
684-
Resume Next
704+
End Function
705+
706+
Private Function SysAllocString(ByVal lPtr As Long) As String
707+
Dim lTemp As Long
708+
709+
lTemp = ApiSysAllocString(lPtr)
710+
Call CopyMemory(ByVal VarPtr(SysAllocString), lTemp, 4)
685711
End Function
686712

687713
Private Function pvPathDifference(sBase As String, sFolder As String) As String
@@ -850,8 +876,8 @@ Private Function pvGetTempFileName() As String
850876

851877
sFile = String(2000, 0)
852878
Call GetTempFileName(Environ$("TEMP"), "UMMM", 0, sFile)
853-
If InStr(sFile, Chr$(0)) > 0 Then
854-
pvGetTempFileName = Left$(sFile, InStr(sFile, Chr$(0)) - 1)
879+
If InStr(sFile, vbNullChar) > 0 Then
880+
pvGetTempFileName = Left$(sFile, InStr(sFile, vbNullChar) - 1)
855881
Else
856882
pvGetTempFileName = "C:\UMMM.tmp"
857883
End If
@@ -919,7 +945,7 @@ Private Function pvGetStringFileInfo(sFile As String, sKey As String) As String
919945
End If
920946

921947
' Strip out null termination (ASCII zero)
922-
pvGetStringFileInfo = Replace(pvGetStringFileInfo, Chr$(0), "")
948+
pvGetStringFileInfo = Replace(pvGetStringFileInfo, vbNullChar, vbNullString)
923949
QH:
924950
End Function
925951

@@ -965,4 +991,3 @@ Private Function pvIsGuid(ByVal sValue As String) As Boolean
965991
Const EMPTY_GUID As String = "{00000000-0000-0000-0000-000000000000}"
966992
pvIsGuid = sValue Like Replace(EMPTY_GUID, "0", "[0-9a-fA-F]")
967993
End Function
968-

0 commit comments

Comments
 (0)