Vino87
7th February 2008 12:57 UTC
Help with Locate function
Hi,
Im making an installer for a mod right now and i need to be able to search for a directory on the users PC and set that directory as the Installation Directory. Is there any way I could use the Locate function to do this
Wizou
7th February 2008 15:33 UTC
if you want the user to select a directory,
look for "Page directory" in NSIS Help File
or !insertmacro MUI_PAGE_DIRECTORY in MUI ReadMe file
if you want to search for a specific existing directory, you will need to tell us more about what you want
Vino87
7th February 2008 15:37 UTC
I dont want the user to select it, i wanna search the users computer for a certain directory and if it exist install there, if not, quit the installation. The game must be installed for the mod to be installed
Wizou
7th February 2008 15:43 UTC
usually the best thing is to get the directory from the registry, under the "Uninstall" key for example
fabian.rap.more
7th February 2008 16:24 UTC
if its a game then there should be a registry key pointing to the folder where its installed.............if u dont know where the key is located the snnop around the registry or google it
Red Wine
8th February 2008 07:32 UTC
@ Vino87,
following example will search in all available HDDs for a given directory,
outfile "test.exe"
ShowInstDetails Show
!include FileFunc.nsh
!insertmacro Locate
!insertmacro GetDrives
Section
${GetDrives} "HDD" "GetDrives_CallBack"
SetOutPath "$R0"
DetailPrint "$OUTDIR"
SectionEnd
Function GetDrives_CallBack
StrCpy $R1 "$9"
StrCmp "$R1" "$R2" +3
MessageBox MB_YESNO "Search in $R1 hard disk?" IDYES +2
goto end
${Locate} "$R1" "/L=D /M=CONTRIB" "Locate_CallBack"
StrCpy $R2 "$R1"
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
MessageBox MB_OK "$$R0=$R0"
end:
Push $0
FunctionEnd
Function Locate_CallBack
StrCpy $R0 $R9
MessageBox MB_YESNO '$R0$\n$\nFind next?' IDYES +2
StrCpy $0 StopLocate
Push $0
FunctionEnd
Vino87
8th February 2008 12:56 UTC
Thanks
fabian.rap.more
8th February 2008 13:50 UTC
Red Wine's function is quite good but u should expect the user to change the name of the folder..........i admit that not many will but it will be safer to read the location from the registry............the game's official site should have a section like this