Lucky49
11th October 2006 18:40 UTC
problem related to files and directories
Hello all,
I have a directory called Dlls which is having some dll files. I need to copy all these files on client directory and also register them. The problem is that the number of dll files in the Dlls directory is not fixed and so I can't hardcode there names. I am wondering if there is a way to copy and register each file one by one from the directory without hard coding anything.
Right now my code is
File "Dlls\ms.dll"
File "UTSDlls\msis.dll"
………
Copyfiles /silent $INSTDIR\ms.dll "C:\Program Files\DLLS"
Copyfiles /silent $INSTDIR\msis.dll "C:\Program Files\DLLS"
…………………
RegDLL "C:\Program Files\DLLS\ms.dll"
RegDLL "C:\Program Files\DLLS\msis.dll"
…………………….
As you can see all the files in Dlls directory are copied by hard coding there names.
I would really appreciate if someone can help me out.
Thanks,
Lucky
goldy1064
11th October 2006 19:02 UTC
Take a look at Locate in the NSIS Manual . You may use it to find all *.dll in a directory and then register each dll.
Lucky49
11th October 2006 21:36 UTC
thanks
Thanks dude,
I can now copy all files but I am still not sure how to register dlls without hard coding there names.
goldy1064
11th October 2006 22:02 UTC
Within the callback function that you pass to Locate, copy the file there and then register the file after copying it.
Lucky49
11th October 2006 23:31 UTC
i didn't get what you wrote. Following is my code now
File "Dlls\*.dll"
Copyfiles /silent $INSTDIR\*.dll "C:\Program Files\DLLs"
My prob is what to write in
RegDLL "C:\Program Files\DLLs\?"
goldy1064
11th October 2006 23:46 UTC
What you need to do is to look at Locate. Locate will allow you to search a directory (at runtime of your installer) for specific files and each time a file is found, you would just need to run RegDLL.
!include 'FileFunc.nsh'
!insertmacro Locate
...
Section Blah
CopyFiles /silent $INSTDIR\*.dll "C:\Program Files\DLLs"
#locates all dll's in C:\Program Files\DLLs
${Locate} "C:\Program Files\DLLs" "/L=F /G=0 /M=*.dll" LocateCallback
SectionEnd
Function LocateCallback
#$R9 holds the absolute path of the file found
#register the DLL
FunctionEnd
If more than just your DLL's will be in the output directory, than do the locate on the directory you were copying from and than just copy each file as Locate finds them and then register each.
Lucky49
12th October 2006 02:06 UTC
Thanks goldy1064
Now I have one last prob i guess. Following is my code now -
File "Dlls\*.dll"
${Locate} "$INSTDIR\" "/L=F /G=0 /M=*.dll" LocateCallback
Function "LocateCallback"
Copyfiles /silent $R9 "C:\DLLs"
RegDLL $R9
FunctionEnd
I have more then one dll files but this function is called I guess only one time so only one dll gets copied and registered. Can you help me understand what’s going wrong.
goldy1064
12th October 2006 16:28 UTC
The below code can be used to continue searching until no more files/directories are found.
Function LocateCallback
...
StrCmp $R9 "" 0 stop_locate
Push ""
goto end
stop_locate:
Push "StopLocate"
end:
FunctionEnd
Lucky49
12th October 2006 23:20 UTC
Thanks
Thanks a lot dude.....