【问题标题】:nsis Advanced Uninstall Log - uninstaller needs to reside in a different dirnsis 高级卸载日志 - 卸载程序需要驻留在不同的目录中
【发布时间】:2014-09-08 14:27:17
【问题描述】:

要求 1: 要求我们的卸载程序仅删除安装程序安装的特定文件夹中的文件(即安装后添加的任何文件必须保持原样)。

要求 2: 还要求卸载程序驻留在上述文件夹以外的特定位置。

我在此处找到并尝试了“高级卸载日志 NSIS 标头”: http://nsis.sourceforge.net/Advanced_Uninstall_Log_NSIS_Header

虽然高级卸载日志 NSIS 标头看起来很有希望,(很好地满足要求 1),但我无法确定是否可以使其也适用于要求 2。

是否可以使用标头仅卸载已安装的文件并从与创建 .dat 文件的目录不同的目录调用?

提前致谢。

【问题讨论】:

  • 您愿意修改 AdvUninstLog.nsh 吗?它可能无需任何修改就可以完成,但需要更多的工作......
  • 嗨 Anders - 是的,我愿意修改 AdvUninstLog.nsh 并对其进行了研究,但不知道从哪里开始。有什么建议吗? (如果这不是此类讨论的适当论坛,请将我重定向到适当的位置。)

标签: logging header nsis uninstallation


【解决方案1】:

在 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

【讨论】:

  • 您的代码运行良好!不,我只需要弄清楚如何将相关部分插入我的应用程序中。
猜你喜欢
  • 2014-09-27
  • 2011-02-18
  • 2012-01-26
  • 1970-01-01
  • 2017-11-15
  • 2014-08-27
  • 2016-06-30
  • 2018-10-01
  • 2012-02-12
相关资源
最近更新 更多