Archive: Not allow users to change app directory


Not allow users to change app directory
HI its me again
Following the suggestions of this forum I ask for a new problem
I dont want to allow user to select the directory of the application and I need now to create 2 different directories depending on the options that are selected, until everything what I saw in the samples uses
SetOutPath $INSTDIR\MyApp
How I make to create for example \MyApp and \MyApp2 ?


Use LogicLib.

-Stu


Examine this test:

outfile 'Components_test.exe'
InstallDir '$PROGRAMFILES\Components Test'

!include 'mui.nsh'

!insertmacro MUI_PAGE_COMPONENTS
# no dir page
#!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

section "!Required Section"
SectionIn RO
SetOutPath '$INSTDIR'
SectionEnd

Section "Components 1"
SetOutPath '$INSTDIR\Component 1'
SectionEnd

Section /o "Components 2"
SetOutPath '$INSTDIR\Component 2'
SectionEnd

Thanks Red Wine
But now my answer is, exist a way to create directories under the ROOT of the Disc and not under $PROGRAMFILES??

TIA


Here is an example on how to create installation directories on the drive where windows are installed :-)
E.g. if it is D:\WINDOWS the installation is going to D:\My Test etc.

!define DEFAULT_DIR 'My Test'

outfile 'test.exe'
showinstdetails show
InstallDir '$PROGRAMFILES\${DEFAULT_DIR}'

page license
page directory dir_pre
page instfiles

function dir_pre
strcpy '$R0' '$WINDIR' 3
strcpy '$INSTDIR' '$R0${DEFAULT_DIR}'
functionend

section -

Setoutpath '$INSTDIR'

Setoutpath '$INSTDIR\MyAPP'

Setoutpath '$INSTDIR\My App More'

sectionend

Thank You RW, this solve my problem

Bye


RW
Sorry its me again

When i compile trying to use your tip, shows me an error

This is a part of code :

--------------------------------------------
!define DEFAULT_DIR 'MyApp'

!include "MUI.nsh"

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE $(MUILicense)
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY dir_pre
--------------------------------------

And the error

!insertmacro: macro "MUI_PAGE_DIRECTORY" requires 0 parameter(s), passed 1!
Error in script "IpReader.nsi" on line 58 -- aborting creation process

--------------------------------------------

Whats wrong?


The example above is about classic UI. For MUI here it is:

!define DEFAULT_DIR 'My Test'

outfile 'test.exe'
showinstdetails show
InstallDir '$PROGRAMFILES\${DEFAULT_DIR}'

!include 'mui.nsh'

!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE dir_pre
!insertmacro MUI_PAGE_DIRECTORY
!define MUI_PAGE_CUSTOMFUNCTION_PRE verify_default_dir
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

function dir_pre
strcpy '$R0' '$WINDIR' 3
strcpy '$INSTDIR' '$R0${DEFAULT_DIR}'
functionend

section - "a hidden section"
Setoutpath '$INSTDIR'
sectionend

section /o "Section MyApp"
Setoutpath '$INSTDIR\MyAPP'
sectionend

section /o "Section My App More"
Setoutpath '$INSTDIR\My App More'
sectionend

function verify_default_dir
strcpy '$R0' '$WINDIR' 3
strcmp '$R0${DEFAULT_DIR}' '$INSTDIR' +3 +1
strcpy '$INSTDIR' '$R0${DEFAULT_DIR}'
messagebox mb_ok 'reseting output directory to $R0${DEFAULT_DIR}'
functionend

Ups, sorry
Thanks i try with this one


Hi RW
I try and doesnt work in the way I need.
It generates a C:\My Test\MyApp directory to me and a C:\My Test\MYapp\My App More
In addition never shows the message to me of messagebox mb_ok “reseting output directory to $R0$ {DEFAULT_DIR}”
I need to create C:\My App and C:\My App More

Any idea ?


1. you'll see the message if you attempt to change the default dir, remove it, probably you don't need that.
2. feel free to modify the skeleton script to suit your needs. add/remove sections, change dirs etc.
EXAMPLE:

outfile 'test.exe'
showinstdetails show
AllowRootDirInstall true

!include 'mui.nsh'

!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_PRE dir_pre
; no dir page
; !insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_LANGUAGE "English"

function dir_pre
strcpy '$R0' '$WINDIR' 3
strcpy '$INSTDIR' '$R0'
functionend

section - "Section MyApp"
Setoutpath '$INSTDIR\MyAPP'
sectionend

section - "Section My App More"
Setoutpath '$INSTDIR\My App More'
sectionend

Thanks RW
It Works as i need
Thank you very much
Now I have another problems, but I am going to ask them in new post
Thanks for your time


You welcome :-)
Just remember that the above, used in function dir_pre code, it's a trick just to give us the drive letter of the disk where windows are installed.
If you wish to install on other media, network drives etc, you have to refer to the included GetRoot, GetDrives etc.