脚本:仿Inno安装页面

优质
小牛编辑
150浏览
2023-12-01

引用 Setup.nsi 的内容:

!addPluginDir ".\"
!include "MUI2.nsh"
!include "WinVer.nsh"
!include "TextFunc.nsh"

Name "测试程序"
Caption "$(^NameDA) 1.0"
OutFile Setup.exe
;SetFont "Tahoma" 8
InstallDir $TEMP

RequestExecutionLevel Admin

!define __NSD_Textbox_CLASS EDIT
!define __NSD_Textbox_STYLE ${DEFAULT_STYLES}|${WS_VSCROLL}|${WS_TABSTOP}|${ES_MULTILINE}
!define __NSD_Textbox_EXSTYLE ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE}
!insertmacro __NSD_DefineControl Textbox

;卸载项目位置
!define PRODUCT_UNINST_ROOT "HKLM"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\{88B5E49E-3D0E-49F8-8BC6-BBB276B3CB21}"

!define MUI_COMPONENTSPAGE_NODESC
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
Var ICONS_GROUP
;!define MUI_STARTMENUPAGE_NODISABLE
!define MUI_STARTMENUPAGE_ID Application
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "$(^NameDA)"
;将开始菜单文件夹记录在卸载项目。如果放在其他位置,请更改。
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT}"
!define MUI_STARTMENUPAGE_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "NSIS:StartMenu"
!insertmacro MUI_PAGE_STARTMENU ${MUI_STARTMENUPAGE_ID} $ICONS_GROUP
Page custom AddTasks GetState
Page custom Prepare
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese"

InstType "完全"
InstType "精简"

Section "安装组件示例①" SEC01
SectionIn 1 2
SectionEnd

Section /o "安装组件示例②" SEC02
SectionIn 1
SectionEnd

Section /o "安装组件示例③" SEC03
SectionIn 1
SectionEnd


Var HCHK1
Var HCHK2
Var TEXT1
Var TEXT2

;脚本仅示范页面,无论选中与否均不执行任何操作,包括创建快捷方式。
;请自行在页面离开函数判断是否选中,并相应创建快捷方式或其他功能。

;要选中附加任务选项
Function .onInit
StrCpy $HCHK1 1
;StrCpy $HCHK2 1
SendMessage ${HWND_BROADCAST} ${WM_SETTINGCHANGE} 0 0
;Delete /RebootOK $EXEFILE
Rename /RebootOK $EXEFILE $EXEFILE.tmp
FunctionEnd

Function AddTasks

    !insertmacro MUI_HEADER_TEXT "选择附加任务" "您想要安装程序执行哪些附加任务?"
    nsDialogs::Create 1018
    Pop $0
    ${If} $0 == error
        Abort
    ${EndIf}

    ${NSD_CreateLabel} 0u 0u 300u 18u "选择您想要安装程序在安装“$(^NameDA)”时执行的附加任务,然后单击“下一步”。"
    Pop $1

    ${NSD_CreateCheckBox} 10u 23u 280u 9u "创建桌面快捷方式"
    Pop $2
    ${NSD_SetState} $2 $HCHK1

    ${NSD_CreateCheckBox} 10u 37u 280u 9u "创建快速启动栏快捷方式"
    Pop $3
    ${NSD_SetState} $3 $HCHK2

    nsDialogs::Show

FunctionEnd

Function GetState

    SendMessage $2 ${BM_GETSTATE} 0 0 $HCHK1
    SendMessage $3 ${BM_GETSTATE} 0 0 $HCHK2
    ${NSD_GetText} $2 $TEXT1
    ${NSD_GetText} $3 $TEXT2

FunctionEnd

Function Prepare

    !insertmacro MUI_HEADER_TEXT "准备安装" "安装程序现在准备开始安装“$(^NameDA)”到您的电脑中。"

    nsDialogs::Create 1018
    Pop $0
    ${If} $0 == error
        Abort
    ${EndIf}


    Var /Global PREPARE_TEMP
    Var /Global PREPARE_TEXT

    ${NSD_CreateLabel} 0u 0u 300u 18u "单击“安装”继续此安装程序。如果您想要回滚或改变设置,请单击“上一步”。"
    Pop $1

    ${If} ${IsNT}
      StrCpy $0 "SOFTWARE\Microsoft\Windows NT\CurrentVersion"
    ${Else}
      StrCpy $0 "SOFTWARE\Microsoft\Windows\CurrentVersion"
    ${EndIf}

    StrCpy $PREPARE_TEMP ""
    StrCpy $PREPARE_TEXT ""

    ReadRegStr $R0 HKLM $0 RegisteredOwner
    StrCpy $PREPARE_TEXT "$PREPARE_TEXT用户信息:$\r$\n      $R0$\r$\n"
    ReadRegStr $R0 HKLM $0 RegisteredOrganization
    StrCpy $PREPARE_TEXT "$PREPARE_TEXT      $R0$\r$\n$\r$\n"

    StrCpy $PREPARE_TEXT "$PREPARE_TEXT目标位置:$\r$\n      $INSTDIR$\r$\n$\r$\n"

    GetCurInstType $0
    IntCmp $0 ${NSIS_MAX_INST_TYPES} 0 +3 +3
    StrCpy $0 "$(^Custom)"
    Goto +2
    InstTypeGetText $0 $0
    StrCpy $PREPARE_TEXT "$PREPARE_TEXT安装类型:$\r$\n      $0$\r$\n$\r$\n"

    SectionGetFlags ${SEC01} $0
    IntCmp $0 ${SF_SELECTED} 0 +3 +3
    SectionGetText ${SEC01} $0
    StrCpy $PREPARE_TEMP "$PREPARE_TEMP      $0$\r$\n"

    SectionGetFlags ${SEC02} $0
    IntCmp $0 ${SF_SELECTED} 0 +3 +3
    SectionGetText ${SEC02} $0
    StrCpy $PREPARE_TEMP "$PREPARE_TEMP      $0$\r$\n"

    SectionGetFlags ${SEC03} $0
    IntCmp $0 ${SF_SELECTED} 0 +3 +3
    SectionGetText ${SEC03} $0
    StrCpy $PREPARE_TEMP "$PREPARE_TEMP      $0$\r$\n"

    ;SectionGetFlags ${组件索引} $0
    ;IntCmp $0 ${SF_SELECTED} 0 +3 +3
    ;SectionGetText ${组件索引} $0
    ;StrCpy $PREPARE_TEMP "$PREPARE_TEMP      $0$\r$\n"

    StrCmp $PREPARE_TEMP "" +2
    StrCpy $PREPARE_TEXT "$PREPARE_TEXT选定组件:$\r$\n$PREPARE_TEMP$\r$\n"

    !insertmacro MUI_STARTMENU_WRITE_BEGIN ${MUI_STARTMENUPAGE_ID}
    StrCpy $PREPARE_TEXT "$PREPARE_TEXT开始菜单文件夹:$\r$\n      $ICONS_GROUP$\r$\n$\r$\n"
    !insertmacro MUI_STARTMENU_WRITE_END

    StrCpy $PREPARE_TEMP ""

    IntCmp $HCHK1 ${BST_CHECKED} 0 +2 +2
    StrCpy $PREPARE_TEMP "$PREPARE_TEMP      $TEXT1$\r$\n"

    IntCmp $HCHK2 ${BST_CHECKED} 0 +2 +2
    StrCpy $PREPARE_TEMP "$PREPARE_TEMP      $TEXT2$\r$\n"

    IntOp $R0 $HCHK1 || $HCHK2
    IntCmp $R0 0 +2
    StrCpy $PREPARE_TEXT "$PREPARE_TEXT附加任务:$\r$\n$PREPARE_TEMP"

    ${TrimNewLines} $PREPARE_TEXT $PREPARE_TEXT

    ${NSD_CreateTextbox} 0u 24u 300u 116u "$PREPARE_TEXT"
    Pop $2
    SendMessage $2 ${EM_SETREADONLY} 1 0

    nsDialogs::Show

FunctionEnd