1
votes

I'm trying to create an NSIS script which copies various files to two different locations that can be specified. I have checked the documentation and other StackOverflow entries but do not come up with a solution. My Problem is that I want to define a second variable for a directory. In this directory sample files and projects shall be copied.

When trying to compile the NSI I get the following error/warnings:

    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)

Here is my script that I'm using:

    !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

For debugging I tried to write the value of $APPDIR into a textfile but it only writes $APPDIR instead of the value. If I change it to $INSTDIR it prints the correct path for $INSTDIR. How can I initialize the variable for $APPDIR? If I try to initialize it on the top, it is there but empty, so the installer fails after succesful compilation of the script.

Running Win 7 with NSIS 2.5.1

Can anybody please shed some light on what is wrong?

Thanks!

1
I hope you mean v2.51 and not v2.5.1 :) - Anders

1 Answers

2
votes

The MUI_DIRECTORYPAGE_VARIABLE define tells MUI that you have a custom variable that you want to use but MUI does not create the variable, you have to do that yourself near the top of your script:

Var APPDIR

So it should look something like

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

Edit: The name of the define is MUI_DIRECTORYPAGE_VARIABLE not MUI_PAGE_DIRECTORY_VARIABLE like you have in your example...