0
votes

I couldn't find this in any searches and have been fighting with these scripts this past week, trying to learn how NSIS' scripting works from scratch in the process. Cutting to the chase, here's what I'm encountering and take note I'm working with another person's scripts in the process:

Initial state of the scripts:
Fails to enable the program's functionality (which is to present an easy to use .exe to call in the command line that may then be followed by other commands in relation to another file to extract its contents). Presents warnings that AddEnvVar and un.RemoveFromEnvVar functions are not called.

Add calls to the functions in the .nsi file in the appropriate sections.

Installer compiles, but when run presents an Installer Corrupted: Invalid Opcode error.

Okay...Not sure why that's happening. There's another script called EnvVarUpdate present, maybe that's it. Add a line in the .nsi to include it. Then I run into this:

Error: Function named "StrStr" already exists. Error in macro
STRFUNC_FUNC on macroline 16 Error in macro FUNCTION_STRING_StrStr on
macroline 1 Error in macro _IncludeStrFunction on macroline 2
!include: error in script: "EnvVarUpdate.nsh" on line 50

Okay. Try commenting out those lines to get it through...And I hit this:

!insertmacro: macro "FUNCTION_STRING_StrStr" requires 0 parameter(s),
passed 3! Error in macro EnvVarUpdate on macroline 84

I have no idea if EnvVarUpdate needs to be included to begin with (since it wasn't originally included in the .nsi script I'm at a loss for what it's even doing there) and I can't figure out why the calls to AddEnvVar and un.RemoveFromEnvVar are corrupting the installer. It seemed logical to me that for since these files were published with the intent being easy compilation that all the files would be necessary, but with the function calls missing and the exclusion of one of the scripts in the .nsi file rendering the compiled installer dysfunctional, I'm led to believe he may have made some mistakes in the process.

My guess is since he also published a compiled installer that works hosted on his own site, he incidentally left the open files a little broken as he figured out the right way to do it. However, personally, I'd still like to repair them if I can figure out how to enable others to manually compile the installers if they like.

If it might help, here's a link to the fellow's code on GitHub.

1

1 Answers

0
votes

AddToPath.nsh contains two functions that manipulate %path% (AddToPath and un.RemoveFromPath) and two generic functions that can manipulate any environment variable (AddToEnvVar and un.RemoveFromEnvVar) but those two functions are never used so you get a warning.

To remove the warnings you can just comment out those two unused functions.

EnvVarUpdate.nsh uses the StrStr that is a part of NSIS so you get a problem because it is already defined in AddToPath.nsh

A common pattern for utility functions like these is to put the function inside a macro and then allow the .nsi to select the functions it uses by inserting the macro (And the macro creates the function at that point):

!macro Foo un
Function ${un}Foo
MessageBox mb_ok "Hello from Foo"
FunctionEnd
!macroend

...

!insertmacro Foo "" ; Use function Foo in installer?
#!insertmacro Foo "un." ; Use function Foo in uninstaller?

Section
call Foo
SectionEnd