Search code examples
installationzipnsis

Archive currently installed files using a NSIS installer


I am trying to customize my installer accordingly, so that it looks, wether there are specific folders in the $INSTDIR, which is getting set on a MUI_PAGE_DIRECTORY. If it finds these folders, it should compress them and put that archive into a backup-folder under $INSTDIR and set it's name according to the date.

I have searched long to find a solution for this, but I did not find any compression plugins nor did I figure out how to ship a 7zip with it and use that for compression. I am not as fit with NSIS though.


Solution

  • Code not tested, but it should help...

    # Bundle 7zip archiver and extract it to TEMP folder
    File "/oname=$TEMP\7za.exe" 7za.exe
    # If target directory exists...
    ${If} ${FileExists} "$INSTDIR"
        # Create archive on temp folder
        execwait '"$TEMP\7za.exe" a "$INSTDIR\archive.7z" "$INSTDIR\folder_to_backup"'
    ${EndIf}
    Delete "$TEMP\7za.exe"