要求1: 我们的卸载程序必须只删除安装程序安装的特定文件夹中的文件(即安装后添加的任何文件必须保持不变)。
要求2: 还需要卸载程序驻留在上述文件夹以外的特定位置。
我找到并尝试了高级卸载日志NSIS标题"在这里找到: http://nsis.sourceforge.net/Advanced_Uninstall_Log_NSIS_Header
虽然高级卸载日志NSIS标头看起来非常有前景,(很好地满足要求1),但我无法确定是否可以使它也适用于要求2.
标头是否可以用于仅卸载已安装的文件,并且可以从除创建.dat文件的目录以外的其他目录调用?
提前致谢。
答案 0 :(得分:0)
在AdvUninstLog.nsh中,您应该注释掉与UNINST_EXE
相关的任何内容,尤其是WriteUninstaller
行。我不确定你是否想要.dat和卸载程序在同一目录中,所以我使用单独的目录只是为了安全起见。
...
!include AdvUninstLog.nsh
!insertmacro UNATTENDED_UNINSTALL
Page Directory
Page InstFiles
Function .onInit
!insertmacro UNINSTALL.LOG_PREPARE_INSTALL
FunctionEnd
Function .onInstSuccess
!insertmacro UNINSTALL.LOG_UPDATE_INSTALL
FunctionEnd
Section "Main Application"
SetOutPath "$InstDir\foo"
WriteUninstaller "$InstDir\foo\uninst.exe"
SetOutPath "$InstDir\data"
!insertmacro UNINSTALL.LOG_OPEN_INSTALL
File /r "${NSISDIR}\Plugins\*" ; "random" files
!insertmacro UNINSTALL.LOG_CLOSE_INSTALL
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" '"$InstDir\foo\uninst.exe"'
; Because the UNINSTALL.LOG_UPDATE_INSTALL macro is responsible for writing the .dat
; it is important to set $InstDir to the directory you want it to be located in.
; This must be done as the last step in your last Section so that $InstDir has
; the correct path when .onInstSuccess is executed.
SetOutPath "$InstDir\bar" ; Make sure the directory exists
StrCpy $InstDir "$InstDir\bar"
SectionEnd
Section UnInstall
; In the uninstaller the initial value of $InstDir is the folder the uninstaller .exe is in.
; In this example I put it in a subfolder so we need to get the root of our install:
GetFullPathname $InstDir "$InstDir\..\"
; This is important, it changes $InstDir to the folder where the .dat is located.
Push $InstDir ; Save
StrCpy $InstDir "$InstDir\bar"
!insertmacro UNINSTALL.LOG_BEGIN_UNINSTALL
Pop $InstDir ; Restore
!insertmacro UNINSTALL.LOG_UNINSTALL "$INSTDIR\data"
!insertmacro UNINSTALL.LOG_END_UNINSTALL
DeleteRegKey /ifempty ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}"
; Because the uninstaller and the .dat were located in their own (unlogged) folders
; we need to manually delete them:
Delete "$INSTDIR\foo\uninst.exe"
RMDir "$INSTDIR\foo"
Delete "$INSTDIR\bar\${UNINSTALL_LOG}.dat"
RMDir "$INSTDIR\bar"
RMDir "$INSTDIR"
SectionEnd