- NSIS Discussion
- Not allow users to change app directory
Archive: Not allow users to change app directory
Boyito
6th December 2006 21:08 UTC
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 ?
Afrow UK
6th December 2006 22:00 UTC
Use LogicLib.
-Stu
Red Wine
6th December 2006 22:20 UTC
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
Boyito
7th December 2006 14:06 UTC
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
Red Wine
7th December 2006 16:03 UTC
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
Boyito
7th December 2006 17:40 UTC
Thank You RW, this solve my problem
Bye
Boyito
7th December 2006 18:06 UTC
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?
Red Wine
7th December 2006 19:20 UTC
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
Boyito
7th December 2006 19:26 UTC
Ups, sorry
Thanks i try with this one
Boyito
7th December 2006 20:03 UTC
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 ?
Red Wine
7th December 2006 20:22 UTC
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
Boyito
7th December 2006 20:44 UTC
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
Red Wine
8th December 2006 17:29 UTC
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.