Archive: WinVer and variables troubles (+)


WinVer and variables troubles (+)
  Good day everybody :)

I'm using NSIS not for long time (less than 4 months), often read this NSIS-related forum, read docs + using search (maybe miss something), etc.

I use NSIS for my MirandaIM pack installer, which globaly (for full installation) detects Windows version and depending on it installs needed/proper files.
I decided to advance/modify/optimize code, but got some troubles which I can't resolve, feeling dumb :(

So, I have files:
tabsrmm.dll
tabsrmm_unicode.dll
tabsrmm_icons_faith_brq_2k.dll
tabsrmm_icons_faith_brq_xp.dll


so, I need to copy files:
* if WinVer is unknown then copy
tabsrmm.dll + tabsrmm_icons_faith_brq_2k.dll (but without "_2k" in the name)
* if WinVer is Win2k then copy
tabsrmm_unicode.dll + tabsrmm_icons_faith_brq_2k.dll (without "_2k" in the name)
if WinVer is WinXP/2k3 then copy
tabsrmm_unicode.dll + tabsrmm_icons_faith_brq_xp.dll
(without "_xp" in the name)

my code is

Function .onInit

ReadRegStr $WinVer HKLM"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" CurrentVersion
StrCmp $WinVer"5.0" win2k
StrCmp $WinVer"5.1" winxp
StrCmp $WinVer"5.2" winxp

StrCpy $icons "2k"
StrCpy $unicode ""
Goto endwinver

win2k:
StrCpy $icons "2k"
StrCpy $unicode "_unicode"
Goto endwinver

winxp:
StrCpy $icons "xp"
StrCpy $unicode "_unicode"
endwinver:
>FunctionEnd
>

Section "tabSRMM v0.9.9.9" SecTabSRMM

SectionIn 1 2 3
SetOverwrite on
SetOutPath "$INSTDIR\\Plugins"
File "..\\Plugins\\tabsrmm${unicode}.dll"
File /oname=tabsrmm_icons.dll "..\\Icons\\tabsrmm_icons\\tabsrmm_icons_faith_brq_${icons}.dll"
>SectionEnd
>
And it doesn't works - when I'm compilate this it complains:
File: "..\Icons\tabsrmm_icons\tabsrmm_icons_faith_brq_${icons}.dll" -> no files found.
in fact that files
tabsrmm_icons_faith_brq_2k.dll
tabsrmm_icons_faith_brq_xp.dll
exist

Thank you for any help :)

You're getting confused with run-time and compile-time commands.

You need to do the checks inside your section, and jump over File calls for certain conditions.

-Stu


Hmmm... Looks like I don't understand :(
So, how to make it work globally, not only in one section...
It would be excellent to get short example (or hint) of it :)


but, Afrow UK, is it really no way to use runtime string substitution for this case?


No, there is no way. The compiler can't guess every possible value the runtime variable might have and compress all of the matching files.


kichik, but I've defined exactly:


     StrCpy $icons "2k" 

StrCpy $unicode ""
Goto endwinver

win2k:
StrCpy $icons "2k"
StrCpy $unicode "_unicode"
Goto endwinver

winxp:
StrCpy $icons "xp"
StrCpy $unicode "_unicode"
:)))
so, $icons can have 2 values = "2k" or "xp", $unicode can have only 2 values too - "" (empty) and "_unicode".

I totaly dislike old my code:
1st var:

Section "tabSRMM 0.9.9.91" tabsrmm

SectionIn 1 2 3
SetOutPath "$INSTDIR\\Plugins"
SetOverwrite on
File "..\\Plugins\\smileyadd.dll"
ReadRegStr $R0 HKLM "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" CurrentVersion
StrCmp $R0'5.0' unicode
StrCmp $R0'5.1' unicode
StrCmp $R0'5.2' unicode

File "..\Plugins\tabsrmm.dll"
Goto tabicons

unicode:
File "..\Plugins\tabsrmm_unicode.dll"
Goto tabicons

tabicons:
ReadRegStr $R0 HKLM "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" CurrentVersion
StrCmp $R0'5.1' xpicons
StrCmp $R0'5.2' xpicons

File/oname=tabsrmm_icons.dll "..\Icons\tabsrmm_icons\tabsrmm_icons_faith_brq_2k.dll"
Goto endtabsrmm

xpicons:
File /oname=tabsrmm_icons.dll "..\Icons\tabsrmm_icons\tabsrmm_icons_faith_brq_xp.dll"
Goto endtabsrmm
endtabsrmm:
>SectionEnd
>
2nd var:

Section "tabSRMM 0.9.9.91" tabsrmm

SectionIn 1 2 3
SetOutPath "$INSTDIR\\Plugins"
SetOverwrite on
File "..\\Plugins\\smileyadd.dll"
ReadRegStr $R0 HKLM "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion" CurrentVersion
StrCmp $R0'5.0' win2k
StrCmp $R0'5.1' winxp
StrCmp $R0'5.2' winxp

File "..\Plugins\tabsrmm.dll"
File /oname=tabsrmm_icons.dll "..\Icons\tabsrmm_icons\tabsrmm_icons_faith_brq_2k.dll"
Goto endtabsrmm

win2k:
File "..\Plugins\tabsrmm_unicode.dll"
File /oname=tabsrmm_icons.dll "..\Icons\tabsrmm_icons\tabsrmm_icons_faith_brq_2k.dll"
Goto endtabsrmm

winxp:
File "..\Plugins\tabsrmm_unicode.dll"
File /oname=tabsrmm_icons.dll "..\Icons\tabsrmm_icons\tabsrmm_icons_faith_brq_xp.dll"
endtabsrmm:
>SectionEnd
>
So, maybe fix/add it in NSIS to work with it? :)

No such feature will be added to NSIS. As I've said in the previous reply, the compiler can't guess which values the runtime variable will contain. For all it knows, the runtime variable can depend on the user's host name.

Best you can do is create a macro and insert it three times with different parameters.

!macro install srmm_postfix icons_postfix
File "..Plugins\tabsrmm_${srmm_postfix}.dll"
File /oname=tabsrmm_icons.dll "tabsrmm_icons_${icons_postfix}.dll"
!macroend
!insertmacro install "" ""
!insertmacro install "unicode" "2k"
!insertmacro install "unicode" "xp"

sad then :(

thank you very much for the macro, I'll try it :)