📄 installer.nsi
字号:
# The contents of this file are subject to the BitTorrent Open Source License# Version 1.0 (the License). You may not copy or use this file, in either# source code or executable form, except in compliance with the License. You# may obtain a copy of the License at http://www.bittorrent.com/license/.## Software distributed under the License is distributed on an AS IS basis,# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License# for the specific language governing rights and limitations under the# License.# Written by Bram Cohen, Matt Chisholm and Greg Hazel;--------------------------------;Include Modern UI!include "MUI.nsh"; replaced by winprepnsi.py!define VERSION "%VERSION%"!define APPNAME "%APP_NAME%"Outfile ${APPNAME}-${VERSION}.exeName "${APPNAME}";SilentInstall silent; automatically close the installer when done.;AutoCloseWindow trueCRCCheck onSetCompressor /SOLID lzma; adds xp style supportXPStyle onInstProgressFlags smooth InstallDir "$PROGRAMFILES\${APPNAME}\"; " this fixes syntax highlighting in xemacs :)!define EXENAME "bittorrent.exe"VAR KILLEXENAMEVAR UPGRADE!define MUI_ICON "images\bittorrent.ico"!define MUI_UNICON "images\bittorrent.ico"!define MUI_LANGDLL_ALWAYSSHOW!define MUI_LANGDLL_REGISTRY_ROOT HKCU!define MUI_LANGDLL_REGISTRY_KEY "Software\BitTorrent"!define MUI_LANGDLL_REGISTRY_VALUENAME "Language";--------------------------------;Pages Page custom installer.upgrade Page custom uninstall!define MUI_PAGE_CUSTOMFUNCTION_SHOW disableBackButton!define MUI_PAGE_HEADER_TEXT "Warning"!define MUI_PAGE_HEADER_SUBTEXT "From ${APPNAME}"!define MUI_LICENSEPAGE_TEXT_TOP "${APPNAME} is 100% FREE, and it always will be."!define MUI_LICENSEPAGE_BUTTON "$(^NextBtn)"!define MUI_LICENSEPAGE_TEXT_BOTTOM " " !insertmacro MUI_PAGE_LICENSE "installer.warning.rtf" Page custom installer.directory installer.directory.leave !define MUI_INSTFILESPAGE_FINISHHEADER_SUBTEXT "${APPNAME} has been successfully installed!" !insertmacro MUI_PAGE_INSTFILES!define MUI_FINISHPAGE_TITLE "${APPNAME} Setup Complete"!define MUI_FINISHPAGE_RUN "$INSTDIR\bittorrent.exe"; this is an opt-in url, we want to make it opt-out!define MUI_FINISHPAGE_LINK "&Visit BitTorrent.com to search for torrents!"!define MUI_FINISHPAGE_LINK_LOCATION http://www.bittorrent.com; so we hi-jack the readme option!define MUI_FINISHPAGE_SHOWREADME!define MUI_FINISHPAGE_SHOWREADME_TEXT "Create a &shortcut to BitTorrent on the Desktop"!define MUI_FINISHPAGE_SHOWREADME_FUNCTION "desktop_shortcut"!define MUI_FINISHPAGE_NOREBOOTSUPPORT !insertmacro MUI_PAGE_FINISH !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES;--------------------------------;Languages%LANG_MACROS%; example:;LangString TEXT_FOO ${LANG_ENGLISH} "Foo thing in English" ;--------------------------------;Reserve Files ;Things that need to be extracted on first (keep these lines before any File command!) ;Only for BZIP2 compression ReserveFile "installer.upgrade.ini" ReserveFile "installer.directory.ini" !insertmacro MUI_RESERVEFILE_INSTALLOPTIONSVar HWNDVar DLGITEMFunction desktop_shortcut ; Create desktop link SetShellVarContext all CreateShortCut "$DESKTOP\${APPNAME}.lnk" "$INSTDIR\${EXENAME}"FunctionEndFunction uninstall ;; IMPORTANT: We cannot ever run any old installers, because they might delete the ;; old installation directory, including any data the user might have stored there. ;; Newer uninstallers play nice, but we cannot tell them apart. ; check here too, since this page is run either way ;Call GetUninstallString ;Pop $R0 ;StrCmp $R0 "" nextuninst ;;Run the uninstaller ;;Do not copy the uninstaller to a temp file ;ExecWait '$R0 /S' ;IfErrors 0 nextuninst ;ExecWait '$R0 /S' ;Sleep 2000 ;IfErrors no_remove_uninstaller ;Goto nextuninst ;no_remove_uninstaller: ; Call MagicUninstall nextuninst: Call QuitIt ClearErrors Delete $INSTDIR\btdownloadgui.exe IfErrors deleteerror Delete $INSTDIR\btmaketorrentgui.exe IfErrors deleteerror Delete $INSTDIR\bittorrent.exe IfErrors deleteerror Delete $INSTDIR\maketorrent.exe IfErrors deleteerror Delete $INSTDIR\choose_language.exe IfErrors deleteerror goto endofdelete deleteerror: MessageBox MB_OK "Removing old BitTorrent exe files failed. You must quit BitTorrent and uninstall it before installing this version." Abort endofdelete: Call MagicUninstall endofuninst:FunctionEndFunction installer.upgrade !insertmacro MUI_HEADER_TEXT "Upgrade" "${APPNAME} ${VERSION}" !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "installer.upgrade.ini" Pop $HWND ;HWND of dialog GetDlgItem $DLGITEM $HWND 1200 ;1200 + Field number - 1 SendMessage $DLGITEM ${WM_SETTEXT} 0 "STR:A version of ${APPNAME} is already installed." GetDlgItem $DLGITEM $HWND 1201 ;1200 + Field number - 1 SendMessage $DLGITEM ${WM_SETTEXT} 0 "STR:This installer will upgrade to ${APPNAME} ${VERSION}." !insertmacro MUI_INSTALLOPTIONS_SHOWFunctionEndFunction installer.directory StrCmp $UPGRADE "no" OK Abort OK: !insertmacro MUI_HEADER_TEXT "Choose Install Location" "Choose the folder in which to install ${APPNAME}" StrCpy $4 $INSTDIR StrCpy $5 ${APPNAME} InstallOptionsEx::initDialog /NOUNLOAD "$PLUGINSDIR\installer.directory.ini" Pop $hwnd ;HWND of dialog !insertmacro MUI_INSTALLOPTIONS_READ $0 "installer.directory.ini" "Field 3" "State" StrCmp $0 "Default Install" 0 show GetDlgItem $DLGITEM $hwnd 1204 EnableWindow $DLGITEM 0 GetDlgItem $DLGITEM $hwnd 1205 EnableWindow $DLGITEM 0 show: InstallOptionsEx::show Pop $R0FunctionEndFunction installer.directory.leave ; At this point the user has either pressed Next or one of our custom buttons ; We find out which by reading from the INI file !insertmacro MUI_INSTALLOPTIONS_READ $0 "installer.directory.ini" "Settings" "State" StrCmp $0 0 page StrCmp $0 3 droplist Abort ; Return to the pagedroplist: ; Make the DirRequest field depend on the droplist !insertmacro MUI_INSTALLOPTIONS_READ $0 "installer.directory.ini" "Field 3" "State" StrCmp $0 "Custom Location" +3 StrCpy $0 0 Goto +2 StrCpy $0 1 GetDlgItem $1 $hwnd 1204 ; DirRequest control EnableWindow $1 $0 GetDlgItem $1 $hwnd 1205 ; button (the following control) EnableWindow $1 $0 Abort ; Return to the pagepage: !insertmacro MUI_INSTALLOPTIONS_READ $0 "installer.directory.ini" "Settings" "Notify" StrCmp $0 "ONNEXT" save Abortsave: ; At this point we know the Next button was pressed, so perform any validation and reading !insertmacro MUI_INSTALLOPTIONS_READ $INSTDIR "installer.directory.ini" "Field 5" "State"FunctionEndFunction disableBackButton FindWindow $0 "#32770" "" $HWNDPARENT GetDlgItem $1 $HWNDPARENT 3 ; back button ShowWindow $1 ${SW_HIDE}FunctionEnd; This function ensures that you have administrator privileges; it is copied from:;http://nsis.sourceforge.net/archive/viewpage.php?pageid=275Function IsUserAdmin Push $R0 Push $R1 Push $R2 ClearErrors UserInfo::GetName IfErrors Win9x Pop $R1 UserInfo::GetAccountType Pop $R2 StrCmp $R2 "Admin" 0 Continue StrCpy $R0 "true" Goto Done Continue: StrCmp $R2 "" Win9x StrCpy $R0 "false" Goto Done Win9x: StrCpy $R0 "true" Done: Pop $R2 Pop $R1 Exch $R0FunctionEnd!macro GetUninstallString UNFunction ${UN}GetUninstallString ReadRegStr $R0 HKLM \ "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APPNAME}" \ "UninstallString" Push $R0FunctionEnd!macroend!macro GetOldPath UNFunction ${UN}GetOldPath Call ${UN}GetUninstallString Pop $0 StrCpy $1 $0 1 0 ; get firstchar StrCmp $1 '"' "" getparent ; if first char is ", let's remove "s first. StrCpy $0 $0 "" 1 StrCpy $1 0 rqloop: StrCpy $2 $0 1 $1 StrCmp $2 '"' rqdone StrCmp $2 "" rqdone IntOp $1 $1 + 1 Goto rqloop rqdone: StrCpy $0 $0 $1 getparent: ; the uninstall string goes to an EXE, lets get the directory. StrCpy $1 -1 gploop: StrCpy $2 $0 1 $1 StrCmp $2 "" gpexit StrCmp $2 "\" gpexit #"emacs IntOp $1 $1 - 1 Goto gploop gpexit: StrCpy $0 $0 $1 Push $0FunctionEnd!macroend!macro EnhancedFindWindow UNFunction ${UN}EnhancedFindWindow ; input, save variables Exch $0 # part of the wt to search for Exch Exch $1 # the wcn Push $2 # length of $0 Push $3 # return code Push $4 # window handle Push $5 # returned window name Push $6 # max length of 5 ; set up the variables SetPluginUnload alwaysoff # recommended, if u're using the \ system plugin StrCpy $4 0 # FindWindow wouldn't work without; StrCpy $2 ${NSIS_MAX_STRLEN} # the max length of string variables StrLen $2 $0 StrLen $5 $4 # it's length ; loop to search for open windows search_loop: FindWindow $4 "" "" 0 $4 IntCmp $4 0 search_failed IsWindow $4 0 search_failed System::Call \ 'user32.dll::GetClassName(i, t, *i) i(r4r4, .r5, r6r6) .r3' IntCmp $3 0 search_loop StrCmp $5 $1 0 search_loop System::Call \ 'user32.dll::GetWindowText(i, t, *i) i(r4r4, .r5, r6r6) .r3' IntCmp $3 0 search_loop StrCpy $3 $5 StrCpy $5 $5 $2 0 StrCmp $0 $5 search_end search_loop ; no matching class-name found, return "failed" search_failed: StrCpy $0 "failed" StrCpy $1 "failed" ; search ended, output and restore variables search_end: SetPluginUnload manual # the system-plugin can now unload itself System::Free 0 # free the memory StrCpy $0 $4 StrCpy $1 $5 Pop $6 Pop $5 Pop $4 Pop $3 Pop $2 Exch $1 Exch Exch $0FunctionEnd!macroend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -