Advanced Uninstall Log NSIS Header
Author: Red Wine (talk, contrib) |
Links
Download
Download Advanced Uninstall Log NSIS header including 2 complete examples of usage.
- Main download link: Advunlog.zip (36 KB).
- Mirror download link: Advulog.zip (36 KB).
MD5: c586e6d4c707aae1737a4df67fa8e398
Discussion
- Winamp Forums thread.
This is the place to post your comments and suggestions. Also bugs reporting goes here.
Alternative
- http://nsis.sourceforge.net/Uninstall_only_installed_files - requires using new commands:
SetOutPath -> ${SetOutPath}, CreateDirectory -> ${CreateDirectory}
, etc.
Overview
Advanced Uninstall Log for NSIS was born in the need to cover a specific gap.
It's been discussed fairly enough that the File /r command is very useful
in cases when developers want to add a huge amount of sub directories and
files, nevertheless it has the disadvantage that such an installation should
be uninstalled with RmDir /r which is risky and removes also data that has
been added/created later within the installation folder.
About Advanced Uninstall Log
Advanced Uninstall Log is a macro system provided in a NSIS header that
is able to monitor an installation and build an uninstall log file which
is used by the uninstaller to uninstall files/directories that have been
added within specific installation blocks.
This means that files which have been installed outside these blocks,
or added later either by the user or application's activities, ignored
by the uninstaller.
Moreover files that might exist into the target directory prior the current
installation, are ignored as well.
Advanced Uninstall Log creates an uninstall log that removes only files that
have been installed and optionally interacts with users for every other file
and/or directory has found in installation folder and requires permission to
remove these files/directories.
It is enhanced as well to support updates, e.g. if the installer later would update the installation by adding new data, the uninstaller would remove the new data that has been added by the installer, without bothering users about.
Features
If target installation folder exists and contains files and/or directories
they all preserved from being uninstalled.
Uninstaller removes data that has been added within specific installation
blocks, preserving all other data that has been created/added outside of
these installation blocks. See included examples for details.
Supports unlimited updates/reinstallations.
Supports two uninstaller modes. Interactive mode requires confirmation
to remove every other file except those files that have been installed.
Unattended mode leaves intact every other file without bothering users.
In case when uninstall log (uninstall.dat) has been removed manually instead
of execute uninstaller, if users attempt to run the installer later, a warning
issued that they should select a new output folder.
Implements only the included with NSIS release headers FileFunc and TextFunc. There is no need for external plugins and headers, adds a very small overhead.
Restrictions
If uninstall log (uninstall.dat) is missing uninstaller won't execute at all.
Due to file create - write procedure that is required in order to add/update the uninstall log (uninstall.dat), restricted users on NT based systems won't be able to execute the installer.
Disadvantage
Since the header does not implement anything else than the common NSIS release, a delay occurs while builds and reads the uninstall log because it needs to throw the list several times. Talking for common cases, most likely the delay won't be noticeable, however, in cases where the target directory isn't empty and contains a large amount of data which will be excluded from uninstall log, or added large amount of data after the installation which will be excluded also, the delay should be noticeable.
Credits
A very big thanks goes to kichik NSIS developer.
When my idea of the Advanced Uninstall Log became an NSIS header, it was
indeed an amateur's attempt to write a flexible and errors free NSIS header.
Kichik dropped me a dozen of suggestions helping me to achieve my plan.
However, his main suggestion to eliminate the mentioned above disadvantage,
still remains untouched by me.
License
This header file is provided 'as-is', without any express or implied
warranty.
In no event will the author be held liable for any damages
arising from the use of this header file.
Permission is granted to anyone to use this header file for any purpose,
including commercial applications,
and to alter it and redistribute
it freely, subject to the following restrictions:
- The origin of this header file must not be misrepresented; you must not claim that you wrote the original header file.
- If you use this header file in a product, an acknowledgment in the product documentation would be appreciated but is not required.
- Altered versions must be plainly marked as such, and must not be misrepresented as being the original header file.
- This notice may not be removed or altered from any distribution.
Modifications
I, Tobbe, have made the texts in this header localizable. (Only messages actually seen by a user of the installer are localizable, not compile time error messages.) By defining UNINSTALLOG_LOCALIZE these text messages can be changed by using LangStrings. If UNINSTALLOG_LOCALIZE is not defined the header will use default messages written in English.
This is how it could look:
!define APP_NAME "Advanced Uninstall Log Demo" !define INSTDIR_REG_ROOT "HKLM" !define INSTDIR_REG_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP_NAME}" !include MUI.nsh !include AdvUninstLog.nsh Name "${APP_NAME}" OutFile "${APP_NAME}[MODERN UI].exe" ShowInstDetails show ShowUninstDetails show InstallDir "$PROGRAMFILES\${APP_NAME}" InstallDirRegKey ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "InstallDir" !insertmacro UNATTENDED_UNINSTALL !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_LICENSE "${NSISDIR}\COPYING" !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_UNPAGE_WELCOME !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES !insertmacro MUI_UNPAGE_FINISH !insertmacro MUI_LANGUAGE "English" ########################################################################################### ## The code below is what is needed to use my modification (if you want localized messages) ########################################################################################### !define UNINSTALLOG_LOCALIZE ;if you define this you have to provide language strings to use LangString UNLOG_HEADER ${LANG_ENGLISH} "=========== Uninstaller Log \ please do not edit this file ===========" LangString UNLOG_DAT_NOT_FOUND ${LANG_ENGLISH} "${UNINST_DAT} not found, \ unable to perform uninstall." LangString UNLOG_DEL_FILE ${LANG_ENGLISH} 'Delete File "$R9"?' LangString UNLOG_DEL_DIR ${LANG_ENGLISH} 'Delete Directory "$R9"?' LangString UNLOG_EMPTY_DIR ${LANG_ENGLISH} "Previous installation detected at $0.$\n\ Required file ${UNINSTALL_LOG}.dat is missing.$\n$\n\ It is highly recommended to select an \ empty directory and perform a fresh \ installation." LangString UNLOG_ERROR_LOG ${LANG_ENGLISH} "Error in log ${UNINSTALL_LOG}." LangString UNLOG_ERROR_CREATE ${LANG_ENGLISH} "Error creating ${UNINSTALL_LOG}." ########################################################################################### ## End my modifications ########################################################################################### Section "Main Application" sec01 SetOutPath '$INSTDIR' !insertmacro UNINSTALL.LOG_OPEN_INSTALL File /r /x "uninst-nsis.exe" /x "Docs" /x "Stubs" /x "Contrib" "${NSISDIR}\*" !insertmacro UNINSTALL.LOG_CLOSE_INSTALL CreateDirectory '$SMPROGRAMS\${APP_NAME}' WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "InstallDir" "$INSTDIR" WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "DisplayName" "${APP_NAME}" WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "UninstallString" "${UNINST_EXE}" SectionEnd Function .onInit !insertmacro UNINSTALL.LOG_PREPARE_INSTALL FunctionEnd Function .onInstSuccess !insertmacro UNINSTALL.LOG_UPDATE_INSTALL FunctionEnd Section UnInstall !insertmacro UNINSTALL.LOG_UNINSTALL "$INSTDIR" !insertmacro UNINSTALL.LOG_UNINSTALL "$APPDATA\${APP_NAME}" !insertmacro UNINSTALL.LOG_END_UNINSTALL DeleteRegKey /ifempty ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" SectionEnd Function UN.onInit !insertmacro UNINSTALL.LOG_BEGIN_UNINSTALL FunctionEnd
The above example is a stripped down version of the example included in the original download.
Here is the modified header (header only) AdvUninstLog_nsh.zip (2 KB) It can be viewed here: pastebin.com/f8fa1474