Skip to content

Commit 4fface4

Browse files
committed
feat: prompt user to install vs redistributable during install
Signed-off-by: Evzen Gasta <evzen.ml@seznam.cz>
1 parent c628468 commit 4fface4

File tree

3 files changed

+225
-2
lines changed

3 files changed

+225
-2
lines changed

WINDOWS.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ You can build Fedora Media Writer yourself. It has just a few dependencies and b
2929
### Dependencies
3030

3131
* `Qt6` (`qtbase`, `qtdeclarative`, `qtsvg` and `qtquickcontrols2`) - already part of the installer
32-
* `Microsoft Visual C++ Redistributable` for C++ (MSVC) runtime libraries
32+
* `Microsoft Visual C++ Redistributable` for C++ (MSVC) runtime libraries - the installer will prompt you to install this if it's not already on your system
3333

3434
### Steps
3535

@@ -42,4 +42,35 @@ make
4242

4343
### Crosscompilation
4444

45-
There is also the [build.sh](/dist/win/build.sh) script included that I use for building a the installer for distribution on this site. It should do everything automatically if you're in Fedora. There are instructions on how to use it inside at the top of the file
45+
There is also the [build.sh](/dist/win/build.sh) script included that I use for building a the installer for distribution on this site. It should do everything automatically if you're in Fedora. There are instructions on how to use it inside at the top of the file.
46+
47+
#### Visual C++ Redistributable Installation
48+
49+
The installer handles the [Microsoft Visual C++ Redistributable (2015-2022)](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170) installation on-demand, which is required for the application to run.
50+
51+
**How it works:**
52+
1. During installation, the installer checks if VC++ Redistributable is already installed
53+
2. If not installed, it prompts the user with a Yes/No dialog:
54+
```
55+
Microsoft Visual C++ Redistributable is not installed on your system.
56+
57+
It is required for Fedora Media Writer to run properly.
58+
59+
Would you like to download and install it now? (approximately 25 MB)
60+
```
61+
3. If the user chooses **"Yes"**:
62+
- Downloads `vc_redist.x64.exe` from Microsoft's official servers
63+
- Installs it automatically with a progress bar (`/passive` mode)
64+
- Cleans up the downloaded file
65+
4. If the user chooses **"No"**:
66+
- Shows a message with a direct download link for manual installation later
67+
68+
**Benefits:**
69+
- Smaller installer size (no bundled redistributable)
70+
- Only downloads when needed
71+
- Always gets the latest version from Microsoft
72+
- Requires internet connection during installation if VC++ is not already installed
73+
74+
**Manual installation:**
75+
If you prefer to install it separately or if the download fails, you can download it manually from:
76+
https://aka.ms/vs/17/release/vc_redist.x64.exe

dist/win/mediawriter.nsi

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
!include "MUI2.nsh"
2+
!include LogicLib.nsh
3+
!include nsDialogs.nsh
4+
!include WinMessages.nsh
25
ManifestDPIAware true
36
XPStyle on
47

@@ -18,6 +21,10 @@ XPStyle on
1821
!define DESCRIPTION "Tool to write Fedora images to flash drives"
1922
!define FULLVERSION "${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}.0"
2023

24+
# VC++ Redistributable configuration
25+
!define VCREDIST_FILE "vc_redist.x64.exe"
26+
!define VCREDIST_URL "https://aka.ms/vs/17/release/vc_redist.x64.exe"
27+
2128
Name "${APPNAME}"
2229
Caption "${APPNAME} ${FULLVERSION}"
2330

@@ -87,6 +94,10 @@ Icon "../../src/app/data/icons/mediawriter.ico"
8794

8895
!define MUI_ICON ../../src/app/data/icons/mediawriter.ico
8996

97+
# VC++ Redistributable configuration
98+
!define VCREDIST_FILE "vc_redist.x64.exe"
99+
!define VCREDIST_URL "https://aka.ms/vs/17/release/vc_redist.x64.exe"
100+
90101
!insertmacro MUI_PAGE_LICENSE "../../build/app/release/LICENSE.GPL-2.txt"
91102
!insertmacro MUI_PAGE_DIRECTORY
92103
!insertmacro MUI_PAGE_INSTFILES
@@ -268,6 +279,12 @@ LangString AdmingRightsRequired ${LANG_TURKISH} "Admin rights requi
268279
LangString AdmingRightsRequired ${LANG_UKRAINIAN} "Admin rights required!"
269280
LangString AdmingRightsRequired ${LANG_UZBEK} "Admin rights required!"
270281

282+
LangString VCRedistNotInstalled ${LANG_ENGLISH} "Microsoft Visual C++ Redistributable is not installed on your system.$\n$\nIt is required for ${APPNAME} to run properly.$\n$\nWould you like to download and install it now? (approximately 25 MB)"
283+
LangString VCRedistDownloading ${LANG_ENGLISH} "Downloading Microsoft Visual C++ Redistributable..."
284+
LangString VCRedistInstalling ${LANG_ENGLISH} "Installing Microsoft Visual C++ Redistributable..."
285+
LangString VCRedistDownloadFailed ${LANG_ENGLISH} "Failed to download Visual C++ Redistributable.$\n$\nPlease check your internet connection and try again,$\nor download it manually from:$\nhttps://aka.ms/vs/17/release/vc_redist.x64.exe"
286+
LangString VCRedistSkipped ${LANG_ENGLISH} "You have chosen to skip the Visual C++ Redistributable installation.$\n$\n${APPNAME} may not work correctly without it.$\n$\nYou can download it manually from:$\nhttps://aka.ms/vs/17/release/vc_redist.x64.exe"
287+
271288
!macro VerifyUserIsAdmin
272289
UserInfo::GetAccountType
273290
pop $0
@@ -278,6 +295,44 @@ ${If} $0 != "admin" ;Require admin rights on NT4+
278295
${EndIf}
279296
!macroend
280297

298+
; Function to detect if VC++ Redistributable 2015-2022 is installed
299+
; Returns: 1 if installed, 0 if not installed (in $R0)
300+
Function CheckVCRedist
301+
Push $0
302+
Push $1
303+
304+
; Default to not installed
305+
StrCpy $R0 "0"
306+
307+
ClearErrors
308+
; Check the primary registry location for x64 VC++ 2015-2022
309+
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" "Installed"
310+
${If} $0 == "1"
311+
StrCpy $R0 "1"
312+
Goto vcredist_check_done
313+
${EndIf}
314+
315+
ClearErrors
316+
; Check alternative registry location
317+
ReadRegStr $0 HKLM "SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" "Installed"
318+
${If} $0 == "1"
319+
StrCpy $R0 "1"
320+
Goto vcredist_check_done
321+
${EndIf}
322+
323+
ClearErrors
324+
; Check older registry location
325+
ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\DevDiv\VC\Servicing\14.0\RuntimeMinimum" "Install"
326+
${If} $1 == "1"
327+
StrCpy $R0 "1"
328+
Goto vcredist_check_done
329+
${EndIf}
330+
331+
vcredist_check_done:
332+
Pop $1
333+
Pop $0
334+
FunctionEnd
335+
281336
function .onInit
282337
!ifdef INNER
283338

@@ -311,6 +366,50 @@ section "install"
311366
; this packages the signed uninstaller
312367
File ../../build/wineprefix/drive_c/uninstall.exe
313368
!endif
369+
370+
; Check and prompt user to install VC++ Redistributable if needed
371+
DetailPrint "Checking for Visual C++ Redistributable..."
372+
Call CheckVCRedist
373+
DetailPrint "VC++ Redistributable check result: $R0"
374+
375+
${If} $R0 == "0"
376+
; VC++ not installed - ask user
377+
MessageBox MB_YESNO|MB_ICONQUESTION "$(VCRedistNotInstalled)" IDYES download_vcredist IDNO skip_vcredist
378+
379+
download_vcredist:
380+
DetailPrint "User chose to install VC++ Redistributable"
381+
SetOutPath "$TEMP"
382+
383+
DetailPrint "$(VCRedistDownloading)"
384+
DetailPrint "Downloading from: ${VCREDIST_URL}"
385+
DetailPrint "Saving to: $TEMP\${VCREDIST_FILE}"
386+
387+
; Try to use inetc plugin (modern, shows progress)
388+
inetc::get /CAPTION "Downloading Visual C++ Redistributable..." /CANCELTEXT "Cancel" "${VCREDIST_URL}" "$TEMP\${VCREDIST_FILE}" /END
389+
Pop $0
390+
391+
${If} $0 == "OK"
392+
DetailPrint "Download successful"
393+
DetailPrint "$(VCRedistInstalling)"
394+
ExecWait '"$TEMP\${VCREDIST_FILE}" /install /passive /norestart' $1
395+
DetailPrint "Installation returned code: $1"
396+
Delete "$TEMP\${VCREDIST_FILE}"
397+
Goto vcredist_done
398+
${Else}
399+
DetailPrint "Download failed with error: $0"
400+
MessageBox MB_OK|MB_ICONEXCLAMATION "$(VCRedistDownloadFailed)"
401+
Goto vcredist_done
402+
${EndIf}
403+
404+
skip_vcredist:
405+
DetailPrint "User chose to skip VC++ Redistributable installation"
406+
MessageBox MB_OK|MB_ICONEXCLAMATION "$(VCRedistSkipped)"
407+
408+
vcredist_done:
409+
DetailPrint "VC++ Redistributable check/install completed"
410+
${Else}
411+
DetailPrint "Visual C++ Redistributable is already installed"
412+
${EndIf}
314413

315414
# Start Menu
316415
createShortCut "$SMPROGRAMS\${APPNAME}.lnk" "$INSTDIR\mediawriter.exe" "" "$INSTDIR\mediawriter.ico"

dist/win/mediawriter_native.nsi

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
!include "MUI2.nsh"
2+
!include "nsDialogs.nsh"
23
ManifestDPIAware true
34
XPStyle on
45

@@ -87,6 +88,10 @@ Icon "../../src/app/data/icons/mediawriter.ico"
8788

8889
!define MUI_ICON ../../src/app/data/icons/mediawriter.ico
8990

91+
# VC++ Redistributable configuration
92+
!define VCREDIST_FILE "vc_redist.x64.exe"
93+
!define VCREDIST_URL "https://aka.ms/vs/17/release/vc_redist.x64.exe"
94+
9095
!insertmacro MUI_PAGE_LICENSE "../../build/app/release/LICENSE.GPL-2.txt"
9196
!insertmacro MUI_PAGE_DIRECTORY
9297
!insertmacro MUI_PAGE_INSTFILES
@@ -268,6 +273,12 @@ LangString AdmingRightsRequired ${LANG_TURKISH} "Admin rights requi
268273
LangString AdmingRightsRequired ${LANG_UKRAINIAN} "Admin rights required!"
269274
LangString AdmingRightsRequired ${LANG_UZBEK} "Admin rights required!"
270275

276+
LangString VCRedistNotInstalled ${LANG_ENGLISH} "Microsoft Visual C++ Redistributable is not installed on your system.$\n$\nIt is required for ${APPNAME} to run properly.$\n$\nWould you like to download and install it now? (approximately 25 MB)"
277+
LangString VCRedistDownloading ${LANG_ENGLISH} "Downloading Microsoft Visual C++ Redistributable..."
278+
LangString VCRedistInstalling ${LANG_ENGLISH} "Installing Microsoft Visual C++ Redistributable..."
279+
LangString VCRedistDownloadFailed ${LANG_ENGLISH} "Failed to download Visual C++ Redistributable.$\n$\nPlease check your internet connection and try again,$\nor download it manually from:$\nhttps://aka.ms/vs/17/release/vc_redist.x64.exe"
280+
LangString VCRedistSkipped ${LANG_ENGLISH} "You have chosen to skip the Visual C++ Redistributable installation.$\n$\n${APPNAME} may not work correctly without it.$\n$\nYou can download it manually from:$\nhttps://aka.ms/vs/17/release/vc_redist.x64.exe"
281+
271282
!macro VerifyUserIsAdmin
272283
UserInfo::GetAccountType
273284
pop $0
@@ -278,6 +289,44 @@ ${If} $0 != "admin" ;Require admin rights on NT4+
278289
${EndIf}
279290
!macroend
280291

292+
; Function to detect if VC++ Redistributable 2015-2022 is installed
293+
; Returns: 1 if installed, 0 if not installed (in $R0)
294+
Function CheckVCRedist
295+
Push $0
296+
Push $1
297+
298+
; Default to not installed
299+
StrCpy $R0 "0"
300+
301+
ClearErrors
302+
; Check the primary registry location for x64 VC++ 2015-2022
303+
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" "Installed"
304+
${If} $0 == "1"
305+
StrCpy $R0 "1"
306+
Goto vcredist_check_done
307+
${EndIf}
308+
309+
ClearErrors
310+
; Check alternative registry location
311+
ReadRegStr $0 HKLM "SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" "Installed"
312+
${If} $0 == "1"
313+
StrCpy $R0 "1"
314+
Goto vcredist_check_done
315+
${EndIf}
316+
317+
ClearErrors
318+
; Check older registry location
319+
ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\DevDiv\VC\Servicing\14.0\RuntimeMinimum" "Install"
320+
${If} $1 == "1"
321+
StrCpy $R0 "1"
322+
Goto vcredist_check_done
323+
${EndIf}
324+
325+
vcredist_check_done:
326+
Pop $1
327+
Pop $0
328+
FunctionEnd
329+
281330
function .onInit
282331
!ifdef INNER
283332

@@ -311,6 +360,50 @@ section "install"
311360
; this packages the signed uninstaller
312361
File c:\uninstall.exe
313362
!endif
363+
364+
; Check and prompt user to install VC++ Redistributable if needed
365+
DetailPrint "Checking for Visual C++ Redistributable..."
366+
Call CheckVCRedist
367+
DetailPrint "VC++ Redistributable check result: $R0"
368+
369+
${If} $R0 == "0"
370+
; VC++ not installed - ask user
371+
MessageBox MB_YESNO|MB_ICONQUESTION "$(VCRedistNotInstalled)" IDYES download_vcredist IDNO skip_vcredist
372+
373+
download_vcredist:
374+
DetailPrint "User chose to install VC++ Redistributable"
375+
SetOutPath "$TEMP"
376+
377+
DetailPrint "$(VCRedistDownloading)"
378+
DetailPrint "Downloading from: ${VCREDIST_URL}"
379+
DetailPrint "Saving to: $TEMP\${VCREDIST_FILE}"
380+
381+
; Try to use inetc plugin (modern, shows progress)
382+
inetc::get /CAPTION "Downloading Visual C++ Redistributable..." /CANCELTEXT "Cancel" "${VCREDIST_URL}" "$TEMP\${VCREDIST_FILE}" /END
383+
Pop $0
384+
385+
${If} $0 == "OK"
386+
DetailPrint "Download successful"
387+
DetailPrint "$(VCRedistInstalling)"
388+
ExecWait '"$TEMP\${VCREDIST_FILE}" /install /passive /norestart' $1
389+
DetailPrint "Installation returned code: $1"
390+
Delete "$TEMP\${VCREDIST_FILE}"
391+
Goto vcredist_done
392+
${Else}
393+
DetailPrint "Download failed with error: $0"
394+
MessageBox MB_OK|MB_ICONEXCLAMATION "$(VCRedistDownloadFailed)"
395+
Goto vcredist_done
396+
${EndIf}
397+
398+
skip_vcredist:
399+
DetailPrint "User chose to skip VC++ Redistributable installation"
400+
MessageBox MB_OK|MB_ICONEXCLAMATION "$(VCRedistSkipped)"
401+
402+
vcredist_done:
403+
DetailPrint "VC++ Redistributable check/install completed"
404+
${Else}
405+
DetailPrint "Visual C++ Redistributable is already installed"
406+
${EndIf}
314407

315408
# Start Menu
316409
createShortCut "$SMPROGRAMS\${APPNAME}.lnk" "$INSTDIR\mediawriter.exe" "" "$INSTDIR\mediawriter.ico"

0 commit comments

Comments
 (0)