Franjo Pintarić
Franjo Pintarić

Reputation: 411

NSIS - Run a function after the installer released the files

I'm using NSIS to create a simple installer, and then NsisXML plug-in by Joel to change some things in the config.xml file.

I've created a simple function that does this:

Function ChangeConfig
${nsisXML->OpenXML} "$INSTDIR\configHexd.xml"
${nsisXML->CreateElement} "/config/config_hexd/paramlist" "param" ""
${nsisXML->SetElementAttr} "/config/config_hexd/paramlist/param[10]" "name" "logPath"
${nsisXML->SetElementAttr} "/config[0]/config_hexd/paramlist/param[10]" "value" "$INSTDIR/logs"
${nsisXML->CloseXML}
FunctionEnd

and I'm calling it like this:

; Finish page
!define MUI_FINISHPAGE_RUN "$INSTDIR\run.exe"
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\readme.txt"
!define MUI_PAGE_CUSTOMFUNCTION_PRE ChangeConfig
!insertmacro MUI_PAGE_FINISH

The script compiling goes well and I get my setup.exe. The only problem is, the setup crashes with an 'unknown runtime error' when it's copying the files. This only happens when I'm using this function, if I don't call it everything goes well. Also everything goes well if I just open and close the XML file without trying to write into it. It only crashes when I try writing into the file.

I think that's because the installer tries writing to the file before it's done copying it over, and I'm wondering how I can prevent that.

Thanks!

Upvotes: 1

Views: 755

Answers (1)

Franjo Pintarić
Franjo Pintarić

Reputation: 411

Ok, I solved it, and it was way easier than I thought.

First of all, my node was not called paramlist but paramList, that was the main problem.

Second, as @Anders said, I shouldn't have used MUI_PAGE_CUSTOMFUNCTION_PRE for my problem, a simple Call of the function after the installer was finished transffering the files was enough.

So, lesson 1: Check for typos before blaming the program

Lesson 2: Read the docs to fully understand what something does.

Lesson 3: In most cases, when you find the answer, you're gonna be baffled as to how easy it was to solve the problem.

Upvotes: 2

Related Questions