最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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
")
...
发布评论

评论列表(0)

  1. 暂无评论