Skip to content

Commit 166ba23

Browse files
author
sascha.schaefer87
committed
- Generate.Ribbon.Markup.pas.ps1: Improved usability of the script: The only required parameters are now the path to the ribbon XML file and the name of the resource. Additionally, a path to the UICC.exe file can be passed.
- Designer/Classes/RibbonCompiler.pas: The script is now used by the designer to generate the resources. - Designer/FSettings: The edit field to enter a path to the resource compiler executable (rc.exe) has been disabled. It will be searched for in the powershell script automatically at the same location as UICC.exe
1 parent f6494a0 commit 166ba23

File tree

4 files changed

+67
-78
lines changed

4 files changed

+67
-78
lines changed

Designer/Classes/RibbonCompiler.pas

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ implementation
6363

6464
function TRibbonCompiler.Compile(const Document: TRibbonDocument): TRibbonCompileResult;
6565
var
66-
DocDir, BmlFilename, RcFilename, HeaderFilename, DprFilename: String;
67-
PasFilename: String;
66+
DocDir, DprFilename: String;
6867
begin
6968
try
7069
if (Document.Filename = '') or (not TFile.Exists(Document.Filename)) then
@@ -80,22 +79,14 @@ function TRibbonCompiler.Compile(const Document: TRibbonDocument): TRibbonCompil
8079
end;
8180

8281
DoMessage(mkInfo, RS_STARTING_RIBBON_COMPILER);
83-
DocDir := ExtractFilePath(Document.Filename);
84-
BmlFilename := ChangeFileExt(Document.Filename, '.bml');
85-
RcFilename := ChangeFileExt(Document.Filename, '.rc');
86-
HeaderFilename := ChangeFileExt(Document.Filename, '.h');
87-
if (not Execute(TSettings.Instance.RibbonCompilerPath, DocDir,
88-
['"' + Document.Filename + '"', '"' + BmlFilename + '"',
89-
'/res:"' + RcFilename + '"', '/header:"' + HeaderFilename + '"']))
90-
then
91-
Exit(crRibbonCompilerError);
92-
9382
DoMessage(mkInfo, '');
9483
DoMessage(mkInfo, RS_STARTING_RESOURCE_COMPILER);
95-
if (not Execute(TSettings.Instance.ResourceCompilerPath, DocDir,
96-
['"' + RcFilename + '"']))
84+
85+
DocDir := ExtractFilePath(Document.Filename);
86+
87+
if (not Execute('powershell -f D:\Projects\delphi-ribbon-framework\Generate.Ribbon.Markup.pas.ps1', DocDir, [Document.Filename, 'APPLICATION', TSettings.Instance.RibbonCompilerPath]))
9788
then
98-
Exit(crResourceCompilerError);
89+
Exit(crRibbonCompilerError);
9990

10091
DoMessage(mkInfo, RS_STARTING_DELPHI_COMPILER);
10192
DprFilename := ChangeFileExt(Document.Filename, '.dpr');
@@ -105,10 +96,6 @@ function TRibbonCompiler.Compile(const Document: TRibbonDocument): TRibbonCompil
10596
then
10697
Exit(crDelphiCompilerError);
10798

108-
PasFilename := ChangeFileExt(Document.Filename, '.pas');
109-
if (not ConvertHeaderFile(HeaderFilename, PasFilename)) then
110-
Exit(crHeaderConversionError);
111-
11299
DoMessage(mkInfo, '');
113100
FOutputDllPath := ChangeFileExt(DprFilename, '.dll');
114101
if (TFile.Exists(FOutputDllPath)) then

Designer/FSettings.dfm

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,12 @@ object FormSettings: TFormSettings
6363
Top = 48
6464
Width = 370
6565
Height = 21
66-
Images = ImageList
66+
Enabled = False
6767
RightButton.HotImageIndex = 1
6868
RightButton.ImageIndex = 0
6969
RightButton.PressedImageIndex = 1
7070
RightButton.Visible = True
7171
TabOrder = 1
72-
OnChange = EditPathChange
73-
OnRightButtonClick = EditResourceCompilerRightButtonClick
7472
end
7573
object EditDelphiCompiler: TButtonedEdit
7674
Left = 163
@@ -112,7 +110,7 @@ object FormSettings: TFormSettings
112110
Left = 120
113111
Top = 28
114112
Bitmap = {
115-
494C010102000800240010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
113+
494C010102000800280010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
116114
0000000000003600000028000000400000001000000001002000000000000010
117115
0000000000000000000000000000000000000000000000000000000000000000
118116
0000000000000000000000000000000000000000000000000000000000000000

Designer/FSettings.pas

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ TFormSettings = class(TForm)
3232
OpenDialog: TOpenDialog;
3333
procedure EditPathChange(Sender: TObject);
3434
procedure EditRibbonCompilerRightButtonClick(Sender: TObject);
35-
procedure EditResourceCompilerRightButtonClick(Sender: TObject);
3635
procedure EditDelphiCompilerRightButtonClick(Sender: TObject);
3736
procedure FormClose(Sender: TObject; var Action: TCloseAction);
3837
private
@@ -77,15 +76,6 @@ procedure TFormSettings.EditPathChange(Sender: TObject);
7776
UpdateControls;
7877
end;
7978

80-
procedure TFormSettings.EditResourceCompilerRightButtonClick(Sender: TObject);
81-
begin
82-
OpenDialog.Filter := 'RC.exe|RC.exe';
83-
OpenDialog.InitialDir := ExtractFilePath(EditResourceCompiler.Text);
84-
OpenDialog.FileName := ExtractFileName(EditResourceCompiler.Text);
85-
if (OpenDialog.Execute) then
86-
EditResourceCompiler.Text := OpenDialog.FileName;
87-
end;
88-
8979
procedure TFormSettings.EditRibbonCompilerRightButtonClick(Sender: TObject);
9080
begin
9181
OpenDialog.Filter := 'UICC.exe|UICC.exe';
@@ -108,6 +98,7 @@ procedure TFormSettings.FormClose(Sender: TObject; var Action: TCloseAction);
10898

10999
procedure TFormSettings.UpdateControls;
110100
begin
101+
EditResourceCompiler.Text := IncludeTrailingPathDelimiter(ExtractFilePath(EditRibbonCompiler.Text)) + 'RC.exe';
111102
ButtonOk.Enabled :=
112103
TFile.Exists(EditRibbonCompiler.Text) and
113104
TFile.Exists(EditResourceCompiler.Text) and

Generate.Ribbon.Markup.pas.ps1

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,82 @@
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
7486
interface
7587
76-
{`$R '$prefix.Ribbon.Markup.res'}
88+
{`$R '$resFileName'}
7789
7890
uses
7991
Generics.Collections, SysUtils, UIRibbon;
8092
8193
const
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

89102
foreach ($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)
168181
if (($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
@@ -178,5 +191,5 @@ end;
178191
end.
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

Comments
 (0)