NSIS根据安装文件log 卸载文件(防止误删)

来源:互联网 发布:it最新动态 编辑:程序博客网 时间:2024/06/05 07:07

1、在普通安装脚本前添加库

!include "LogicLib.nsh"

2、; 激活安装日志记录,该日志文件将会作为卸载文件的依据(注意,本区段必须放置在所有区段之前)

Section "-LogSetOn"  LogSet onSectionEnd

3、

/****************************** * 以下是安装程序的卸载部分 * ******************************/

; 根据安装日志卸载文件的调用宏

!macro DelFileByLog LogFile  ifFileExists `${LogFile}` 0 +4    Push `${LogFile}`    Call un.DelFileByLog    Delete `${LogFile}`!macroendSection Uninstall  !insertmacro MUI_STARTMENU_GETFOLDER "Application" $ICONS_GROUP  Delete "$INSTDIR\${PRODUCT_NAME}.url"; 调用宏只根据安装日志卸载安装程序自己安装过的文件!insertmacro DelFileByLog "$INSTDIR\install.log"  ; 清除安装程序创建的且在卸载时可能为空的子目录,对于递归添加的文件目录,请由最内层的子目录开始清除(注意,不要带 /r 参数,否则会失去 DelFileByLog 的意义)RMDir "$SMPROGRAMS\$ICONS_GROUP"SectionEnd

-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--

; 以下是卸载程序通过安装日志卸载文件的专用函数,请不要随意修改      Function un.DelFileByLog      Exch $R0      Push $R1      Push $R2      Push $R3      FileOpen $R0 $R0 r      ${Do}        FileRead $R0 $R1        ${IfThen} $R1 == `` ${|} ${ExitDo} ${|}        StrCpy $R1 $R1 -2        StrCpy $R2 $R1 11        StrCpy $R3 $R1 20        ${If} $R2 == "File: wrote"        ${OrIf} $R2 == "File: skipp"        ${OrIf} $R3 == "CreateShortCut: out:"        ${OrIf} $R3 == "created uninstaller:"          Push $R1          Push `"`          Call un.DelFileByLog.StrLoc          Pop $R2          ${If} $R2 != ""            IntOp $R2 $R2 + 1            StrCpy $R3 $R1 "" $R2            Push $R3            Push `"`            Call un.DelFileByLog.StrLoc            Pop $R2            ${If} $R2 != ""              StrCpy $R3 $R3 $R2              Delete /REBOOTOK $R3            ${EndIf}          ${EndIf}        ${EndIf}        StrCpy $R2 $R1 7        ${If} $R2 == "Rename:"          Push $R1          Push "->"          Call un.DelFileByLog.StrLoc          Pop $R2          ${If} $R2 != ""            IntOp $R2 $R2 + 2            StrCpy $R3 $R1 "" $R2            Delete /REBOOTOK $R3          ${EndIf}        ${EndIf}      ${Loop}      FileClose $R0      Pop $R3      Pop $R2      Pop $R1      Pop $R0    FunctionEnd    Function un.DelFileByLog.StrLoc      Exch $R0      Exch      Exch $R1      Push $R2      Push $R3      Push $R4      Push $R5      StrLen $R2 $R0      StrLen $R3 $R1      StrCpy $R4 0      ${Do}        StrCpy $R5 $R1 $R2 $R4        ${If} $R5 == $R0        ${OrIf} $R4 = $R3          ${ExitDo}        ${EndIf}        IntOp $R4 $R4 + 1      ${Loop}      ${If} $R4 = $R3        StrCpy $R0 ""      ${Else}        StrCpy $R0 $R4      ${EndIf}      Pop $R5      Pop $R4      Pop $R3      Pop $R2      Pop $R1      Exch $R0    FunctionEnd
这期间或许会遇到该问题。
Section: "-LogSetOn"
错误: 已指定 LogSet , 但未定义 NSIS_CONFIG_LOG .
是这样的提示,请问怎么解决呢?

代码是用HM VNISEdit 脚本编辑器向导产生
代码里都有:
!include "LogicLib.nsh"
; 激活安装日志记录,该日志文件将会作为卸载文件的依据(注意,本区段必须放置在所有区段之前)
Section "-LogSetOn"
LogSet on
SectionEnd
最佳答案
根据你的 NSIS 版本下载开启安装 log 的文件覆盖你原来的 NSIS 文件夹中同名文件:
http://sourceforge.net/projects/nsis/files/
比如 NSIS 2.46,就下载 nsis-2.46-log.zip 覆盖你 NSIS 中同名文件。

0 0
原创粉丝点击