NSIS concatenate string with slash - string

I'm trying to build a string with this expression bla://${foo}/bar where ${foo} == "hostname". The expected result is bla://hostname/bar but I get http://${foo}/bar instead.
So I figure there is something special about the combination /$ but I can't figure it out.
Thanks for your help

/$ is not special but a define that does not exist ends up as ${definename}.
DetailPrint "${foo}" ; Prints ${foo}
!define foo example.com
DetailPrint "${foo}" ; Prints example.com
All defines are resolved at compile time, if this hostname is something the user could configure on a custom page you need to use a NSIS variable...

Related

READ THE ENVIRONMENT VARIABLE DURING THE COMPILE TIME IN NSIS

HI Everyone As i was working with the NSIS code, i need to get the environment variable value during the compile time, I Found this code written in somewhere But am not getting understand what does 'Foo' means. & How can we execute the below code in compile time, in my compiler Am not getting the environment variable value with the below following code, Can anybody give a brief example about where we can execute this & How it works?
Edit : As you requested i was inserting the link of Code referred from this forum "https://stackoverflow.com/questions/22149007/nsis-how-to-check-at-compile-time-if-an-environment-variable-exists"
; NSIS 2+
!define DOLLAR $
!if "$%foo%" == "${DOLLAR}%foo%"
!echo "%foo% not set"
!endif
; NSIS 3+
!if "$%foo%" == "${U+24}%foo%"
!echo "%foo% not set"
!endif
This code tries to check if a environment variable has been set (on the computer where the compiler is executing). If it has not been set the compiler just returns the raw string (like a batch file does). The code you found escapes the $ to check if the raw string is returned.
Foo is just a placeholder name, meaning the %Foo% variable. If you want to check %windir% for example, use !if "$%windir%" == "${U+24}%windir%".
If you just want the value, just use $%windir%:
ReadEnvStr $0 WINDIR
MessageBox MB_OK "%windir% was $%windir% when this installer was compiled. On this machine it is $0"

How to request plain HTTP from a website using Inetc

Haya, at the moment im trying to solve a problem in my code regarding a SendRequest error since i believe the website im using (https://www.gnu.org/licenses/gpl-3.0.txt) is not being validated as having a correct certificate by inetc or something close to this - i read here (https://stackoverflow.com/a/26893754/11718125) that to fix this i could use plain http.
how could i go about doing this?
The answer you linked to is old, INetC now supports a /WEAKSECURITY switch.
To use plain HTTP, just change the https: part in the URL to http:. This does not work everywhere, some servers might force a redirect to HTTPS.
This works for me:
Section
InitPluginsDir
inetc::get /WEAKSECURITY /SILENT "https://www.gnu.org/licenses/gpl-3.0.txt" "$PluginsDir\License.txt" /END
ClearErrors
FileOpen $1 "$PluginsDir\License.txt" r
IfErrors 0 +2
Abort "No file?"
loop:
FileRead $1 $2
IfErrors +3
DetailPrint $2
Goto loop
FileClose $1
SectionEnd

How do I use/include StrContains in NSIS

Do I need to include a specific .nsh library or function definition to use the function 'StrContains' in NSIS?
I have looked for a download for the library but I cant seem to find it?
When I go to compile this code I get the compile error: "Invalid command: ${StrContains}"
!include "LogicLib.nsh"
# Compile error below
!macro test
${StrContains} $0 $1 "abc"
!macroend
Section
DetailPrint ""
SectionEnd
You need to add the function definition shown in the StrContains function page of the NSIS wiki (in the category of strings functions) in your code.
Don't forget the last statement !define StrContains ... to be able to call it with ${StrContains}

How do I conditionally compile an NSIS script based on commandline parameters?

I'm trying to generalize a setup file by externally passing the version number. I want to be able to do this:
makensis myscript.nsi parameter=value
and then read the parameter within the script, so that using the same script I can generate differently versioned executables. I found this & this, but they seem to be for passing commandline parameters to the generated setup.exe. Is this possible, and how?
You can add symbols to the globally defined list from the command line using the /D switch:
makensis /DMyVersion="1.0.1" install.nsi
Then you can use them using the ${} syntax:
!ifdef MyVersion
StrCpy $Version "${MyInstallerName}"
!else
StrCpy $Version "1.0.0"
!endif
Also of possible interest is the GetVersion plugin discussed in this SO question: NSIS - put EXE version into name of installer

Install from dynamic location

I have 2 versions of the same exe file for my project. The installer is supposed to pick one of the 2 versions depending on some conditions.
In a normal case i would do File executable\myExe.exe. Because i now have 2 versions of the file, i would have to do something like File "${ExeSourcePath}\myExe.exe", and $ExeSourcePath is determined by checking various conditions. When compiling this code i get
File: "${ExeSourcePath}\myExe.exe" -> no files found.
Anyone knows why? I'm only allowed to use fixed paths with the File command or am i doing something wrong?
${ExeSourcePath} is a precompiler define and $ExeSourcePath is a variable used at runtime, the File command can only use precompiler defines.
There are two ways you can handle this:
A) Include both files and decide at runtime based on the users system or choices made during install:
!include LogicLib.nsh
Section
ReadRegStr $0 HKLM "Software\foo\bar" baz
${If} $0 > 5
File "c:\myproject\version2\app.exe"
${Else}
File "c:\myproject\version1\app.exe"
${EndIf}
SectionEnd
B) Only include one file based on command line passed to makensis (/Dusev2 app.nsi) or something on your system:
Section
!define projectroot "c:\myproject"
!searchparse /noerrors /file ....... usev2 ;Or you can use !system etc
!ifdef usev2
File "${projectroot}\version2\app.exe"
!else
File "${projectroot}\version1\app.exe"
!endif
SectionEnd

Resources