我正在使用NSIS创建安装程序。创建安装程序时,我需要根据需要自定义屏幕。我知道我们不应该修改NSIS包含的.NSH文件。
因此,我的操作如下所示:但是在这里,我需要针对9种语言进行操作。有没有更好的方法来隔离每种语言的单独文件并在此处使用? 以及如何在自定义许可协议屏幕上添加按钮和复选框?
;Include Modern UI
!include "MUI2.nsh"
Name "PowerChute Personal Edition 4.0.1"
OutFile "PCPE_4.0.1.exe"
InstallDir "$PROGRAMFILES64\APC\PowerChute Personal Edition"
InstallDirRegKey HKLM "Software\APC\PowerChute Personal Edition" "Install_Dir"
RequestExecutionLevel admin
; Pages
;Page components
;Page directory
;Page instfiles
;UninstPage uninstConfirm
;UninstPage instfiles
;Customizing the Welcome Text
!define MUI_TEXT_WELCOME_INFO_TEXT "The Setup Wizard will install PowerChute Personal Edition on$\r$\n your computer. Click Next to continue or Cancel to exit the$\r$\n Setup Wizard."
!define MUI_WELCOMEFINISHPAGE_BITMAP "C:\Code\Code\PCPE\NULLSOFT\src\Bitmaps\dlgbmp-for-china.bmp"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyWelcomeShowCallback
!insertmacro MUI_PAGE_WELCOME
;Customizing the License Page Text
!define MUI_TEXT_LICENSE_TITLE "End-User License Agreement"
!define MUI_TEXT_LICENSE_SUBTITLE "Please read the following license agreement carefully"
!define MUI_INNERTEXT_LICENSE_BOTTOM ""
!define MUI_INNERTEXT_LICENSE_TOP ""
!define MUI_PAGE_CUSTOMFUNCTION_LICENSESHOW MyLicenseShowCallback
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\license.rtf"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_LICENSE "${NSISDIR}\Docs\Modern UI\license.rtf"
!insertmacro MUI_UNPAGE_COMPONENTS
!insertmacro MUI_UNPAGE_DIRECTORY
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English" ; The first language is the default language
!insertmacro MUI_LANGUAGE "PortugueseBR"
;--------------------------------
;Installer Functions
Function .onInit
FunctionEnd
;--------------------------------
; The stuff to install
; WELCOME PAGE CALLING FUNCTION
Function MyWelcomeShowCallback
SendMessage $mui.WelcomePage.Text ${WM_SETTEXT} 0 "STR:$(MUI_TEXT_WELCOME_INFO_TEXT)"
FunctionEnd
Function MyLicenseShowCallback
SendMessage $mui.LicensePage.Text ${WM_SETTEXT} 0 "STR:$(MUI_TEXT_LICENSE_TITLE)"
FunctionEnd
使用两个独立的.nsh文件(CustomChinese.nsh和CustomEnglish.nsh)更新代码:
根据您的输入,我将每种语言的!define语句保存在单独的.nsh文件(CustomChinese.nsh和CustomEnglish.nsh)中,然后将这些文件包含在我的.nsi文件中。
但是不允许同时包含两个.nsh文件(CustomChinese.nsh和CustomEnglish.nsh)和两个语言文件(!insertmacro MUI_LANGUAGE“英语”和!insertmacro MUI_LANGUAGE“中文”)。因此,我每个都只给出一个文件。但是,如何赋予多个文件,以便根据语言环境获取适当的文件?
下面是完整的代码:
Var IsOnLicensePage
Var PrintBtn
!include LogicLib.nsh
!include "MUI2.nsh"
Name "EMR 4.0"
OutFile "LocaleDlls.exe"
InstallDir $PROGRAMFILES\LocaleDlls
InstallDirRegKey HKLM "Software\NSIS_LocaleDlls" "Install_Dir"
; Request application privileges for Windows Vista
RequestExecutionLevel admin
;--------------------------------
; Pages
;Customizing the Welcome Text
!define MUI_WELCOMEFINISHPAGE_BITMAP "C:\Code\Code\PCPE\NULLSOFT\src\Bitmaps\dlgbmp-for-china.bmp"
!insertmacro MUI_PAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyLicenseShowCallback
!define MUI_LICENSEPAGE_CHECKBOX ""
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\license.rtf"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_LICENSE "${NSISDIR}\Docs\Modern UI\license.rtf"
!insertmacro MUI_UNPAGE_DIRECTORY
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
; Below are the Custom Language Files
;!include "CustomEnglish.nsh"
!include "CustomChinese.nsh"
;--------------------------------
;Languages
;!insertmacro MUI_LANGUAGE "English" ; The first language is the default language
!insertmacro MUI_LANGUAGE "Chinese"
;Installer Functions
;--------------------------------
Function MyLicenseShowCallback
GetDlgItem $0 $hwndparent 2 ; Find cancel button so we can copy its size and y position.
System::Call *(i,i,i,i)p.r1
System::Call 'USER32::GetWindowRect(pr0,pr1)'
System::Call *$1(i.r2,i.r3,i.r4,i.r5)
IntOp $5 $5 - $3 ;height
IntOp $4 $4 - $2 ;width
System::Call 'USER32::ScreenToClient(p$hwndparent,pr1)'
System::Call *$1(i.r2,i.r3)
System::Free $1
IntOp $2 $4 / 5 ; Calculate x padding based on the width but you can put any value you want in $2
System::Call 'USER32::CreateWindowEx(i 0,t "Button",t "Print",i ${WS_CHILD}|${WS_VISIBLE}|${WS_TABSTOP},i r2,i r3,i r4,i r5,p $hwndparent,p 0x666,p 0,p 0)p.r0'
StrCpy $PrintBtn $0
SendMessage $hwndparent ${WM_GETFONT} 0 0 $1
SendMessage $0 ${WM_SETFONT} $1 1
GetFunctionAddress $0 onmybtnclick
ButtonEvent::AddEventHandler 0x666 $0
FunctionEnd
Function onmybtnclick
ExecShell "open" "$INSTDIR\license.rtf" "0"
FunctionEnd
; The stuff to install
Section "LocaleDlls (required)"
SectionIn RO
; Set output path to the installation directory. Here is the path C:\Program Files\LocaleDlls
SetOutPath $INSTDIR
; Give the File path
System::Call 'KERNEL32::AddDllDirectory(w "$INSTDIR")' ; Tell Windows we trust all .DLLs in this directory
;MessageBox MB_OK "Return value = $Language"
${If} $Language == 1033
MessageBox MB_OK "Current Locale is English... Loading English Files"
File "C:\Code\Code\PCPE\Install\pcpe301\Chinese\license.rtf"
File "C:\Code\Code\PCPE\Install\pcpe301\Chinese\APC PCPE.chm"
${ElseIf} $Language = 2052
MessageBox MB_OK "Current Locale is Chinese... Loading Chinese Files"
File "C:\Code\Code\PCPE\Install\pcpe301\Chinese\license.rtf"
File "C:\Code\Code\PCPE\Install\pcpe301\Chinese\APC PCPE.chm"
${EndIf}
; Do the install
; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\NSIS_DllTesting "Install_Dir" "$INSTDIR"
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls" "DisplayName" "NSIS LocaleDlls"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\LocaleDlls" "NoRepair" 1
WriteUninstaller "uninstall.exe"
SectionEnd
**CustomChinese.nsh**
!echo "NSIS CustomChinese"
!addincludedir "${NSISDIR}\Contrib\Modern UI 2"
;--------------------------------
;For Welcome Page
!define MUI_TEXT_WELCOME_INFO_TITLE 欢迎使用 安装向导
!define MUI_TEXT_WELCOME_INFO_TEXT 欢迎使用 安装向导
;For License Agreement Page
!define MUI_TEXT_LICENSE_TITLE 最终用户许可协议
!define MUI_TEXT_LICENSE_SUBTITLE 请仔细阅读以下许可协议
!define MUI_INNERTEXT_LICENSE_BOTTOM
!define MUI_INNERTEXT_LICENSE_TOP
!define MUI_INNERTEXT_LICENSE_BOTTOM_CHECKBOX
!define MUI_LICENSEPAGE_CHECKBOX
!define MUI_LICENSEPAGE_CHECKBOX_TEXT 我接受许可协议中的条款
!insertmacro MUI_LANGUAGE "Chinese"
**CustomEnglish.nsh**
!echo "NSIS CustomEnglish"
!addincludedir "${NSISDIR}\Contrib\Modern UI 2"
;--------------------------------
;For Welcome Page
!define MUI_TEXT_WELCOME_INFO_TITLE "Welcome to the $(^NameDA) Setup Wizard"
!define MUI_TEXT_WELCOME_INFO_TEXT "The Setup Wizard will install EMR on$\r$\nyour computer. Click Next to continue or Cancel to exit the$\r$\nSetup Wizard."
;For License Agreement Page
!define MUI_TEXT_LICENSE_TITLE "End-User License Agreement"
!define MUI_TEXT_LICENSE_SUBTITLE "Please read the following license agreement carefully"
!define MUI_INNERTEXT_LICENSE_BOTTOM ""
!define MUI_INNERTEXT_LICENSE_TOP ""
!define MUI_INNERTEXT_LICENSE_BOTTOM_CHECKBOX ""
!define MUI_LICENSEPAGE_CHECKBOX ""
!define MUI_LICENSEPAGE_CHECKBOX_TEXT "I &agree to terms in the License Agreement"
!insertmacro MUI_LANGUAGE "English"
下面是两个.nsh文件中带有!ifdef语句的更新代码段:
就我而言,样本仍在工作。但是,如果我在“ MyEnglish.nsh”和“ MySwedish.nsh”中都包含MUI属性,例如(MUI_CANCEL_MESSAGE“确定要取消吗?”,则显示编译器错误:!define:“ MUI_CANCEL_MESSAGE”已定义! / p>
下面是代码:
english.nsh
!define MUI_CANCEL_MESSAGE "Are you sure you want to cancel EMR?"
!insertmacro MUI_LANGUAGE "English"
Sweedish.nsh
!define MUI_CANCEL_MESSAGE "Sind Sie sicher, dass Sie die Installation von?"
!insertmacro MUI_LANGUAGE "Swedish"
MySetup.nsi:
!include "english.nsh"
!include "Swedish.nsh"
Function onAbort
${If} $PageId <> 0
${If} ${Cmd} ` MessageBox MB_YESNO "${MUI_CANCEL_MESSAGE}" IDYES `
;Call WelLeave
SendMessage $HWNDPARENT 0x408 -$PageId ""
${EndIf}
Abort
${EndIf}
FunctionEnd
然后,如下所示更改了customenglish.nsh和Sweedish.nsh文件。这次它正在编译,但是当单击“取消”时,在弹出的消息框中它没有显示文本,而是显示“ $ {MUI_CANCEL_MESSAGE}”
english.nsh
!ifdef MUI_CANCELWARNING
${LangFileString} MUI_CANCEL_MESSAGE "Are you sure you want to cancel EMR?"
!endif
!insertmacro MUI_LANGUAGE "English"
Sweedish.nsh
!ifdef MUI_CANCELWARNING
${LangFileString} MUI_CANCEL_MESSAGE "Sind Sie sicher, dass Sie die Installation von?"
!endif
!insertmacro MUI_LANGUAGE "Swedish"
答案 0 :(得分:0)
有多种方法可以做到这一点。
您可以手动覆盖每种语言的每个MUI字符串:
!include "MUI2.nsh"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!define MUI_TEXT_WELCOME_INFO_TITLE "English title goes here"
!insertmacro MUI_LANGUAGE "English"
!define MUI_TEXT_WELCOME_INFO_TITLE "Swedish bork bork"
!insertmacro MUI_LANGUAGE "Swedish"
您可以将这些定义放在单独的文件中,如果需要每种语言一个替代文件,则可以!include
放置它们。
另一种方法是将所有与语言相关的说明放在您的自定义语言文件中:
MySetup.nsi:
!include "MUI2.nsh"
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!include "MyEnglish.nsh"
!include "MySwedish.nsh"
Section
DetailPrint $(myCustomString)
SectionEnd
MySwedish.nsh:
!define MUI_TEXT_WELCOME_INFO_TITLE "Swedish bork bork"
!insertmacro MUI_LANGUAGE "Swedish"
LangString myCustomString 0 "Bork !?"