Serban Constantin
Serban Constantin

Reputation: 3576

NSIS set temp folder name at run-time

I am currently extracting some files needed by the installer in a folder placed in the Windows temp directory. The way I have set it now is that that folder has a unique name based on the product name as well as the date.

The problem is that the whole folder name variable is set at installer build time and not when the installer is run, which means that I don't have a new temporary folder each time the same installer is run.

The code I'm using to create the folder is:

; Support folder
;  this folder will contain temporary files visibible only for the lifetime of the installation
!define /date SUPPORTDIR "$TEMP\${PRODUCT_NAME}_%y%m%d%H%M%S"

var InitSupportDirDone
function InitSupportDir
    ${if} $InitSupportDirDone != 1
        SetOutPath "${SUPPORTDIR}"
        !include supportfiles.nsh
        StrCpy $InitSupportDirDone 1
    ${endif}
functionend

This causes my SUPPORTDIR to be already set, as can be seen from the build log:

!define: "SUPPORTDIR"="$TEMP\Test-Proj_130911164903"

How can I change this so that the date (and folder name) is set each time the installer runs instead of at build time?

Upvotes: 0

Views: 1346

Answers (1)

Anders
Anders

Reputation: 101756

You could create a loop, starting with a 0 suffix and increasing it as long as a folder with that name exists but in you case you don't have to, just call InitPluginsDir in .onInit and use $pluginsdir as your temp folder...

Upvotes: 1

Related Questions