Search code examples
parsinginstallationnsis

Using NSIS Splice Function Causes Crash


I am using the function Splice in my NSIS Installer.

My Problem: When I execute the below code the Splice function causes the installer to go into an infinite loop or crash it(it doesn't respond). Whats going wrong?

Am I using Splice wrong? If I cant use splice to split my string the way I want it to, is there another function I could use to split a string?

Section "Dummy"

    Push "user_lib_4d C:\12d\9.00\DTEI_Customisation\SURVEY_12d9\DTEI_Survey_User_Lib"  # "user_lib_4d C:/blah"
    Push "0"
    Push "user_lib_4d"
    Call Splice   # causes an infinite loop/crash

SectionEnd

Solution

  • I accidentally stumbled across the same trouble when using Splice function. But it took me only a little search on google to arrive at the right solution. The point is Splice is not meant for that. The Push "user_lib_4d" line is actually expecting a separator string. The solution is to use any of the actual string function meant for this purpose. There are plenty out there which makes it impossible to mention all here. You could rely on search substring, remove, or replace functions. The one I use and have had success is with StrRep by dirtydingus.

    In your case:

    Section "Dummy"

    Push "user_lib_4d C:\12d\9.00\DTEI_Customisation\SURVEY_12d9\DTEI_Survey_User_Lib"
    Push "user_lib_4d"
    Push ""
    Call StrRep
    Pop $R0 ;result
    
    MessageBox mb_ok $R0
    

    SectionEnd

    Edit: for advanced operations you could use StrStrAdv