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
1+ # Stop on errors
2+ $ErrorActionPreference = " Stop"
43
4+ $xmlFilePath = $args [0 ]
55
6- # Stop on errors
7- $ErrorActionPreference = " Stop"
6+ # Determine the current working directory from the given xml file path
7+ $workingDir = ([System.IO.Path ]::GetDirectoryName($xmlFilePath ))
8+ if ([string ]::IsNullOrEmpty($workingDir ))
9+ {
10+ $workingDir = " ."
11+ }
12+ $workingDir = $workingDir + ([System.IO.Path ]::DirectorySeparatorChar)
813
9- $appDir = get-location
10- $prefix = $args [0 ]
11- $workingDir = $args [1 ]
12- $RessourceName = $args [2 ]
13- $UICCDir = $args [3 ]
14+ # Prepare file paths for the files that we want to create
15+ $pasFilePath = $workingDir + ([System.IO.Path ]::GetFileNameWithoutExtension($xmlFilePath ) + " .pas" )
16+ $bmlFilePath = $workingDir + ([System.IO.Path ]::GetFileNameWithoutExtension($xmlFilePath ) + " .bml" )
17+ $rcFilePath = $workingDir + ([System.IO.Path ]::GetFileNameWithoutExtension($xmlFilePath ) + " .rc" )
18+ $headerFilePath = $workingDir + ([System.IO.Path ]::GetFileNameWithoutExtension($xmlFilePath ) + " .h" )
19+ $resFileName = ([System.IO.Path ]::GetFileNameWithoutExtension($xmlFilePath ) + " .res" )
20+ $unitName = ([System.IO.Path ]::GetFileNameWithoutExtension($xmlFilePath ))
1421
22+ $RessourceName = $args [1 ]
23+ $UICCDir = $args [2 ]
1524
16- function FindUICCExe ($pUICCDir )
25+ # Checks if a file exists under a given location. If yes, the path to this file is returned. If not, we lookup several known locations and return those, if the file is found.
26+ function FindFileInLocation ($pLocation , $pFileName )
1727{
1828 # First check if a valid path was passed via the command line
19- $lUICCmd = $pUICCDir + " \UICC.exe "
20- if (Test-Path $lUICCmd )
29+ $lPath = $pLocation + " \" + $pFileName
30+ if (Test-Path $lPath )
2131 {
22- return $lUICCmd
32+ return $lPath
2333 }
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 " )
34+ # Check if the file exists under %PATH%
35+ if ( Get-Command $pFileName - ErrorAction SilentlyContinue )
2636 {
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" )
37+ return " $pFileName "
38+ }
39+ # If not, check a few known locations for uicc.exe
40+ elseif (Test-Path " ${env: ProgramFiles(x86)} \Microsoft SDKs\Windows\v7.1A\Bin\$pFileName " )
3041 {
31- return " ${env: ProgramFiles(x86)} \Windows Kits\8.0\bin\x86\uicc.exe "
42+ return " ${env: ProgramFiles(x86)} \Microsoft SDKs\Windows\v7.1A\Bin\ $pFileName "
3243 }
33- elseif (Test-Path " ${env: ProgramFiles(x86)} \Windows Kits\8.1 \bin\x86\uicc.exe " )
44+ elseif (Test-Path " ${env: ProgramFiles(x86)} \Windows Kits\8.0 \bin\x86\$pFileName " )
3445 {
35- return " ${env: ProgramFiles(x86)} \Windows Kits\8.1 \bin\x86\uicc.exe "
46+ return " ${env: ProgramFiles(x86)} \Windows Kits\8.0 \bin\x86\$pFileName "
3647 }
37- # Check %PATH%
38- elseif (Test-Path " UICC.exe" )
48+ elseif (Test-Path " ${env: ProgramFiles(x86)} \Windows Kits\8.1\bin\$pFileName " )
3949 {
40- return " UICC.exe "
41- }
50+ return " ${ env: ProgramFiles(x86)} \Windows Kits\8.1\bin\x86\ $pFileName "
51+ }
4252 else
4353 {
4454 # Nothing found -> exit
45- write " Cannot find UICC.exe ."
55+ write " Cannot find $pFileName . Aborting execution ."
4656 exit
4757 }
4858}
4959
50- $UICCmd = FindUICCExe(" $UICCDir " )
51- write-host " UICC.exe found: Using $UICCmd "
60+ # Find UICC.exe
61+ $UICCCmd = FindFileInLocation - pLocation $UICCDir - pFileName " UICC.exe"
62+ write-host " UICC.exe found: Using $UICCCmd "
5263
64+ # Use the provided xml file to Create the .bml, .h and .rc file
65+ & $UICCCmd " /W0" " $xmlFilePath " " $bmlFilePath " " /header:$headerFilePath " " /res:$rcFilePath " " /name:$RessourceName "
5366
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 "
67+ # Find rc.exe (Use the same locations as UICC.exe)
68+ $RCCmd = FindFileInLocation - pLocation $UICCDir - pFileName " rc.exe"
69+ write-host " RC.exe found: Using $RCCmd "
5670
5771# Create the .RES resource file
58- $rcName = $prefix + " .Ribbon.Markup.rc"
59- rc " $workingDir \$rcName "
72+ rc " $rcFilePath "
6073
6174# Create a new Markup .pas file that will contain the Ribbon command constants.
6275
63- $markupFileName = " $prefix .Ribbon.Markup.pas"
6476[System.Collections.ArrayList ]$markupContent = New-Object ([System.Collections.ArrayList ])
6577
6678$FileTopPart = @"
67- unit $prefix .Ribbon.Markup ;
79+ unit $unitName ;
6880
6981// *****************************************************************************
7082// * This is an automatically generated source file for UI Element definition *
@@ -73,18 +85,19 @@ unit $prefix.Ribbon.Markup;
7385
7486interface
7587
76- {`$ R '$prefix .Ribbon.Markup.res '}
88+ {`$ R '$resFileName '}
7789
7890uses
7991 Generics.Collections, SysUtils, UIRibbon;
8092
8193const
8294"@
83- Set-Content - Path " $workingDir \$markupFileName " - Value $FileTopPart
95+
96+ write-host " Setting content to " + $pasFilePath
97+ Set-Content - Path " $pasFilePath " - Value $FileTopPart
8498
8599# Get content of the header file (e.g. TreeSize.Ribbon.Markup.h).
86- $headerFileName = " $prefix .Ribbon.Markup.h"
87- $data = Get-Content " $workingDir \$headerFileName "
100+ $data = Get-Content " $headerFilePath "
88101
89102foreach ($line in $data )
90103{
@@ -94,7 +107,7 @@ foreach ($line in $data)
94107 $commandId = ([regex ]" \b\d{1,5}\b" ).match($line ).groups[0 ].value
95108 $commandName = ([regex ]" \b\w+\b" ).match($line ).groups[0 ].value
96109 $appendLine = " $commandName = $commandId ;"
97- Add-Content " $workingDir \ $markupFileName " " $appendLine "
110+ Add-Content " $pasFilePath " " $appendLine "
98111 $dummy = $markupContent.Add ($appendLine );
99112 }
100113}
@@ -111,7 +124,7 @@ begin
111124 Result := TRibbonMarkupElementList.Create();
112125"@
113126
114- Add-Content " $workingDir \ $markupFileName " $FileMiddlePart
127+ Add-Content " $pasFilePath " $FileMiddlePart
115128
116129
117130# Add the mapping by using the previously generated markup content
@@ -133,7 +146,7 @@ foreach ($line in $markupContent)
133146 if (($commandName ) -and ($commandID ))
134147 {
135148 $appendLine = " Result.Add(TRibbonMarkupElement.Create('$commandName ', $commandId , $LabelTitleResourceID , $LabelDescriptionResourceID , $TooltipTitleResourceID , $TooltipDescriptionResourceID ));"
136- Add-Content " $workingDir \ $markupFileName " " $appendLine "
149+ Add-Content " $pasFilePath " " $appendLine "
137150 $LabelTitleResourceID = -1
138151 $LabelDescriptionResourceID = -1
139152 $TooltipTitleResourceID = -1
@@ -168,7 +181,7 @@ foreach ($line in $markupContent)
168181if (($commandName ) -and ($commandID ))
169182{
170183 $appendLine = " Result.Add(TRibbonMarkupElement.Create('$commandName ', $commandId , $LabelTitleResourceID , $TooltipTitleResourceID ));"
171- Add-Content " $workingDir \ $markupFileName " " $appendLine "
184+ Add-Content " $pasFilePath " " $appendLine "
172185}
173186
174187# Add the ending part
178191end.
179192"@
180193
181- Add-Content " $workingDir \ $markupFileName " $FileEndPart
182- write-host " Ribbon pascal markup file generation successful: '$markupFileName '"
194+ Add-Content " $pasFilePath " $FileEndPart
195+ write-host " Ribbon pascal markup file generation successful: '$pasFilePath '"
0 commit comments