Archive: How to pass LOCALFILE to Library.nsh as a variable


How to pass LOCALFILE to Library.nsh as a variable
i wish to pass a dynamic foldername to upgrade all its DLLs/OCXs but i'm getting the error:
'!error: InstallLib 1: The library $5\$1 could not be found.
Error in macro InstallLib on macroline 89'.

Even tried to !define a custom var (i.e. var MyVar) and use it (with StrCpy $MyVar "c:\sourcedir": no way.
I've read almost all relevant posts in this forum but i must admit i can't still understand where the issue is: i would really appreciate just some hints.
Here below the abstract of the code i'm using.
Thanks in advance.

;test upgrade all dll in a given folder
!include Library.nsh
var ALREADY_INSTALLED
name "Get files test"
outfile "testgetfiles.exe"
InstallDir "$PROGRAMFILES\MyTest"

Section -DoIt
push "c:\sourcedir\winlib"
call GetFiles
SectionEnd

Function GetFiles
Exch $5
FindFirst $0 $1 "$5\*.*"
loop:
StrCmp $1 "" done
StrCmp $1 "." readnext
StrCmp $1 ".." readnext
ifFileExists "$5\$1" 0 readnext
StrCpy $ALREADY_INSTALLED 1
!insertmacro InstallLib REGDLL $ALREADY_INSTALLED REBOOT_NOTPROTECTED "$5\$1" "$SYSDIR\$1" "$SYSDIR"
readnext:
FindNext $0 $1
Goto loop
done:
FindClose $0
FunctionEnd


addin...
forgot mention: the parameter 'localfile' in library.nsh is used 'as is'. on the contrary, destfile and tempbasedir are converted to variables ($r4/$r5).
I tried to !define in the script a compile var and use it in the Installib line (${dllpath}\$1 instead of $5\$1).
Error is the same.
What am i missing, if the case ?
thanks to anybody would help.


The issue is that localfile expects a local file name. The compiler can't predict which files the installer will find at runtime. It can't guess which files it needs to compress.


yes but thonk to UpgradeDLL_Function...
thanks for quick reply, kichik.
I understand what you mean, however: should not this apply also to 'destfile' ?
Let me explain my target. i'm writing a wizard to auto generate scripts from a given source structure. i've two options: 1. create the 'File ...' lines step by step as soon my wizard recurse the folders; 2. call GetFiles function to recursively 'File...' AND 'InstallLib...' on each file the wizard finds (of course, Installib is called only if .OCX,.DLL,.TLB are detected).
Well, i found in this forum the post by mr. Opher Shachar with the function 'UpgradeDLL_Func' which seems to do exactly that job. I'm not using it for two reasons: first i'm not able to find the necessary include 'PathManip.nsh'; second, Library.nsh seems to be more feasible.
I would like to use this library, but i can't pass the dynamic folders as they're processed by the GetFiles function.
Why it is not possible to manage the 'localfile' parm the same way as 'destfile' ? Sorry, this is not clear to me.
thanks.


folders can be dynamically passed...
after some testing, i see now that folders can be assigned dynamically using !define. The compiler now gives error only on the filename (still a user var, this is my mistake).
Don't understand why files are treated in different way than folders; anycase, it's not an elegant (partial) solution as i have to !undef / !define the same 'source_dll_path' inside the folder recursion loop.
Guess no solution at present...


destfile doesn't contain a path of a local file that needs to be compressed into the installer while localfile does. destfile tells the Library macro where to put the file. That doesn't affect which files it needs to compress. It can be totally dependent on how the script runs on the user's machine.

With localfile, it's a completely different story. The compiler can't run the script on your machine, while compiling it, in order to find out which files it needs to compress. Even if it could run the script somehow, it can't predict which values the registers will contain on the user's machine. It can't predict which files it needs to compress. You must specify them explicitly.