使用变量时如何修复 "CreateDirectory: Relative paths not supported"?
How to fix "CreateDirectory: Relative paths not supported" when using a variable?
作为一个新手,我还处于试验和构建小原型的阶段。这个想法是构建一个静默安装程序,它在 .INI 的多个部分中具有所有设置,并且用户使用参数 /config={NameOfSection}
调用安装程序。
我的现状:
FooBar-install.ini
[PROD]
FOOHOME=c:\FooBar
FooBar.nsi
!include FileFunc.nsh
!include LogicLib.nsh
!insertmacro GetParameters
!insertmacro GetOptions
var /GLOBAL config
var /GLOBAL cmdLineParams
var /global REGAPPKEY
var /global FOOHOME
!define TheName "FooBar"
!define OutFileSuffix "-Install."
!define IniFile "$EXEDIR${TheName}${OutFileSuffix}ini"
Name "${TheName} ${PRODUCT_VERSION}" ; bei 2 Kunden geht's auch kd-spezifisch ;)
OutFile ${TheName}${OutFileSuffix}exe
RequestExecutionLevel admin
Icon "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
Section "-aInstaller Section"
ReadINIStr $FOOHOME ${IniFile} $config "FOOHOME"
MessageBox MB_OK "ini=${IniFile} , config=$config, FOOHOME=$FOOHOME"
CreateDirectory "SFOOHOME"
SectionEnd
function .onInit
UserInfo::GetAccountType
pop [=12=]
${If} [=12=] != "admin" ;Require admin rights on NT4+
MessageBox mb_iconstop "Administrator rights required!"
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
${Else}
MessageBox MB_OK "onInit"
${EndIf}
; Get parameters
${GetParameters} $cmdLineParams
; /? param (help)
ClearErrors
${GetOptions} $cmdLineParams '/?' $R0
IfErrors +3 0
MessageBox MB_OK "Befehlszeilenparameter /config={{name}} verweist auf einen Abschnitt aus ${TheName}${OutFileSuffix}ini mit div. Parametern zur Steuerung des Setup"
Abort
Call parseParameters
Pop $R0
FunctionEnd
Function parseParameters
; /config
${GetOptions} $cmdLineParams '/config=' $R0
${If} ${Errors}
StrCpy $config "errPROD"
${Else}
StrCpy $config $R0
${Endif}
FunctionEnd
问题
如果我尝试编译它,我会收到消息
CreateDirectory: Relative paths not supported
Usage: CreateDirectory directory_name
问题
我不明白为什么在编译时会出现这个错误。当使用变量时(尤其是在变量依赖于用户输入的情况下),在参数未知时抱怨参数似乎没有意义。
如何避免这个问题?
一个让我困惑的小谜题是引用 variables.The 语句的语法 MessageBox MB_OK "ini=${IniFile} , config=$config, FOOHOME=$FOOHOME"
表明了这一点。我发现我需要将 IniFile 包含在 {} 中以显示其值(我注释掉了 CreateDir 行以编译安装程序并检查我的假设)。我什么时候必须使用 {}
?
如果您在我的小脚本中看到任何其他 "unusual" 东西,我很乐意知道 ;)
你打错了,把CreateDirectory "SFOOHOME"
改成CreateDirectory "$FOOHOME"
您可能想再次阅读文档以了解基础知识; ${define}
、$(langstring)
和 $variable
。
作为一个新手,我还处于试验和构建小原型的阶段。这个想法是构建一个静默安装程序,它在 .INI 的多个部分中具有所有设置,并且用户使用参数 /config={NameOfSection}
调用安装程序。
我的现状:
FooBar-install.ini
[PROD]
FOOHOME=c:\FooBar
FooBar.nsi
!include FileFunc.nsh
!include LogicLib.nsh
!insertmacro GetParameters
!insertmacro GetOptions
var /GLOBAL config
var /GLOBAL cmdLineParams
var /global REGAPPKEY
var /global FOOHOME
!define TheName "FooBar"
!define OutFileSuffix "-Install."
!define IniFile "$EXEDIR${TheName}${OutFileSuffix}ini"
Name "${TheName} ${PRODUCT_VERSION}" ; bei 2 Kunden geht's auch kd-spezifisch ;)
OutFile ${TheName}${OutFileSuffix}exe
RequestExecutionLevel admin
Icon "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
Section "-aInstaller Section"
ReadINIStr $FOOHOME ${IniFile} $config "FOOHOME"
MessageBox MB_OK "ini=${IniFile} , config=$config, FOOHOME=$FOOHOME"
CreateDirectory "SFOOHOME"
SectionEnd
function .onInit
UserInfo::GetAccountType
pop [=12=]
${If} [=12=] != "admin" ;Require admin rights on NT4+
MessageBox mb_iconstop "Administrator rights required!"
SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
${Else}
MessageBox MB_OK "onInit"
${EndIf}
; Get parameters
${GetParameters} $cmdLineParams
; /? param (help)
ClearErrors
${GetOptions} $cmdLineParams '/?' $R0
IfErrors +3 0
MessageBox MB_OK "Befehlszeilenparameter /config={{name}} verweist auf einen Abschnitt aus ${TheName}${OutFileSuffix}ini mit div. Parametern zur Steuerung des Setup"
Abort
Call parseParameters
Pop $R0
FunctionEnd
Function parseParameters
; /config
${GetOptions} $cmdLineParams '/config=' $R0
${If} ${Errors}
StrCpy $config "errPROD"
${Else}
StrCpy $config $R0
${Endif}
FunctionEnd
问题
如果我尝试编译它,我会收到消息
CreateDirectory: Relative paths not supported
Usage: CreateDirectory directory_name
问题
我不明白为什么在编译时会出现这个错误。当使用变量时(尤其是在变量依赖于用户输入的情况下),在参数未知时抱怨参数似乎没有意义。
如何避免这个问题?
一个让我困惑的小谜题是引用 variables.The 语句的语法
MessageBox MB_OK "ini=${IniFile} , config=$config, FOOHOME=$FOOHOME"
表明了这一点。我发现我需要将 IniFile 包含在 {} 中以显示其值(我注释掉了 CreateDir 行以编译安装程序并检查我的假设)。我什么时候必须使用{}
?如果您在我的小脚本中看到任何其他 "unusual" 东西,我很乐意知道 ;)
你打错了,把CreateDirectory "SFOOHOME"
改成CreateDirectory "$FOOHOME"
您可能想再次阅读文档以了解基础知识; ${define}
、$(langstring)
和 $variable
。