Skip to content

Commit b337ce4

Browse files
committed
Provide Bundle Icon in BA container and update wixstdba to use it
Fixes 8104
1 parent 164ea64 commit b337ce4

20 files changed

Lines changed: 188 additions & 24 deletions

File tree

src/ext/Bal/stdbas/WixInternalUIBootstrapperApplication.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,14 +557,19 @@ class CWixInternalUIBootstrapperApplication : public CBootstrapperApplicationBas
557557
HRESULT CreateMainWindow()
558558
{
559559
HRESULT hr = S_OK;
560-
WNDCLASSW wc = { };
560+
WNDCLASSEXW wc = { };
561561
DWORD dwWindowStyle = WS_POPUP;
562562

563+
LoadBundleIcon(m_hModule, &m_hIcon, &m_hSmallIcon);
564+
565+
wc.cbSize = sizeof(WNDCLASSEXW);
563566
wc.lpfnWndProc = CWixInternalUIBootstrapperApplication::WndProc;
564567
wc.hInstance = m_hModule;
565568
wc.lpszClassName = WIXIUIBA_WINDOW_CLASS;
569+
wc.hIcon = m_hIcon;
570+
wc.hIconSm = m_hSmallIcon;
566571

567-
if (!::RegisterClassW(&wc))
572+
if (!::RegisterClassExW(&wc))
568573
{
569574
ExitWithLastError(hr, "Failed to register window.");
570575
}
@@ -601,6 +606,18 @@ class CWixInternalUIBootstrapperApplication : public CBootstrapperApplicationBas
601606
::UnregisterClassW(WIXIUIBA_WINDOW_CLASS, m_hModule);
602607
m_fRegistered = FALSE;
603608
}
609+
610+
if (m_hIcon)
611+
{
612+
::DestroyIcon(m_hIcon);
613+
m_hIcon = NULL;
614+
}
615+
616+
if (m_hSmallIcon)
617+
{
618+
::DestroyIcon(m_hSmallIcon);
619+
m_hSmallIcon = NULL;
620+
}
604621
}
605622

606623
//
@@ -807,6 +824,8 @@ class CWixInternalUIBootstrapperApplication : public CBootstrapperApplicationBas
807824
m_sczFailedMessage = NULL;
808825

809826
m_hUiThread = NULL;
827+
m_hIcon = NULL;
828+
m_hSmallIcon = NULL;
810829
m_fRegistered = FALSE;
811830
m_hWnd = NULL;
812831

@@ -847,6 +866,8 @@ class CWixInternalUIBootstrapperApplication : public CBootstrapperApplicationBas
847866
LPWSTR m_sczConfirmCloseMessage;
848867

849868
HANDLE m_hUiThread;
869+
HICON m_hIcon;
870+
HICON m_hSmallIcon;
850871
BOOL m_fRegistered;
851872
HWND m_hWnd;
852873

src/ext/Bal/stdbas/WixStandardBootstrapperApplication.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,26 +3301,24 @@ class CWixStandardBootstrapperApplication : public CBootstrapperApplicationBase
33013301
HRESULT CreateMainWindow()
33023302
{
33033303
HRESULT hr = S_OK;
3304-
WNDCLASSW wc = { };
3304+
WNDCLASSEXW wc = { sizeof(WNDCLASSEXW)};
33053305
DWORD dwWindowStyle = 0;
33063306
int x = CW_USEDEFAULT;
33073307
int y = CW_USEDEFAULT;
33083308
POINT ptCursor = { };
33093309

3310-
ThemeInitializeWindowClass(m_pTheme, &wc, CWixStandardBootstrapperApplication::WndProc, m_hModule, WIXSTDBA_WINDOW_CLASS);
3310+
ThemeInitializeWindowClassEx(m_pTheme, &wc, CWixStandardBootstrapperApplication::WndProc, m_hModule, WIXSTDBA_WINDOW_CLASS);
33113311

3312-
// If the theme did not provide an icon, try using the icon from the bundle engine.
3312+
// If the theme did not provide an icon, try using the icon from the bundle then fallback to the bundle engine.
33133313
if (!wc.hIcon)
33143314
{
3315-
HMODULE hBootstrapperEngine = ::GetModuleHandleW(NULL);
3316-
if (hBootstrapperEngine)
3317-
{
3318-
wc.hIcon = ::LoadIconW(hBootstrapperEngine, MAKEINTRESOURCEW(1));
3319-
}
3315+
LoadBundleIcon(m_hModule, &m_hIcon, &m_hSmallIcon);
3316+
wc.hIcon = m_hIcon;
3317+
wc.hIconSm = m_hSmallIcon;
33203318
}
33213319

33223320
// Register the window class and create the window.
3323-
if (!::RegisterClassW(&wc))
3321+
if (!::RegisterClassExW(&wc))
33243322
{
33253323
ExitWithLastError(hr, "Failed to register window.");
33263324
}
@@ -3358,7 +3356,6 @@ class CWixStandardBootstrapperApplication : public CBootstrapperApplicationBase
33583356
return hr;
33593357
}
33603358

3361-
33623359
//
33633360
// InitializeTaskbarButton - initializes taskbar button for progress.
33643361
//
@@ -3397,6 +3394,18 @@ class CWixStandardBootstrapperApplication : public CBootstrapperApplicationBase
33973394
::UnregisterClassW(WIXSTDBA_WINDOW_CLASS, m_hModule);
33983395
m_fRegistered = FALSE;
33993396
}
3397+
3398+
if (m_hIcon)
3399+
{
3400+
::DestroyIcon(m_hIcon);
3401+
m_hIcon = NULL;
3402+
}
3403+
3404+
if (m_hSmallIcon)
3405+
{
3406+
::DestroyIcon(m_hSmallIcon);
3407+
m_hSmallIcon = NULL;
3408+
}
34003409
}
34013410

34023411

@@ -4822,6 +4831,8 @@ class CWixStandardBootstrapperApplication : public CBootstrapperApplicationBase
48224831
m_pTheme = NULL;
48234832
memset(m_rgdwPageIds, 0, sizeof(m_rgdwPageIds));
48244833
m_hUiThread = NULL;
4834+
m_hIcon = NULL;
4835+
m_hSmallIcon = NULL;
48254836
m_fRegistered = FALSE;
48264837
m_hWnd = NULL;
48274838

@@ -5110,6 +5121,8 @@ class CWixStandardBootstrapperApplication : public CBootstrapperApplicationBase
51105121
THEME_ASSIGN_CONTROL_ID m_rgInitControls[LAST_WIXSTDBA_CONTROL - WIXSTDBA_FIRST_ASSIGN_CONTROL_ID];
51115122
DWORD m_rgdwPageIds[countof(vrgwzPageNames)];
51125123
HANDLE m_hUiThread;
5124+
HICON m_hIcon;
5125+
HICON m_hSmallIcon;
51135126
BOOL m_fRegistered;
51145127
HWND m_hWnd;
51155128

src/ext/Bal/stdbas/precomp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,9 @@
4242

4343
#include "stdbas.messages.h"
4444
#include "WixStandardBootstrapperApplication.h"
45+
46+
HRESULT LoadBundleIcon(
47+
__in HMODULE hModule,
48+
__out HICON* phIcon,
49+
__out HICON* phSmallIcon
50+
);

src/ext/Bal/stdbas/stdbas.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2+
3+
#include "precomp.h"
4+
5+
static const LPCWSTR WIX_BUNDLE_ICON_FILENAME = L"WixBundle.ico";
6+
7+
8+
//
9+
// LoadBundleIcon - loads the icon that was (optionally) authored in the bundle otherwise use the one embedded in the bootstrapper application.
10+
//
11+
HRESULT LoadBundleIcon(
12+
__in HMODULE hModule,
13+
__out HICON* phIcon,
14+
__out HICON* phSmallIcon
15+
)
16+
{
17+
HRESULT hr = S_OK;
18+
LPWSTR sczIconPath = NULL;
19+
int nIconWidth = ::GetSystemMetrics(SM_CXICON);
20+
int nIconHeight = ::GetSystemMetrics(SM_CYICON);
21+
int nSmallIconWidth = ::GetSystemMetrics(SM_CXSMICON);
22+
int nSmallIconHeight = ::GetSystemMetrics(SM_CYSMICON);
23+
HICON hIcon = NULL;
24+
HICON hSmallIcon = NULL;
25+
26+
// First look for the optional authored bundle icon.
27+
hr = PathRelativeToModule(&sczIconPath, WIX_BUNDLE_ICON_FILENAME, hModule);
28+
ExitOnFailure(hr, "Failed to get path to bundle icon: %ls", WIX_BUNDLE_ICON_FILENAME);
29+
30+
if (FileExistsEx(sczIconPath, NULL))
31+
{
32+
hIcon = reinterpret_cast<HICON>(::LoadImageW(NULL, sczIconPath, IMAGE_ICON, nIconWidth, nIconHeight, LR_LOADFROMFILE));
33+
34+
hSmallIcon = reinterpret_cast<HICON>(::LoadImageW(NULL, sczIconPath, IMAGE_ICON, nSmallIconWidth, nSmallIconHeight, LR_LOADFROMFILE));
35+
}
36+
else // fallback to the first icon resource in the bootstrapper application.
37+
{
38+
hIcon = reinterpret_cast<HICON>(::LoadImageW(hModule, MAKEINTRESOURCEW(1), IMAGE_ICON, nIconWidth, nIconHeight, LR_DEFAULTCOLOR));
39+
40+
hSmallIcon = reinterpret_cast<HICON>(::LoadImageW(hModule, MAKEINTRESOURCEW(1), IMAGE_ICON, nSmallIconWidth, nSmallIconHeight, LR_DEFAULTCOLOR));
41+
}
42+
43+
*phIcon = hIcon;
44+
*phSmallIcon = hSmallIcon;
45+
46+
LExit:
47+
ReleaseStr(sczIconPath);
48+
49+
return hr;
50+
}

src/ext/Bal/stdbas/stdbas.vcxproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<ClCompile Include="precomp.cpp">
6161
<PrecompiledHeader>Create</PrecompiledHeader>
6262
</ClCompile>
63+
<ClCompile Include="stdbas.cpp" />
6364
<ClCompile Include="WixInternalUIBootstrapperApplication.cpp" />
6465
<ClCompile Include="WixStandardBootstrapperApplication.cpp" />
6566
</ItemGroup>
@@ -80,4 +81,4 @@ rc.exe -fo "$(OutDir)stdbas.res" "$(IntDir)stdbas.messages.rc"</Command>
8081
</ItemGroup>
8182

8283
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
83-
</Project>
84+
</Project>

src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/BalExtensionFixture.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public void CanBuildUsingDisplayInternalUICondition()
2424
{
2525
var baseFolder = fs.GetFolder();
2626
var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
27-
var bundleSourceFolder = TestData.Get(@"TestData\WixStdBa");
27+
var bundleSourceFolder = TestData.Get(@"TestData", "WixStdBa");
28+
var dataFolder = TestData.Get(@"TestData", ".Data");
2829
var intermediateFolder = Path.Combine(baseFolder, "obj");
2930
var baFolderPath = Path.Combine(baseFolder, "ba");
3031
var extractFolderPath = Path.Combine(baseFolder, "extract");
@@ -36,6 +37,7 @@ public void CanBuildUsingDisplayInternalUICondition()
3637
"-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
3738
"-intermediateFolder", intermediateFolder,
3839
"-bindpath", Path.Combine(bundleSourceFolder, "data"),
40+
"-bindpath", dataFolder,
3941
"-o", bundleFile,
4042
});
4143
compileResult.AssertSuccess();
@@ -62,7 +64,8 @@ public void CanBuildUsingDisplayFilesInUseDialogCondition()
6264
{
6365
var baseFolder = fs.GetFolder();
6466
var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
65-
var bundleSourceFolder = TestData.Get(@"TestData\WixStdBa");
67+
var bundleSourceFolder = TestData.Get(@"TestData", "WixStdBa");
68+
var dataFolder = TestData.Get(@"TestData", ".Data");
6669
var intermediateFolder = Path.Combine(baseFolder, "obj");
6770
var baFolderPath = Path.Combine(baseFolder, "ba");
6871
var extractFolderPath = Path.Combine(baseFolder, "extract");
@@ -74,6 +77,7 @@ public void CanBuildUsingDisplayFilesInUseDialogCondition()
7477
"-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
7578
"-intermediateFolder", intermediateFolder,
7679
"-bindpath", Path.Combine(bundleSourceFolder, "data"),
80+
"-bindpath", dataFolder,
7781
"-o", bundleFile,
7882
});
7983
compileResult.AssertSuccess();
@@ -101,6 +105,7 @@ public void CanBuildUsingBootstrapperApplicationId()
101105
var baseFolder = fs.GetFolder();
102106
var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
103107
var bundleSourceFolder = TestData.Get("TestData", "WixStdBa");
108+
var dataFolder = TestData.Get(@"TestData", ".Data");
104109
var intermediateFolder = Path.Combine(baseFolder, "obj");
105110
var baFolderPath = Path.Combine(baseFolder, "ba");
106111
var extractFolderPath = Path.Combine(baseFolder, "extract");
@@ -112,6 +117,7 @@ public void CanBuildUsingBootstrapperApplicationId()
112117
"-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
113118
"-intermediateFolder", intermediateFolder,
114119
"-bindpath", Path.Combine(bundleSourceFolder, "data"),
120+
"-bindpath", dataFolder,
115121
"-o", bundleFile,
116122
});
117123
compileResult.AssertSuccess();
@@ -141,7 +147,8 @@ public void CanBuildUsingOverridable()
141147
{
142148
var baseFolder = fs.GetFolder();
143149
var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
144-
var bundleSourceFolder = TestData.Get(@"TestData\Overridable");
150+
var bundleSourceFolder = TestData.Get(@"TestData", "Overridable");
151+
var dataFolder = TestData.Get(@"TestData", ".Data");
145152
var intermediateFolder = Path.Combine(baseFolder, "obj");
146153
var baFolderPath = Path.Combine(baseFolder, "ba");
147154
var extractFolderPath = Path.Combine(baseFolder, "extract");
@@ -152,6 +159,7 @@ public void CanBuildUsingOverridable()
152159
Path.Combine(bundleSourceFolder, "Bundle.wxs"),
153160
"-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
154161
"-intermediateFolder", intermediateFolder,
162+
"-bindpath", dataFolder,
155163
"-o", bundleFile,
156164
});
157165
compileResult.AssertSuccess();
@@ -182,7 +190,8 @@ public void CanBuildUsingWixStdBa()
182190
{
183191
var baseFolder = fs.GetFolder();
184192
var bundleFile = Path.Combine(baseFolder, "bin", "test.exe");
185-
var bundleSourceFolder = TestData.Get(@"TestData\WixStdBa");
193+
var bundleSourceFolder = TestData.Get(@"TestData", "WixStdBa");
194+
var dataFolder = TestData.Get(@"TestData", ".Data");
186195
var intermediateFolder = Path.Combine(baseFolder, "obj");
187196

188197
var compileResult = WixRunner.Execute(new[]
@@ -191,6 +200,7 @@ public void CanBuildUsingWixStdBa()
191200
Path.Combine(bundleSourceFolder, "Bundle.wxs"),
192201
"-ext", TestData.Get(@"WixToolset.BootstrapperApplications.wixext.dll"),
193202
"-intermediateFolder", intermediateFolder,
203+
"-bindpath", dataFolder,
194204
"-o", bundleFile,
195205
});
196206
compileResult.AssertSuccess();
Binary file not shown.

src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/WixStdBa/BootstrapperApplicationId.wxs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
33
xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
4-
<Bundle Name="WixStdBa" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="75D5D534-E177-4689-AAE9-CAC1C39002C2">
4+
<Bundle Name="WixStdBa" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="75D5D534-E177-4689-AAE9-CAC1C39002C2"
5+
IconSourceFile="test.ico">
56
<BootstrapperApplication Id="Custom">
67
<bal:WixStandardBootstrapperApplication LicenseUrl="http://wixtoolset.org/about/license/" Theme="hyperlinkLicense" />
78
</BootstrapperApplication>

src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/WixStdBa/Bundle.wxs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
33
xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
4-
<Bundle Name="WixStdBa" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="75D5D534-E177-4689-AAE9-CAC1C39002C2">
4+
<Bundle Name="WixStdBa" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="75D5D534-E177-4689-AAE9-CAC1C39002C2"
5+
IconSourceFile="test.ico">
56
<BootstrapperApplication>
67
<bal:WixStandardBootstrapperApplication LicenseUrl="http://wixtoolset.org/about/license/" Theme="hyperlinkLicense" />
78
</BootstrapperApplication>

src/ext/Bal/test/WixToolsetTest.BootstrapperApplications/TestData/WixStdBa/DisplayFilesInUseDialogConditionBundle.wxs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
33
xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
4-
<Bundle Name="WixStdBa" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="75D5D534-E177-4689-AAE9-CAC1C39002C2">
4+
<Bundle Name="WixStdBa" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="75D5D534-E177-4689-AAE9-CAC1C39002C2"
5+
IconSourceFile="test.ico">
56
<BootstrapperApplication>
67
<bal:WixStandardBootstrapperApplication LicenseUrl="http://wixtoolset.org/about/license/" Theme="hyperlinkLicense" />
78
</BootstrapperApplication>

0 commit comments

Comments
 (0)