[BOOTDATA][CMAKE][MKSHELLLINK] Improve shell link shortcuts creation for the LiveImage (#8936)

CORE-15156, CORE-19691, CORE-19692

Finally get rid of the livecd_start.cmd hack introduced waaaay back
in commit ff6d7b0236 (r54514)!
See also commits ea682b6909 (r54512) and 71867403fd (r54513).

For target paths, use the shell "special shell folder" syntax:
`shell:windows\...` or `shell:system\...`, introduced in commit
7b081be46d (PR #7158) by Whindmar Saksit.

Specify an explicit icon path and index for the "Read Me.lnk" shortcut.

Includes ideas from PR #7154 by Katayama Hirofumi MZ.

The generated shell links are confirmed to work on ReactOS, but also on
Windows 2003 and Windows 7.

- Change the MKSHELLLINK icon parameter syntax to be: `-i [icon_path[,nr]]`
  where, either both `icon_path` and icon index are given, separated by
  a comma ',' , or, either the `icon_path` is given but the index is
  optional (default: 0), or, only the icon index is given, in which case
  the icon path is set to the target instead.

- Use a `VERBATIM` command-line for `add_custom_command()`, so that *nix
  builds can cope with parameters containing backslashes.

- The shortcut target path, working directory, command-line arguments,
  and icon path all may specify explicit Win32 environment variables
  (like `%SystemRoot%`, `%HOMEDRIVE%`, etc.). Because these environment
  variables are specified as data given to the build tool via CMake,
  **AND** we have to workaround keeping these variables unexpanded when
  they are transmitted to the tool via CMD.EXE (on builds made on Windows),
  specify these variables in an "escaped" format, using `^%` instead:
  `^%SystemRoot^%`, etc.
  Additionally these paths may be explicitly quoted and passed that way
  to the MKSHELLLINK tool.

  In order to deal with both unquoting the strings and unescaping the
  environment variables, introduce a helper function and invoke them on
  the aforementioned strings.
This commit is contained in:
Hermès Bélusca-Maïto
2026-05-13 22:16:07 +02:00
parent bc70254ad9
commit a46e1e96ec
4 changed files with 230 additions and 54 deletions
+113 -31
View File
@@ -59,13 +59,26 @@ add_cd_file(FILE ${CMAKE_CURRENT_SOURCE_DIR}/livecd/unattend.inf DESTINATION rea
# LiveImage shortcuts
add_custom_target(livecd_links)
function(add_livecd_shortcut name app)
cmake_parse_arguments(_shortcut "" "" "DESTINATION" ${ARGN})
function(add_livecd_shortcut name path)
cmake_parse_arguments(_shortcut "" "WORKDIR;CMDLINE_ARGS;ICON;ICON_INDEX" "DESTINATION" ${ARGN})
if(NOT _shortcut_DESTINATION)
message(FATAL_ERROR "You must provide at least one destination")
endif()
add_link(${name} livecd_start.cmd GUID "{450D8FBA-AD25-11D0-98A8-0800361B1103}" CMD_LINE_ARGS ${app} ICON ${app} MINIMIZE)
if(DEFINED _shortcut_WORKDIR)
set(_shortcut_WORKDIR WORKDIR "${_shortcut_WORKDIR}")
endif()
if(DEFINED _shortcut_CMDLINE_ARGS)
set(_shortcut_CMDLINE_ARGS CMDLINE_ARGS "${_shortcut_CMDLINE_ARGS}")
endif()
if(DEFINED _shortcut_ICON)
set(_shortcut_ICON ICON "${_shortcut_ICON}")
endif()
if(DEFINED _shortcut_ICON_INDEX)
set(_shortcut_ICON_INDEX ICON_INDEX ${_shortcut_ICON_INDEX})
endif()
add_link(${name} ${path} ${_shortcut_WORKDIR} ${_shortcut_CMDLINE_ARGS} ${_shortcut_ICON} ${_shortcut_ICON_INDEX})
# Only on CMake 3.20+: target_sources(livecd_links PRIVATE ...)
set_property(TARGET livecd_links APPEND PROPERTY SOURCES "${CMAKE_CURRENT_BINARY_DIR}/${name}.lnk")
@@ -80,7 +93,14 @@ endfunction()
## NOTE: What would be nice is to create this list using /media/inf/shortcuts.inf
## and taking their default english translation!
add_cd_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/livecd_start.cmd" DESTINATION "Profiles/Default User/My Documents" FOR livecd)
set(env_percent "%")
# Win32: Use pseudo-escapes '^%' to work-around variables expansion by CMD.EXE
if (CMAKE_HOST_WIN32)
set(env_percent "^%")
endif()
set(envvar_systemroot "${env_percent}SystemRoot${env_percent}")
set(envvar_homedrive "${env_percent}HOMEDRIVE${env_percent}")
set(envvar_homepath "${env_percent}HOMEPATH${env_percent}")
set(dir_allusers_desktop "Profiles/All Users/Desktop")
set(dir_startmenu_programs "Profiles/All Users/Start Menu/Programs")
@@ -93,32 +113,94 @@ set(dir_startmenu_entertainment "${dir_startmenu_accessories}/Entertainment")
set(dir_startmenu_systemtools "${dir_startmenu_accessories}/System Tools")
set(dir_quicklaunch "Profiles/Default User/Application Data/Microsoft/Internet Explorer/Quick Launch")
add_livecd_shortcut("Read Me" readme.txt DESTINATION "${dir_allusers_desktop}")
add_livecd_shortcut("ReactOS Explorer" explorer.exe
add_livecd_shortcut("Read Me"
"shell:windows\\readme.txt"
ICON "${envvar_systemroot}\\system32\\shell32.dll" ICON_INDEX -152
DESTINATION "${dir_allusers_desktop}")
add_livecd_shortcut("ReactOS Explorer"
"shell:windows\\explorer.exe" ICON_INDEX 1
WORKDIR "${envvar_homedrive}${envvar_homepath}"
DESTINATION "${dir_startmenu_programs}" "${dir_quicklaunch}")
add_livecd_shortcut("Command Prompt" cmd.exe
add_livecd_shortcut("Command Prompt"
"shell:system\\cmd.exe" ICON_INDEX 0
WORKDIR "${envvar_homedrive}${envvar_homepath}"
DESTINATION "${dir_allusers_desktop}" "${dir_startmenu_accessories}" "${dir_quicklaunch}")
add_livecd_shortcut("Device Manager" devmgmt.exe DESTINATION "${dir_startmenu_admintools}")
add_livecd_shortcut("Event Viewer" eventvwr.exe DESTINATION "${dir_startmenu_admintools}")
add_livecd_shortcut("Service Manager" servman.exe DESTINATION "${dir_startmenu_admintools}")
add_livecd_shortcut("System Configuration" msconfig.exe DESTINATION "${dir_startmenu_admintools}")
add_livecd_shortcut("Accessibility Utility Manager" utilman.exe DESTINATION "${dir_startmenu_accessibility}")
add_livecd_shortcut("Magnify" magnify.exe DESTINATION "${dir_startmenu_accessibility}")
add_livecd_shortcut("On-Screen Keyboard" osk.exe DESTINATION "${dir_startmenu_accessibility}")
add_livecd_shortcut("Remote Desktop Connection" mstsc.exe DESTINATION "${dir_startmenu_comms}")
add_livecd_shortcut("Multimedia Player" mplay32.exe DESTINATION "${dir_startmenu_entertainment}")
add_livecd_shortcut("Sound Recorder" sndrec32.exe DESTINATION "${dir_startmenu_entertainment}")
add_livecd_shortcut("Volume Control" sndvol32.exe DESTINATION "${dir_startmenu_entertainment}")
add_livecd_shortcut("Character Map" charmap.exe DESTINATION "${dir_startmenu_systemtools}")
add_livecd_shortcut("Clipboard Viewer" clipbrd.exe DESTINATION "${dir_startmenu_systemtools}")
add_livecd_shortcut("Keyboard Layout Switcher" kbswitch.exe DESTINATION "${dir_startmenu_systemtools}")
add_livecd_shortcut("ReactX Diagnostic" dxdiag.exe DESTINATION "${dir_startmenu_systemtools}")
add_livecd_shortcut("Registry Editor" regedit.exe DESTINATION "${dir_startmenu_systemtools}")
add_livecd_shortcut("Task Manager" taskmgr.exe DESTINATION "${dir_startmenu_systemtools}")
add_livecd_shortcut("Calculator" calc.exe DESTINATION "${dir_startmenu_accessories}")
add_livecd_shortcut("Paint" mspaint.exe DESTINATION "${dir_startmenu_accessories}")
add_livecd_shortcut("Notepad" notepad.exe DESTINATION "${dir_startmenu_accessories}")
add_livecd_shortcut("WordPad" wordpad.exe DESTINATION "${dir_startmenu_accessories}")
add_livecd_shortcut("Solitaire" sol.exe DESTINATION "${dir_startmenu_games}")
add_livecd_shortcut("Spider Solitaire" spider.exe DESTINATION "${dir_startmenu_games}")
add_livecd_shortcut("WineMine" winmine.exe DESTINATION "${dir_startmenu_games}")
add_livecd_shortcut("Device Manager"
"shell:system\\devmgmt.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_admintools}")
add_livecd_shortcut("Event Viewer"
"shell:system\\eventvwr.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_admintools}")
add_livecd_shortcut("Service Manager"
"shell:system\\servman.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_admintools}")
add_livecd_shortcut("System Configuration"
"shell:system\\msconfig.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_admintools}")
add_livecd_shortcut("Accessibility Utility Manager"
"shell:system\\utilman.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_accessibility}")
add_livecd_shortcut("Magnify"
"shell:system\\magnify.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_accessibility}")
add_livecd_shortcut("On-Screen Keyboard"
"shell:system\\osk.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_accessibility}")
add_livecd_shortcut("Remote Desktop Connection"
"shell:system\\mstsc.exe" ICON_INDEX 0
WORKDIR "${envvar_homedrive}${envvar_homepath}"
DESTINATION "${dir_startmenu_comms}")
add_livecd_shortcut("Multimedia Player"
"shell:system\\mplay32.exe" ICON_INDEX 0
WORKDIR "${envvar_homedrive}${envvar_homepath}"
DESTINATION "${dir_startmenu_entertainment}")
add_livecd_shortcut("Sound Recorder"
"shell:system\\sndrec32.exe" ICON_INDEX 0
WORKDIR "${envvar_homedrive}${envvar_homepath}"
DESTINATION "${dir_startmenu_entertainment}")
add_livecd_shortcut("Volume Control"
"shell:system\\sndvol32.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_entertainment}")
add_livecd_shortcut("Character Map"
"shell:system\\charmap.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_systemtools}")
add_livecd_shortcut("Clipboard Viewer"
"shell:system\\clipbrd.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_systemtools}")
add_livecd_shortcut("Keyboard Layout Switcher"
"shell:system\\kbswitch.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_systemtools}")
add_livecd_shortcut("ReactX Diagnostic"
"shell:system\\dxdiag.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_systemtools}")
add_livecd_shortcut("Registry Editor"
"shell:windows\\regedit.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_systemtools}")
add_livecd_shortcut("Task Manager"
"shell:system\\taskmgr.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_systemtools}")
add_livecd_shortcut("Calculator"
"shell:system\\calc.exe" ICON_INDEX 0
WORKDIR "${envvar_homedrive}${envvar_homepath}"
DESTINATION "${dir_startmenu_accessories}")
add_livecd_shortcut("Paint"
"shell:system\\mspaint.exe" ICON_INDEX 0
WORKDIR "${envvar_homedrive}${envvar_homepath}"
DESTINATION "${dir_startmenu_accessories}")
add_livecd_shortcut("Notepad"
"shell:system\\notepad.exe" ICON_INDEX 0
WORKDIR "${envvar_homedrive}${envvar_homepath}"
DESTINATION "${dir_startmenu_accessories}")
add_livecd_shortcut("WordPad"
"shell:system\\wordpad.exe" ICON_INDEX 0
WORKDIR "${envvar_homedrive}${envvar_homepath}"
DESTINATION "${dir_startmenu_accessories}")
add_livecd_shortcut("Solitaire"
"shell:system\\sol.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_games}")
add_livecd_shortcut("Spider Solitaire"
"shell:system\\spider.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_games}")
add_livecd_shortcut("WineMine"
"shell:system\\winmine.exe" ICON_INDEX 0
DESTINATION "${dir_startmenu_games}")
-1
View File
@@ -1 +0,0 @@
@start %1