我第二次致电ReadINIStr怎么了?

时间:2019-05-30 16:18:35

标签: nsis

我是NSIS的新手。尝试构建一些示例,以帮助理解最终要构建的生产安装程序中要使用的技术...

我想构建一个无提示安装程序,该程序从具有多个部分的.INI文件中获取其参数。要在安装程序的命令行中指定该部分。

所以,我有这个NSIS-TEST.INI文件:

[PROD]
PATHONE=c:\Folder\Foo
AppName=My little stupid app

想法是使用这样的命令行:

FooSetup config=prod

NSIS-TEST.NSI的实际设置为:

; Script generated by the HM NIS Edit Script Wizard.
var /global REGAPPKEY
var /global PRODUCT_DIR_REGKEY
; HM NIS Edit Wizard helper defines
!define REG_APPKEY ""
!define config "PROD"
!define PATHONE ""
!define PRODUCT_NAME "foo"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "foo"
!define PRODUCT_WEB_SITE "http://www.example.com"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"

OutFile "FooSetup.exe"
InstallDir "c:\foo-goo"
Icon "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
;SilentInstall silent
;SilentUninstall silent
;InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""

Section -aHauptgruppe SEC01

ReadINIStr $REGAPPKEY $INSTDIR\nsis-test.ini  ${config} "AppName"

ReadINIStr $PATHONE $INSTDIR\nsis-test.ini ${config} "PATHONE"


;MessageBox MB_ICONINFORMATION|MB_OK "config=${config}"


  ;SetOutPath "$INSTDIR"
  ;SetOverwrite ifnewer
;  File "..\..\..\pfad\zur\datei\AppMainExe.exe"
 ; CreateDirectory "$SMPROGRAMS\foo"
 ; CreateShortCut "$SMPROGRAMS\foo\foo.lnk" "$INSTDIR\AppMainExe.exe"
 ; CreateShortCut "$DESKTOP\foo.lnk" "$INSTDIR\AppMainExe.exe"
 ; File "..\..\..\path\to\file\Example.file"
SectionEnd

Section -AdditionalIcons
  WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
  CreateShortCut "$SMPROGRAMS\foo\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
  CreateShortCut "$SMPROGRAMS\foo\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  ;WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\AppMainExe.exe"
  ;WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
  ;WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
  ;WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\AppMainExe.exe"
  ;WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
  ;WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
  ;WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd


Function un.onUninstSuccess
  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) wurde erfolgreich deinstalliert."
FunctionEnd

Function un.onInit
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "M�chten Sie $(^Name) und alle seinen Komponenten deinstallieren?" IDYES +2
  Abort
FunctionEnd

Section Uninstall
  Delete "$INSTDIR\${PRODUCT_NAME}.url"
  Delete "$INSTDIR\uninst.exe"
  Delete "$INSTDIR\Example.file"
  Delete "$INSTDIR\AppMainExe.exe"

  Delete "$SMPROGRAMS\foo\Uninstall.lnk"
  Delete "$SMPROGRAMS\foo\Website.lnk"
  Delete "$DESKTOP\foo.lnk"
  Delete "$SMPROGRAMS\foo\foo.lnk"

  RMDir "$SMPROGRAMS\foo"
  RMDir "$INSTDIR"

  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  ;DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
  SetAutoClose true
SectionEnd

FooSetup config=prod

如果我对此进行编译,则输出的最后几行是:

Section: "-aHauptgruppe" ->(SEC01)
ReadINIStr $REGAPPKEY [PROD]:AppName from $INSTDIR\nsis-test.ini

Usage: ReadINIStr $(user_var: output) ini_file section entry_name
Error in script "c:\blabla\setup2019\nsis-test.nsi" on line 29 -- aborting creation process

因此,它已经处理了我的ReadINIStr指令中的第一个,并在第二个指令上进行了倒刺。我看了几个小时的这段代码,注入了换行符等,但是我看不出第二条指令有什么不同...

1 个答案:

答案 0 :(得分:1)

false不是变量。您不见了:

$PATHONE

请注意,您确实有

Var PATHONE

因此请注意不要混淆两者。