; 该脚本使用 HM VNISEdit 脚本编辑器向导产生

; 安装程序初始定义常量
!define PRODUCT_NAME ""
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER " Inc."
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"

SetCompressor lzma

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

; MUI 预定义常量
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

; 语言选择窗口常量设置
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"

; 欢迎页面
!insertmacro MUI_PAGE_WELCOME
; 许可协议页面
;!insertmacro MUI_PAGE_LICENSE "Licence.txt"
; 安装过程页面
!insertmacro MUI_PAGE_INSTFILES
; 安装完成页面
!define MUI_FINISHPAGE_RUN "$INSTDIR\WPF.exe"
!insertmacro MUI_PAGE_FINISH

; 安装卸载过程页面
!insertmacro MUI_UNPAGE_INSTFILES

; 安装界面包含的语言设置
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese"

; 安装预释放文件
!insertmacro MUI_RESERVEFILE_LANGDLL
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
; ------ MUI 现代界面定义结束 ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Lane.exe"
InstallDir "$PROGRAMFILES\Lane"
ShowInstDetails show
ShowUnInstDetails show
BrandingText " "

Section "MainSection" SEC01
  SetOutPath "$INSTDIR"
  SetOverwrite ifnewer
  File /r "Release\*.*"
  SetOutPath "$INSTDIR\configs"
     ${If} $LANGUAGE == '
      File "configs\zh-CN\app-config.xml"
    ${Else}
      File "configs\en-US\app-config.xml"
  ${EndIf}

  CreateDirectory "$SMPROGRAMS\Lane" /*所有程序文件夹*/
  CreateShortCut "$SMPROGRAMS\Lane\Lane.lnk" "$INSTDIR\WPF.exe" /*所有程序--快捷方式*/
  CreateShortCut "$DESKTOP\Lane.lnk" "$INSTDIR\WPF.exe" /*桌面--快捷方式*/
  CreateShortCut "$SMSTARTUP\Lane.lnk" "$INSTDIR\WPF.exe" /*自启动--快捷方式*/
  Call GetNetFrameworkVersion
    Pop $R1
  ${If} $R1 < '2.0.50727'
  SetDetailsPrint textonly
  DetailPrint "正在安装 .NET Framework 2.0 SP2..."
  SetDetailsPrint listonly

  SetOutPath "$INSTDIR"
  SetOverwrite on
  File "Framwork2.0\dotnetfx.exe"
  ExecWait '"$INSTDIR\dotnetfx.exe"'
  Delete "$INSTDIR\dotnetfx.exe"
  ${ElseIf} $R1 < '3.0'
  File "Framwork2.0\dotnetfx.exe"
  ExecWait '"$INSTDIR\dotnetfx.exe"'
  Delete "$INSTDIR\dotnetfx.exe"
  ${ElseIf} $R1 < '3.5'
  File "Framwork2.0\dotnetfx.exe"
  ExecWait '"$INSTDIR\dotnetfx.exe"'
  Delete "$INSTDIR\dotnetfx.exe"
  ${ElseIf} $R1 < '4.0'
  File "Framwork2.0\dotnetfx.exe"
  ExecWait '"$INSTDIR\dotnetfx.exe"'
  Delete "$INSTDIR\dotnetfx.exe"
  ${ElseIf} $R1 < '4.5'
  File "Framwork2.0\dotnetfx.exe"
  ExecWait '"$INSTDIR\dotnetfx.exe"'
  Delete "$INSTDIR\dotnetfx.exe"
  ${EndIf}
SectionEnd

Section -AdditionalIcons
  CreateShortCut "$SMPROGRAMS\Lane\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd

Section -Post
  WriteUninstaller "$INSTDIR\uninst.exe"
  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}" "DisplayVersion" "${PRODUCT_VERSION}"
  WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd

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

Function GetNetFrameworkVersion
    ;获取.Net Framework版本,支持
    Push $
    Push $

    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Install"
    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Version"
    StrCmp $  KnowNetFrameworkVersion +

    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0\Client" "Install"
    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0\Client" "Version"
    StrCmp $  KnowNetFrameworkVersion +

    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" "Install"
    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" "Version"
    StrCmp $  KnowNetFrameworkVersion +

    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup" "InstallSuccess"
    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup" "Version"
    StrCmp $  KnowNetFrameworkVersion +

    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" "Install"
    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" "Version"
    StrCmp $  +
    StrCpy $ "2.0.50727.832"
    StrCmp $  KnowNetFrameworkVersion +

    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322" "Install"
    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322" "Version"
    StrCmp $  +
    StrCpy $ "1.1.4322.573"
    StrCmp $  KnowNetFrameworkVersion +

    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\.NETFramework\policy\v1.0" "Install"
    ReadRegDWORD $ HKLM "SOFTWARE\Microsoft\.NETFramework\policy\v1.0" "Version"
    StrCmp $  +
    StrCpy $ "1.0.3705.0"
    StrCmp $  KnowNetFrameworkVersion +

    StrCpy $ "not .NetFramework"
    KnowNetFrameworkVersion:
    Pop $
    Exch $
FunctionEnd

Function .onInit
  !insertmacro MUI_LANGDLL_DISPLAY

FunctionEnd

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

Section Uninstall
  Delete "$INSTDIR\uninst.exe"

  Delete "$SMPROGRAMS\Lane\Uninstall.lnk"
  Delete "$DESKTOP\Lane.lnk"
  Delete "$SMPROGRAMS\Lane\Lane.lnk"
  Delete "$SMSTARTUP\Lane.lnk"
  RMDir "$SMPROGRAMS\Lane"
  RMDir /r "$INSTDIR\zh-Hant"
  RMDir /r "$INSTDIR\zh-Hans"
  RMDir /r "$INSTDIR\Logs"
  RMDir /r "$INSTDIR\ko"
  RMDir /r "$INSTDIR\ja"
  RMDir /r "$INSTDIR\it"
  RMDir /r "$INSTDIR\fr"
  RMDir /r "$INSTDIR\es"
  RMDir /r "$INSTDIR\en"
  RMDir /r "$INSTDIR\de"
  RMDir /r "$INSTDIR\configs"
  RMDir /r "$INSTDIR"
  RMDir "$INSTDIR"

  DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
  SetAutoClose true
SectionEnd

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

Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
  MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2
  Abort
FunctionEnd

Function un.onUninstSuccess
  HideWindow
  MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。"
FunctionEnd
05-11 13:51