Archive: How to clear temp folder?


How to clear temp folder?
My installer extracts silence.mp3 to the $TEMP and I have one problem with it. If any user will click Install, temp folder is cleared, cause there's following code in Section/SectionEnd:
[...]
Delete "$TEMP\silence.mp3"
[...]
But what if user will abort the installation? silence.mp3 won't be erased from the temp dir :/ Any idea how to delete it? :/


You could use the $PLUGINSDIR instead, far as I know that's deleted on cancel as well.

Otherwise, just add Delete "$TEMP\silence.mp3" into your .onUserAbort function.


Thank you very much! I'll check both options :D


Oh! One more question! Where $PLUGINSDIR stores temporary files?


$PLUGINSDIR is a variable that is assigned on runtime. It will point to a directory under $TEMP, "$TEMP\nst023.tmp\" is a good example. The installer will delete all files in this directory and then remove the directory when the installer quits. To set this up, simply call InitPluginsDir in the installer's .onInit callback function.


You can just MessageBox MB_OK "$PLUGINSDIR" to see it, it'll change each time.


Thanks!!!

I have a new problem :(
When I'm using $PLUGINSDIR silent.mp3 is removed but nsis temp folders containing files such as nsis logo, etc (which are created in temp dir) are not erased! And when I want to use...

Function .onUserAbort
Delete "$TEMP\silence.mp3"
FunctionEnd

...I got an error:
Function: ".onUserAbort"
Error: Function named ".onUserAbort" already exists.

But there *isnt* already existing function with such name! What's wrong?


You're using the MUI. You need to err do something clever.

*Looks it up*

Yes, use a custom function. MUI (annoyingly :)) defines its own .onUserAbort, so you have to define your own function which MUI somehow mashes into the original. You do this:

!define MUI_CUSTOMFUNCTION_ABORT "customAbortFunction"

Function "customAbortFunction"
Delete "$TEMP\silence.mp3"
FunctionEnd


:D
I really appreciate it, thanks!