Search code examples
nsisunzip

How to Use the NSIS Unzip Plugin properly?


Im new to NSIS programming, so i found the NSISUNZ plugin to extract files.

This is my Code:

OutFile "TEst.exe"
Section
!addplugindir nsisunz
initPluginsDir
nsisunz::Unzip "C:\Users\user\Downloads\TestVerzeichnis.zip" "C:\Users\user\Downloads"
SectionEnd

I do not get an Error or something but the file does not get extracted. For the installation of the plugin I just extracted the .dll file into the plugins folder.

What am I doing wrong here?

Thanks for answering


Solution

  • If the output is just a single letter then you most likely using the Unicode version of the plug-in in a Ansi installer.

    Ideally you should create a Unicode installer with NSIS v3:

    1. Move the plug-in to the Unicode plug-in subfolder inside the root plugins folder.
    2. Add Unicode True to your .NSI.

    If you are still using NSIS v2 then you need to find a different version of the plug-in, most likely the other file on the wiki.

    Unicode True
    !addplugindir /x86-unicode "$%userprofile%\Downloads\Nsisunz\Plugin unicode"
    
    !include LogicLib.nsh
    Function SplitWrite
    Pop $2
    StrCpy $3 ""
    StrCpy $4 0
    loop:
        StrCpy $5 $2 1 $4
        ${If} $5 == "|"
        ${OrIf} $5 == ""
            IntOp $6 $4 - 2
            StrCpy $6 $2 2 $6
            FileWriteByte $1 "0x$6"
        ${EndIf}
        IntOp $4 $4 + 1
        StrCmp $5 "" 0 loop
    FunctionEnd
    
    Section
    InitPluginsDir
    ; Create a example .zip file 
    FileOpen $1 "$PluginsDir\test.zip" w
    Push 50|4B|03|04|0A|00|00|00|00|00|AC|BA|93|50
    Call SplitWrite
    Push F8|06|53|6B|08|00|00|00|08|00|00|00|08|00|00|00|54|65|73|74|2E|74|78|74|48|65|6C|6C|6F|20|0D|0A|50|4B|01|02|3F|00|0A|00|00|00|00|00|AC|BA|93|50
    Call SplitWrite
    Push F8|06|53|6B|08|00|00|00|08|00|00|00|08|00|24|00|00|00|00|00|00|00|20|20|00|00|00|00|00|00|54|65|73|74|2E|74|78|74|0A|00|20|00|00|00|00|00|01|00|18|00
    Call SplitWrite
    Push D6|75|96|79|90|16|D6|01|96|4F|96|79|90|16|D6|01|96|4F|96|79|90|16|D6|01|50|4B|05|06|00|00|00|00|01|00|01|00|5A|00|00|00|2E|00|00|00|00|00
    Call SplitWrite
    FileClose $1
    
    CreateDirectory "$PluginsDir\TestDir"
    nsisunz::Unzip "$PluginsDir\test.zip" "$PluginsDir\TestDir"
    Pop $0
    DetailPrint $0 ; "success"
    ${If} $0 == "success"
        FileOpen $1 "$PluginsDir\TestDir\Test.txt" r
        FileRead $1 $2
        FileClose $1
        DetailPrint $2 ; "Hello"
    ${EndIf}
    
    SectionEnd