c++ - NSIS configuration through cmake fails to set double quotes correctly - Stack Overflow

I am new to NSIS I am trying to add two install commands that will add registry values for my app, the

I am new to NSIS I am trying to add two install commands that will add registry values for my app, the end goal is for those values to look like this: "path\to\executable" "%1"

The problem is that NSIS does not accept any format for this end result:

set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
  WriteRegStr HKCR '.acmi\\OpenWithProgids' 'MyApp.myext' ''
  WriteRegStr HKCR 'Applications\\MyApp.exe\\shell\\open\\command' '' '\"$INSTDIR\\bin\\MyApp.exe\" \"%1\"'
")

This results into the weird value ;$INSTDIR\bin\MyApp.exe" "%1; where the first and last " are turned into ;

set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
  WriteRegStr HKCR '.acmi\\OpenWithProgids' 'MyApp.myext' ''
  WriteRegStr HKCR 'Applications\\MyApp.exe\\shell\\open\\command' '' '\\\"$INSTDIR\\bin\\MyApp.exe\" \"%1\\\"'
")

This will do "$INSTDIR\bin\MyApp.exe;%1" so again the first and last unescaped " will turn into ; and also I have the extra \ at the beggining and end

set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
  WriteRegStr HKCR '.acmi\\OpenWithProgids' 'MyApp.myext' ''
  WriteRegStr HKCR 'Applications\\MyApp.exe\\shell\\open\\command' '' '\\\"$INSTDIR\\bin\\MyApp.exe\\\" \\\"%1\\\"'
")

Escaping all " will result in no ; but the exta \ will still break the path...

What should be done to get the wanted end result? "path\to\executable" "%1"


EDIT:

For anyone following in the future what worked is moving the WriteRegStr commands to a separate .nsh file and set CPACK_NSIS_EXTRA_INSTALL_COMMANDS to include the file

NSIS_registry.nsh

WriteRegStr HKCR ".acmi\OpenWithProgids" "MyApp.myext" ""
WriteRegStr HKCR "Applications\MyApp.exe\shell\open\command" "" '"$INSTDIR\bin\MyApp.exe" "%1"'

CMakeLists.txt

...
set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "
    !include ${CMAKE_SOURCE_DIR}\\NSIS_registry.nsh
")
...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744824726a4595724.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信