Archive: Help with Locate function


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


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


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


usually the best thing is to get the directory from the registry, under the "Uninstall" key for example


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


@ 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

Thanks


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