Subtracting from a variable in NSIS - nsis

I have to make the variable $tmp2 to equal $len - 15
I have not found anything that says how to simply subtract in NSIS

Use the IntOp instruction to perform basic 32-bit math operations:
IntOp $temp2 $len - 15
MessageBox MB_OK "Result is $temp2"

Related

get output from nsExec::Exec

I am trying to get the standard output from nsExec. for example, this should display a current date in MessageBox:
nsExec::Exec 'date /t'
Pop $0
MessageBox MB_OK "$0"
Apparently thats not how you do it. It only displays 1. What is the correct way of getting the output back from nsExec::Exec
::Exec just hides stdout, you want ::ExecToStack.
The syntax looks like this:
nsExec::Exec '"App"'
Pop $0 ; Exit code / error
nsExec::ExecToStack '"App"'
Pop $0 ; Exit code / error
Pop $1 ; stdout output
You got an error code because time is a built-in command in cmd.exe, not an application. You need to invoke cmd.exe to perform that command:
nsExec::ExecToStack '"$sysdir\cmd.exe" /C time /t'
Pop $0 ; Exit code / error, should be 0
Pop $1 ; Time
If all you wanted was to know the time you could also do this:.
System::Call 'kernel32::GetLocalTime(p#r0)'
System::Call '*$0(&i2, &i2, &i2, &i2, &i2.r4, &i2.r5, &i2.r6, &i2)'
IntFmt $5 "%.2d" $5 ; 0 pad
IntFmt $6 "%.2d" $6 ; 0 pad
MessageBox mb_ok $4:$5:$6

NSIS push, pop and URLEncode

I'm trying to encode with URLEncode a strings in NSIS. I'm using a NSIS plugin called URLEncode. The problem is that I try encode 2 vars, but the first encoded var lost the value after I encoded the second var.
Push "${AFF_NAME}"
Call URLEncode
Pop $3
;at this point the messagebox show the result good.
MessageBox MB_OK $3
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "ProductName"
Push $0
Call URLEncode
Pop $0
;now after second var encoded the result of first var $3 lost the value
MessageBox MB_OK $3
Please Help I'm very new using NSIS and I dont know how do it good. I searching info but without success.
Very thanks !
I'm not aware of a URLEncode plug-in but there is a helper function on the NSIS wiki called URLEncode and it fails to preserve the registers.
You can fix it by modifying the start and end of the function so it looks like this:
; Start
Function URLEncode
System::Store S ; Save registers
Pop $0 ;param
...
Done:
Push $9
System::Store L ; Restore registers
FunctionEnd
; End

Deregistering a font with NSIS

When I try to uninstall a font like that...
Section "un.Uninstall"
StrCpy $FONT_DIR $FONTS
!insertmacro RemoveTTFFont "$FONTS\Vani.ttf"
!insertmacro RemoveTTFFont "$FONTS\Vanib.ttf"
SendMessage ${HWND_BROADCAST} ${WM_FONTCHANGE} 0 0 /TIMEOUT=5000
SectionEnd
I get the following error message:
Error in macro GetFileNameCall on macroline 2
Error in macro RemoveTTFFont on macroline 9
(...) aborting process
In other words, there's something wrong with the following section in the FontReg.nsh file:
!ifmacrondef GetFileNameCall
!macro GetFileNameCall _PATHSTRING _RESULT
Push `${_PATHSTRING}`
Call GetFileName
Pop ${_RESULT}
!macroend
!endif
!ifndef GetFileName
!define GetFileName `!insertmacro GetFileNameCall`
Function GetFileName
Exch $0
Push $1
Push $2
StrCpy $2 $0 1 -1
StrCmp $2 '\' 0 +3
StrCpy $0 $0 -1
goto -3
StrCpy $1 0
IntOp $1 $1 - 1
StrCpy $2 $0 1 $1
StrCmp $2 '' end
StrCmp $2 '\' 0 -3
IntOp $1 $1 + 1
StrCpy $0 $0 '' $1
end:
Pop $2
Pop $1
Exch $0
FunctionEnd
!endif
Can someone, if not tell me how to fix the bug, at least point me in the right direction?
It would be useful for the community as many have had this problem but no one has solved it yet, like here - http://forums.winamp.com/showthread.php?t=245701
I haven't received any answers unfortunately, but I must share the solution I came up with, since I saw that lots of people have had the same problem.
There is a bug in macros to remove fonts, namely "RemoveTTF", "RemoveTTFFont" and similiar sounding ones in the following files : FontReg.nsh, FontRegAdv.nsh. All of them use the same function called "GetFileNameCall" which causes the error. The problem with this function is that it sees "FontName" and "FontFileName" as the same item! As a matter of fact, font file name differs from font name. I solved the problem by copying the needed code from FontRegAdv.nsh and replacing FontFileName and FontName variables with the actual font file names and font names.

NSIS variable value get set concerns

Well, from few years I'm working with NSIS installers and I treat all variables as string in my scripts. Somewhere I read about this, that NSIS internally treat all variables as string, but don't know the exact fact.
Now my query is whenever we are copying some values into some variables or checking the variable's value using logic statements what should be the ideal way to do it. Let me show you an example what I'm talking about.
StrCpy $1 "Some string goes here"
StrCpy $2 999
${If} $1 == "String to match here"
${If} $2 == 999
${If} $2 == "999"
I guess I have no other option for StrCpy $1 case as there I'm copying string into a variable, but for case StrCpy $2, perhaps I can write StrCpy $2 "999" as well. Same thing goes for If statements.
I would like to know the correct convention for NSIS scripting.
Yes, internally everything is stored as strings and they converted to numbers when doing a number operation. Strings that cannot be converted to numbers are treated as 0.
StrCpy $2 999 and StrCpy $2 "999" is exactly the same thing, the quotes are only required when the string has spaces and the quotes are removed by the compiler automatically even when there are no spaces. This also means that ${If} $2 == 999 and ${If} $2 == "999" is the same.
When comparing you should use =, <>, <, <=, >= and > for numbers and == and != for strings.
${IfThen} 0x29A = 666 ${|} DetailPrint "True" ${|} ; 0x29A is 666 in hex
${IfThen} 0x29A == 666 ${|} DetailPrint "This will never print" ${|}

why need in Locate plugin find section the following line?

Section
${Locate} "C:\ftp" "/L=F /M=RPC DCOM.rar /S=1K" "Example1"
; 'RPC DCOM.rar' file in 'C:\ftp' with size 1 Kb or more
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
MessageBox MB_OK "$$R0=$R0"
SectionEnd
Function Example1
StrCpy $R0 $R9
; $R0="C:\ftp\files\RPC DCOM.rar"
MessageBox MB_YESNO '$R0$\n$\nFind next?' IDYES +2
** StrCpy $0 StopLocate ** -> why needs this line?
Push $0
FunctionEnd
Thx for the help!
${Locate} has a loop that looks for files that matches your input and when it finds one it calls your callback-function (Example1 in this case). It searches subdirectories by default so there could be more than one "RPC DCOM.rar" file.
If you only care about the first file then you can stop it from searching other subdirectories by pushing the string "StopLocate" to the stack. Pushing anything else will continue the search...

Resources