1+ # This PowerShell script converts an XML of the Windows Ribbon Framework
2+ # into a binary RES file that needs to be linked into the final EXE file.
3+ # Authors: Daniel Lemke, Sascha Schaefer at JAM Software, Germany
4+
5+
6+ # Stop on errors
7+ $ErrorActionPreference = " Stop"
8+
9+ $appDir = get-location
10+ $prefix = $args [0 ]
11+ $workingDir = $args [1 ]
12+ $RessourceName = $args [2 ]
13+ $UICCDir = $args [3 ]
14+
15+
16+ function FindUICCExe ($pUICCDir )
17+ {
18+ # First check if a valid path was passed via the command line
19+ $lUICCmd = $pUICCDir + " \UICC.exe"
20+ if (Test-Path $lUICCmd )
21+ {
22+ return $lUICCmd
23+ }
24+ # If not, check a few known locations for uicc.exe
25+ elseif (Test-Path " ${env: ProgramFiles(x86)} \Microsoft SDKs\Windows\v7.1A\Bin\uicc.exe" )
26+ {
27+ return " ${env: ProgramFiles(x86)} \Microsoft SDKs\Windows\v7.1A\Bin\uicc.exe"
28+ }
29+ elseif (Test-Path " ${env: ProgramFiles(x86)} \Windows Kits\8.0\bin\x86\uicc.exe" )
30+ {
31+ return " ${env: ProgramFiles(x86)} \Windows Kits\8.0\bin\x86\uicc.exe"
32+ }
33+ elseif (Test-Path " ${env: ProgramFiles(x86)} \Windows Kits\8.1\bin\x86\uicc.exe" )
34+ {
35+ return " ${env: ProgramFiles(x86)} \Windows Kits\8.1\bin\x86\uicc.exe"
36+ }
37+ # Check %PATH%
38+ elseif (Test-Path " UICC.exe" )
39+ {
40+ return " UICC.exe"
41+ }
42+ else
43+ {
44+ # Nothing found -> exit
45+ write " Cannot find UICC.exe."
46+ exit
47+ }
48+ }
49+
50+ $UICCmd = FindUICCExe(" $UICCDir " )
51+ write-host " UICC.exe found: Using $UICCmd "
52+
53+
54+ # Create the .bml, .h and .rc file
55+ & $UICCmd " /W0" " $workingDir \$prefix .Ribbon.Markup.xml" " $workingDir \$prefix .Ribbon.Markup.bml" " /header:$workingDir \$prefix .Ribbon.Markup.h" " /res:$workingDir \$prefix .Ribbon.Markup.rc" " /name:$RessourceName "
56+
57+ # Create the .RES resource file
58+ $rcName = $prefix + " .Ribbon.Markup.rc"
59+ rc " $workingDir \$rcName "
60+
61+ # Create a new Markup .pas file that will contain the Ribbon command constants.
62+
63+ $markupFileName = " $prefix .Ribbon.Markup.pas"
64+ [System.Collections.ArrayList ]$markupContent = New-Object ([System.Collections.ArrayList ])
65+
66+ $FileTopPart = @"
67+ unit $prefix .Ribbon.Markup;
68+
69+ // *****************************************************************************
70+ // * This is an automatically generated source file for UI Element definition *
71+ // * resource symbols and values. Please do not modify manually. *
72+ // *****************************************************************************
73+
74+ interface
75+
76+ {`$ R '$prefix .Ribbon.Markup.res'}
77+
78+ uses
79+ Generics.Collections, SysUtils, UIRibbon;
80+
81+ const
82+ "@
83+ Set-Content - Path " $workingDir \$markupFileName " - Value $FileTopPart
84+
85+ # Get content of the header file (e.g. TreeSize.Ribbon.Markup.h).
86+ $headerFileName = " $prefix .Ribbon.Markup.h"
87+ $data = Get-Content " $workingDir \$headerFileName "
88+
89+ foreach ($line in $data )
90+ {
91+ if ($line.Contains (" #define" ))
92+ {
93+ $line = $line.TrimStart (" #define" )
94+ $commandId = ([regex ]" \b\d{1,5}\b" ).match($line ).groups[0 ].value
95+ $commandName = ([regex ]" \b\w+\b" ).match($line ).groups[0 ].value
96+ $appendLine = " $commandName = $commandId ;"
97+ Add-Content " $workingDir \$markupFileName " " $appendLine "
98+ $dummy = $markupContent.Add ($appendLine );
99+ }
100+ }
101+
102+ # Add some additional predefined text.
103+ $FileMiddlePart = @"
104+
105+ function GetElements(): TRibbonMarkupElementList;
106+
107+ implementation
108+
109+ function GetElements(): TRibbonMarkupElementList;
110+ begin
111+ Result := TRibbonMarkupElementList.Create();
112+ "@
113+
114+ Add-Content " $workingDir \$markupFileName " $FileMiddlePart
115+
116+
117+ # Add the mapping by using the previously generated markup content
118+
119+ # Initialization
120+ $commandName = " "
121+ $LabelTitleResourceID = -1
122+ $LabelDescriptionResourceID = -1
123+ $TooltipTitleResourceID = -1
124+ $TooltipDescriptionResourceID = -1
125+
126+ # RegEx for resource IDs
127+ $resourceIdRegexPattern = " \b\d{1,5}\b"
128+
129+ foreach ($line in $markupContent )
130+ {
131+ if (! ($line.Contains (" RESID" )))
132+ {
133+ if (($commandName ) -and ($commandID ))
134+ {
135+ $appendLine = " Result.Add(TRibbonMarkupElement.Create('$commandName ', $commandId , $LabelTitleResourceID , $LabelDescriptionResourceID , $TooltipTitleResourceID , $TooltipDescriptionResourceID ));"
136+ Add-Content " $workingDir \$markupFileName " " $appendLine "
137+ $LabelTitleResourceID = -1
138+ $LabelDescriptionResourceID = -1
139+ $TooltipTitleResourceID = -1
140+ $TooltipDescriptionResourceID = -1
141+ }
142+
143+ $commandName = ([regex ]" \b\w+\b" ).match($line ).groups[0 ].value
144+ $commandId = ([regex ]$resourceIdRegexPattern ).match($line ).groups[0 ].value
145+ continue
146+ }
147+ if ($commandName -and $line.Contains ($commandName ))
148+ {
149+ if ($line.Contains (" LabelTitle" ))
150+ {
151+ $LabelTitleResourceID = ([regex ]$resourceIdRegexPattern ).match($line ).groups[0 ].value
152+ }
153+ elseif ($line.Contains (" LabelDescription" ))
154+ {
155+ $LabelDescriptionResourceID = ([regex ]$resourceIdRegexPattern ).match($line ).groups[0 ].value
156+ }
157+ elseif ($line.Contains (" TooltipTitle" ))
158+ {
159+ $TooltipTitleResourceID = ([regex ]$resourceIdRegexPattern ).match($line ).groups[0 ].value
160+ }
161+ elseif ($line.Contains (" TooltipDescription" ))
162+ {
163+ $TooltipDescriptionResourceID = ([regex ]$resourceIdRegexPattern ).match($line ).groups[0 ].value
164+ }
165+ }
166+ }
167+
168+ if (($commandName ) -and ($commandID ))
169+ {
170+ $appendLine = " Result.Add(TRibbonMarkupElement.Create('$commandName ', $commandId , $LabelTitleResourceID , $TooltipTitleResourceID ));"
171+ Add-Content " $workingDir \$markupFileName " " $appendLine "
172+ }
173+
174+ # Add the ending part
175+ $FileEndPart = @"
176+ end;
177+
178+ end.
179+ "@
180+
181+ Add-Content " $workingDir \$markupFileName " $FileEndPart
182+ write-host " Ribbon pascal markup file generation successful: '$markupFileName '"
0 commit comments