我正在尝试创建一个NSIS脚本,该脚本将各种文件复制到可以指定的两个不同位置。 我已经检查了文档和其他StackOverflow条目,但没有提出解决方案。 我的问题是我想为目录定义第二个变量。在此目录中,应复制样本文件和项目。
在尝试编译NSI时,我收到以下错误/警告:
3 warnings:
unknown variable/constant "APPDIR" detected, ignoring (C:\Users\max\Desktop\PortablePlayer\so.nsi:29)
unknown variable/constant "APPDIR" detected, ignoring (C:\Users\max\Desktop\PortablePlayer\so.nsi:33)
unknown variable/constant "APPDIR\Testfile.txt" detected, ignoring (C:\Users\max\Desktop\PortablePlayer\so.nsi:43)
以下是我使用的脚本:
!include "MUI.nsh"
Name "MyApp"
OutFile "MyApp-Installer.exe"
InstallDir "$PROGRAMFILES\My App"
; Installation Directory for the App
!insertmacro MUI_PAGE_DIRECTORY
; Installation Directory for the samples and projects
!define MUI_PAGE_HEADER_SUBTEXT "Choose your custom Samples Folder"
!define MUI_DIRECTORYPAGE_TEXT_TOP "To separate your App and your samples and projects you can choose a different folder than the installation directory"
!define MUI_PAGE_DIRECTORY_VARIABLE $APPDIR
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section ""
SetOutPath $INSTDIR
File Testfile.txt
SetOutPath $APPDIR
File Testfile.txt
FileOpen $0 "$DESKTOP\Hello_world.txt" w
FileWrite $0 $APPDIR
FileClose $0
WriteUninstaller "$INSTDIR\MyApp-Uninstaller.exe"
SectionEnd
Section "Uninstall"
Delete "$INSTDIR\Testfile.txt"
Delete "$INSTDIR\MyApp-Uninstaller.exe"
RMDir $INSTDIR
Delete "$APPDIR\Testfile.txt"
SectionEnd
对于调试我试图将$ APPDIR的值写入文本文件,但它只写$ APPDIR而不是值。 如果我将其更改为$ INSTDIR,则会打印$ INSTDIR的正确路径。 如何为$ APPDIR初始化变量? 如果我尝试在顶部初始化它,它就是空的,因此安装程序在成功编译脚本后失败。
使用NSIS 2.5.1运行Win 7
有人可以说明问题是什么吗?
谢谢!
答案 0 :(得分:1)
MUI_DIRECTORYPAGE_VARIABLE
定义告诉MUI你有一个你想要使用的自定义变量但是MUI没有创建变量,你必须自己在脚本顶部附近做这个:
Var APPDIR
所以看起来应该像
Var APPDIR
!include "MUI.nsh"
!define MUI_DIRECTORYPAGE_VARIABLE $APPDIR
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section
DetailPrint $APPDIR
SectionEnd
编辑:定义的名称是MUI_DIRECTORYPAGE_VARIABLE而不是MUI_PAGE_DIRECTORY_VARIABLE,就像你的示例中那样......