提供修复界面的NSIS安装包

; 该脚本由邦畿千里制作,可自由传播使用 QQ:911377

提供修复界面的NSIS安装包

下载源码

!include "LogicLib.nsh"

; 安装背景及文字
!define PRODUCT_TEXT_KEY "(邦畿千里)"
!define PRODUCT_TEXT_BACK "resource/back.bmp"
!define PRODUCT_TEXT_PROXCY "现无偿提供给NSIS爱好者使用!"
!define PRODUCT_TEXT_TEL "QQ:911137"
!define PRODUCT_TEXT_AREA "1.自动监测,修复,安装,删除!"
!define PRODUCT_TEXT_INTRUDUCE "2.自由替换图片、背景,注册动态库,执行Exe多种功能!"


; 安装程序初始定义常量
!define PRODUCT_PATH "邦畿千里系列软件"
!define PRODUCT_NAME "邦畿千里画图软件"
!define PRODUCT_MAINEXE "mspaint.exe"
!define PRODUCT_VERSION "2008"
!define PRODUCT_PUBLISHER "邦畿千里"
!define PRODUCT_WEB_SITE "http://www.baidu.com"
!define PRODUCT_REGRUN "Software/Microsoft/Windows/CurrentVersion/Run"
!define PRODUCT_DIR_REGKEY "Software/Microsoft/Windows/CurrentVersion/App Paths/${PRODUCT_PUBLISHER}/${PRODUCT_NAME}"
!define PRODUCT_UNINST_KEY "Software/Microsoft/Windows/CurrentVersion/Uninstall/${PRODUCT_TEXT_KEY}${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

SetCompressor lzma

; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
!include "MUI.nsh"

; MUI 预定义常量
;--------------------------------
;Interface Configuration
!define MUI_ABORTWARNING
;安装图标
!define MUI_ICON "resource/install.ico"
;卸载图标
!define MUI_UNICON "resource/uninstall.ico"
;上部图片
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "resource/header.bmp"
;左侧图片
!define MUI_WELCOMEFINISHPAGE_BITMAP "resource/left.bmp"
!define MUI_WELCOMEFINISHPAGE_BITMAP_NOSTRETCH
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "resource/left.bmp"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP_NOSTRETCH
;页面加载之前进行初始化
!define MUI_CUSTOMFUNCTION_GUIINIT ".onGUIBegin"

;-------------修复页面变量定义-----------------------
!include nsDialogs.nsh
Var UninstallFileName
Var RADIO_REPAIR
Var RADIO_REMOVE
Var Checkbox_State_REPAIR
Var Checkbox_State_REMOVE
Var Checkbox_State

;-------------页面定义---------------------------
; 欢迎页面
!insertmacro MUI_PAGE_WELCOME
; 修复页面
Page custom nsDialogsRepair nsDialogsRepairLeave
; 许可协议页面
!insertmacro MUI_PAGE_LICENSE "resource/licence.txt"
; 安装目录选择页面
!insertmacro MUI_PAGE_DIRECTORY
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安转完成后自动运行文件
!define MUI_FINISHPAGE_RUN "$INSTDIR/${PRODUCT_MAINEXE}"
; 安装完成页面
!insertmacro MUI_PAGE_FINISH
; 安装卸载确认页面
!insertmacro MUI_UNPAGE_CONFIRM
; 安装卸载过程页面
!insertmacro MUI_UNPAGE_INSTFILES
; 安装卸载完成页面
!insertmacro MUI_UNPAGE_FINISH
; 安装预释放文件
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "SimpChinese"
; ------ MUI 现代界面定义结束 ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "${PRODUCT_NAME} ${PRODUCT_VERSION}.exe"
InstallDir "$PROGRAMFILES/${PRODUCT_PATH}/${PRODUCT_NAME}"
InstallDirRegKey HKLM "${PRODUCT_UNINST_KEY}" "UninstallString"
ShowInstDetails hide
ShowUnInstDetails hide
BrandingText ${PRODUCT_PUBLISHER}

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

Section "!主程序" SEC01
SectionIn RO
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
CreateDirectory "$SMPROGRAMS/${PRODUCT_PATH}/${PRODUCT_NAME}"
; 创建开始菜单快捷方式
CreateShortCut "$SMPROGRAMS/${PRODUCT_PATH}/${PRODUCT_NAME}/${PRODUCT_NAME}.lnk" "$INSTDIR/${PRODUCT_MAINEXE}"
; 创建桌面快捷方式
CreateShortCut "$DESKTOP/${PRODUCT_NAME}.lnk" "$INSTDIR/${PRODUCT_MAINEXE}"
File "Program/Main/mspaint.exe"
SectionEnd

Section "-系统文件" SEC02
SectionIn RO
; 关闭日志,以保证不被卸载掉,主要用于公用文件
LogSet off
SetOutPath "$SYSDIR"
SetOverwrite ifnewer
File "Program/System/midas.dll"
; 注册动态库
regdll $SYSDIR/midas.dll
LogSet on
SectionEnd

/******************************
* 创建卸载快捷方式 *
******************************/
Section -AdditionalIcons
; 创建开始菜单卸载快捷方式
CreateShortCut "$SMPROGRAMS/${PRODUCT_PATH}/${PRODUCT_NAME}/Uninstall.lnk" "$INSTDIR/uninst.exe"
SectionEnd

/******************************
* 写注册表 *
******************************/
Section -Post
WriteUninstaller "$INSTDIR/uninst.exe"
; 系统启动自动运行软件
WriteRegStr HKLM "${PRODUCT_REGRUN}" "${PRODUCT_NAME}" "$INSTDIR/${PRODUCT_MAINEXE}"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR/${PRODUCT_MAINEXE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR/uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR/${PRODUCT_MAINEXE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd

/******************************
* 以下是安装程序的初始和结束部分 *
******************************/

; 页面加载之前进行初始化
Function .onInit
ReadRegStr $UninstallFileName ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString"
FunctionEnd

; 启动背景
Function .onGUIBegin
BgImage::SetBg /NOUNLOAD /FILLSCREEN ${PRODUCT_TEXT_BACK}
CreateFont $R0 "Comic Sans MS" 30 400
BgImage::AddText /NOUNLOAD "${PRODUCT_NAME}" $R0 0 0 255 48 18 798 198

CreateFont $R3 "Comic Sans MS" 10 100
BgImage::AddText /NOUNLOAD ${PRODUCT_TEXT_AREA} $R3 0 0 255 88 78 798 198
CreateFont $R4 "Comic Sans MS" 10 100
BgImage::AddText /NOUNLOAD ${PRODUCT_TEXT_INTRUDUCE} $R4 0 0 255 88 98 798 198

CreateFont $R1 "Comic Sans MS" 20 200
BgImage::AddText /NOUNLOAD ${PRODUCT_TEXT_PROXCY} $R1 0 0 255 68 118 798 198
CreateFont $R2 "Comic Sans MS" 20 200
BgImage::AddText /NOUNLOAD ${PRODUCT_TEXT_TEL} $R2 0 0 255 68 158 798 198

BgImage::Redraw /NOUNLOAD
FunctionEnd

; 销毁启动背景
Function .onGUIEnd
BgImage::Destroy
FunctionEnd

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

; 根据安装日志卸载文件的调用宏
!macro DelFileByLog LogFile
ifFileExists `${LogFile}` 0 +4
Push `${LogFile}`
Call un.DelFileByLog
Delete `${LogFile}`
!macroend

Section Uninstall

; 调用宏只根据安装日志卸载安装程序自己安装过的文件
!insertmacro DelFileByLog "$INSTDIR/install.log"

; 清除安装程序创建的且在卸载时可能为空的子目录,对于递归添加的文件目录,请由最内层的子目录开始清除(注意,不要带 /r 参数,否则会失去 DelFileByLog 的意义)
RMDir "$SMPROGRAMS/${PRODUCT_PATH}/${PRODUCT_NAME}"
RMDir "$SMPROGRAMS/${PRODUCT_PATH}"

RMDir "$INSTDIR"

DeleteRegValue HKLM "${PRODUCT_REGRUN}" "${PRODUCT_NAME}"
DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
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

/******************************
* 以下是安装程序的修复部分 *
******************************/

Function nsDialogsRepairLeave
${NSD_GetState} $RADIO_REPAIR $Checkbox_State_REPAIR
${NSD_GetState} $RADIO_REMOVE $Checkbox_State_REMOVE
${If} $Checkbox_State_REMOVE == ${BST_CHECKED}
Exec $UninstallFileName
Quit
${EndIf}
FunctionEnd

Function nsDialogsRepair
${if} $UninstallFileName == ""
Abort
${EndIf}
!insertmacro MUI_HEADER_TEXT "已经安装" "选择您要执行的操作"

nsDialogs::Create /NOUNLOAD 1018

${NSD_CreateLabel} 10u 0u 300u 30u "软件已经安装,请选择您要执行的操作,并点击『下一步(N)』继续"

${NSD_CreateRadioButton} 40u 30u 100u 30u "修复或重新安装"
Pop $RADIO_REPAIR
${If} $Checkbox_State_REPAIR == ${BST_CHECKED}
${NSD_Check} $RADIO_REPAIR
${NSD_GetState} $RADIO_REPAIR $Checkbox_State
${EndIf}

${NSD_CreateRadioButton} 40u 60u 100u 30u "卸载"
Pop $RADIO_REMOVE
${If} $Checkbox_State_REMOVE == ${BST_CHECKED}
${NSD_Check} $RADIO_REMOVE
${NSD_GetState} $RADIO_REMOVE $Checkbox_State
${EndIf}

${If} $Checkbox_State <> ${BST_CHECKED}
${NSD_Check} $RADIO_REPAIR
${EndIf}
nsDialogs::Show
FunctionEnd

你可能感兴趣的:(安装)