- NSIS Discussion
- Problem to delete installer when cancel
Archive: Problem to delete installer when cancel
skuallpa
27th July 2009 12:57 UTC
Problem to delete installer when cancel
Hello,
I am working on an updater. Once the download is done, the updater is automatically launched, then overwrite some files and finally delete itself (using the SelfDel plug-in)
Function .onInstSuccess
SelfDel::del
FunctionEnd
This works well.
However the updater is not deleted in the following case.
At the very beginning of the updater, the user can choose language:
Function .onInit
;display multilanguage list
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
If the user press "cancel" in the window that appear to choose the language, the updater exit and the updater file is not deleted.
How can I deal with this case?
Thanks in advance
MSG
27th July 2009 13:14 UTC
Have you tried calling selfdel from another callback function, such as .onGUIEnd or .onInstFailed?
skuallpa
27th July 2009 13:53 UTC
Thanks for your reply MSG,
I just tried calling SelfDel from inside the .onGUIEnd and .onInstFailed function but the updater has not been deleted.
I have also tried calling from inside .onUserAbort but this gave me a compilation error. (function .onUserAbort already defined).
Is the .onUserAbort already defined in the macro ?
!insertmacro MUI_LANGDLL_DISPLAY
Another idea?
MSG
27th July 2009 14:27 UTC
Ah, yes, onuserabort and some other callbacks are used in MUI. You have to use this instead:
!define MUI_CUSTOMFUNCTION_ABORT MyOnUserAbort
Function MyOnUserAbort
SelfDel::del
FunctionEnd
See http://nsis.sourceforge.net/Docs/Mod...02/Readme.html (search for 'custom functions')
Kshiro
27th July 2009 16:28 UTC
I used this to enable Cancel Button during installing .
GetDlgItem $0 $HWNDPARENT 2
EnableWindow $0 1
And i used SelfDel plug-in but it only work when extract the first file . If i click cancel button when extracting above 2nd file , it dont work .
skuallpa
28th July 2009 09:31 UTC
Thanks for these answers.
I have tried this
!define MUI_CUSTOMFUNCTION_ABORT MyOnUserAbort
Function MyOnUserAbort
SelfDel::del
FunctionEnd
But this doesn't work. The updater is still not deleted if user press cancel in the window in which he can choose the language.
Concerning the solution proposed by Kshiro: I don't see very well how to use this code. The cancel button is already enable. I just want to remove installer if user press cancel.
jpderuiter
28th July 2009 13:14 UTC
This is because the MUI_LANGDLL_DISPLAY macro calls Abort when the user canceled the Languages dialog, which causes an instant quit of the installer (see chapter 4.7.2.1.2 of the NSIS user manual).
I think this some sort of bug in MUI.
You can prevent this by removing
${if} $LANGUAGE == "cancel"
Abort
${endif}
from the MUI_LANGDLL_DISPLAY macro (in Localization.nsh for MUI2)
You need to add this then in the .onInit function after calling MUI_LANGDLL_DISPLAY.
Afrow UK
29th July 2009 01:59 UTC
Maybe you should post a feature request for a MUI_CUSTOMFUNCTION_LANGDLL_ABORT MyOnUserAbort or something similar.
Stu
skuallpa
29th July 2009 08:29 UTC
Thanks for these answers
So I have finally edit the file Localization.nsh (located in Program Files\NSIS\Contrib\Modern UI 2). I have add the following line
Pop $LANGUAGE
${if} $LANGUAGE == "cancel"
SelfDel::del ;remove updater file
Abort
${endif}
and let in my installer the functions
!define MUI_CUSTOMFUNCTION_ABORT MyOnUserAbort
Function MyOnUserAbort
SelfDel::del ;remove updater file
FunctionEnd
Function .onInstSuccess
SelfDel::del ;remove updater file
FunctionEnd
So that, the updater file is deleted:
-If the user directly press cancel during the language selection
-If the user cancel the installation
-after the installation was successful.
Thanks again for your help