脚本:PPTV网络电视V2.4.3.0012

优质
小牛编辑
115浏览
2023-12-01
注:这个脚本不错,比较有借鉴意义。先来看几个图:

引用 PPTV.nsi 的内容:

SetCompressor lzma
SetCompressorDictSize 32

!AddIncludeDir ".\"

;!define Project PPTV
;!include "Assoc.nsh"   ;Ansifa的文件关联头文件
!include "MyUI.nsh"
!define PRODUCT_NAME "PPTV网络电视"
!define PRODUCT_VERSION "V2.4.3.0012"
!define PAGE_BGCOLOR 0xFFFFFF

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
Caption "$(^Name) 安装 - by gfm688"
OutFile "PPTV_Test.exe"
Icon ".\Resource\Icon.ico"
LoadLanguageFile "${NSISDIR}\Contrib\Language files\SimpChinese.nlf"
ReserveFile "${NSISDIR}\Plugins\ButtonEvent.dll"
BrandingText "WWW.PPTV.COM"
CheckBitmap ".\Resource\check.bmp"
ComponentText "${PRODUCT_NAME}将与您的本地媒体文件建立关联,以便您用PPTV客户端打开本地文件" "勾选需要关联的文件格式:"
ShowInstDetails nevershow
InstallDir "$PROGRAMFILES\PPTV"
DirText "“安装向导”将安装 $(^Name) 在下列文件夹。$\n$\n要安装到不同文件夹,单击 [浏览(B)] 并选择其他的文件夹。$\n$\n单击 [下一步(N)] 继续。"
LicenseBkColor ${PAGE_BGCOLOR}

!define WELCOMEPAGE_TEXT_TOP "${PRODUCT_NAME}是PPLive旗下全球最大的网络电视平台。$\n$\n\
本向导将引导你完成${PRODUCT_NAME}客户端的安装。$\n\
安装进程开始前,建议先关闭其他所有应用程序。这将允许“安装向导”更新相应的系统文件,而无需重新启动你的计算机。$\n$\n\
单击 [下一步(N)] 继续。"

!define WELCOMEPAGE_TEXT_BOTTOM "新版本特性:$\n\
1.会员用户免广告、看专享频道,充值即享VIP尊贵体验$\n\
2.关联本地文件,支持播放电脑中的视频文件$\n\
3.广告策略调整,避免重复弹出,音量可以控制$\n\
4.新增PPTV$\"一起看新鲜$\"屏保"

!insertmacro MyWelcomePage

PageEx license
    LicenseData ".\Resource\License.rtf"
    LicenseText "如果你接受协议中的条款,单击 [我接受(I)] 继续安装。如果你选定 [取消(C)] ,安装程序将会关闭。必须接受协议才能安装“$(^Name)”。"
	PageCallbacks "" LicenseShow
PageExEnd

Page directory "" DirShow
Page instfiles "" InstShow
Page components AssocPre AssocShow AssocLeave

!define FINISHPAGE_TEXT_TOP "${PRODUCT_NAME} 已成功安装到你的计算机。"
;....这里定义6个函数,是在完成页面的离开函数判断CheckBox是否选中而执行的
!define FINISH_OPTION1 RunPPTVNow   ;我只写了第1个测试一下,其它5个省略不写了
;!define FINISH_OPTION2 XXXXXX
;.............................
!insertmacro MyFinishPage

Section
;ReserveFile /r /x ".\Resource\check.bmp" ".\Resource\*.bmp"
DetailPrint "正在安装 ${PRODUCT_NAME} ..."
Sleep 10
Sleep 100
Sleep 1000
SectionEnd

InstType "全选"
InstType "全不选"
InstType "恢复默认"

!macro InsertSection SEC
	Section "${SEC}" SEC${SEC}
	    SectionIn 1
	SectionEnd
!macroend

!macro DefaultSection SEC
	Section "${SEC}" SEC${SEC}
	    SectionIn 1 3
	SectionEnd
!macroend

SectionGroup /e "全部媒体文件格式"
	SectionGroup "Windows媒体文件"
	!insertmacro DefaultSection ".asf"
	!insertmacro DefaultSection ".wmv"
	!insertmacro InsertSection ".wma"
	SectionGroupEnd

	SectionGroup "Real媒体文件"
	!insertmacro InsertSection ".rm"
	!insertmacro InsertSection ".rmvb"
	!insertmacro InsertSection ".ra"
	SectionGroupEnd

	SectionGroup "MEEG4媒体文件"
	!insertmacro DefaultSection ".mp4"
	!insertmacro InsertSection ".m4v"
	!insertmacro InsertSection ".mpeg4"
	SectionGroupEnd
SectionGroupEnd


Function LicenseShow
	!insertmacro PAGEINIT_BASIC
    !insertmacro SET_PAGECTL_TEXT 1040 "按 [PgDn] 阅读“授权协议”的其余部分。"
   	!insertmacro SET_PAGECTL_COLOR 1040 ${PAGE_TEXTCOLOR} ${PAGE_BGCOLOR}
   	!insertmacro SET_HEADER_IMAGE "license_header.bmp" ".\Resource\license_header.bmp"
   	!insertmacro SET_PAGECTL_COLOR 1006 0x0d839d ${PAGE_BGCOLOR}
FunctionEnd


Function DirShow
	!insertmacro PAGEINIT_BASIC
	!insertmacro SET_PAGECTL_COLOR 1020 ${PAGE_TEXTCOLOR} ${PAGE_BGCOLOR}
	!insertmacro SET_PAGECTL_COLOR 1023 ${PAGE_TEXTCOLOR} ${PAGE_BGCOLOR}
	!insertmacro SET_PAGECTL_COLOR 1024 ${PAGE_TEXTCOLOR} ${PAGE_BGCOLOR}
	!insertmacro SET_HEADER_IMAGE "directory_header.bmp" ".\Resource\directory_header.bmp"
FunctionEnd

Function InstShow
    !insertmacro PAGEINIT_BASIC
    !insertmacro SET_HEADER_IMAGE "instfiles_header.bmp" ".\Resource\instfiles_header.bmp"
	!insertmacro SET_INSTPAGE_IMAGE ".\Resource\newfeather.bmp"
FunctionEnd

Function AssocPre
    ${EnableSysMenuItem} ${SC_CLOSE} ${MF_DISABLED}
    GetDlgItem $0 $HWNDPARENT 2
    EnableWindow $0 0
    SetCurInstType 2
FunctionEnd

Function AssocShow
    !insertmacro PAGEINIT_BASIC
	!insertmacro SET_PAGECTL_COLOR 1021 ${PAGE_TEXTCOLOR} ${PAGE_BGCOLOR}
	!insertmacro SET_HEADER_IMAGE "FileOption.bmp" ".\Resource\FileOption.bmp"
	!insertmacro SetButton 16002 SelectALL
	!insertmacro SetButton 16003 SelectNone
	!insertmacro SetButton 16004 SetDefault
	!insertmacro SET_PAGECTL_FONT 1006 "Tahoma" "9" "520"   ;设置控件字体
	!insertmacro SET_PAGECTL_FONT 1021 "Tahoma" "9" "520"
	!insertmacro SET_PAGECTL_FONT 1032 "Tahoma" "9" "520"
FunctionEnd

;!define CBN_SELCHANGE       1
!macro CB_SETCURSEL item_index  ;item_index: Specifies the zero-based index of the string to select.
	Push $R0
	Push $R1
	FindWindow $R0 "#32770" "" $HWNDPARENT
    GetDlgItem $R1 $R0 1017
    SendMessage $R1 ${CB_SETCURSEL} ${item_index} 0
    SendMessage $HWNDPARENT ${WM_COMMAND} 66553 $R1
	;66553 即低位是1017, 高位是CBN_SELCHANGE
	Pop $R1
	Pop $R0
!macroend

Function SelectALL
    !insertmacro CB_SETCURSEL 0
FunctionEnd

Function SelectNone
    !insertmacro CB_SETCURSEL 1
FunctionEnd

Function SetDefault
    !insertmacro CB_SETCURSEL 2
FunctionEnd

!macro ExecSection_Assoc SEC_IDX EXT DESC ICO CONTENTTYPE CLSID
	Push $R0
	SectionGetFlags ${SEC_IDX} $R0
	IntOp $R0 $R0 & 1   ;第一位不变,其它位 置0
	StrCmp $R0 0 +2
	;!insertmacro Assoc_Media ${ext} ${ext} ${desc} "$INSTDIR\pptv.exe" ${ico} ${ContentType} ${CLSID}
	MessageBox MB_ICONINFORMATION|MB_OK "${ext}" ;MessageBox测试用,实际不要的
	Pop $R0
!macroend

Function AssocLeave
	!insertmacro ExecSection_Assoc ${SEC.asf} "asf" "ASF 媒体文件" "懒得写了" "video/x-ms-asf" "{cd3afa8f-b84f-48f0-9393-7edc34128127}"
	!insertmacro ExecSection_Assoc ${SEC.wmv} "wmv" "懒得写了" "懒得写了" "懒得写了" "懒得写了"
	;....这里放更多的ExecSection_Assoc
	
	;System::Call 'Shell32::SHChangeNotify(i ${SHCNE_ASSOCCHANGED}, i ${SHCNF_IDLIST}, i 0, i 0)'
	!insertmacro UnsetButton 16002
	!insertmacro UnsetButton 16003
	!insertmacro UnsetButton 16004
FunctionEnd

Function RunPPTVNow
	${MessageBox2} "立即运行 PPTV网络电视......" "测试用的MsgBox" MB_ICONINFORMATION|MB_OK
	;这里放运行PPTV网络电视的代码
FunctionEnd

Function .onGUIInit
	;InitPluginsDir
	SetCtlColors $HWNDPARENT "" 0xF3F8FC
	GetDlgItem $0 $HWNDPARENT 1044
	SetCtlColors $0 "" ${PAGE_BGCOLOR}
	!insertmacro SHOW_PARENT_CTL 16002 0
	!insertmacro SHOW_PARENT_CTL 16003 0
	!insertmacro SHOW_PARENT_CTL 16004 0
	GetDlgItem $0 $HWNDPARENT 1028
	SetCtlColors $0 "" transparent
	BrandingURL::Set /NOUNLOAD "0" "114" "255" "http://www.pptv.com/"
	;ButtonLinker::CreateLinker /NOUNLOAD $0 "http://www.pptv.com/" ;晕,Linker创建的链接改不了颜色
FunctionEnd

Function .onGUIEnd
	ButtonEvent::Unload
	BrandingURL::Unload
FunctionEnd

Function .onUserAbort
    MessageBox MB_YESNO|MB_ICONEXCLAMATION "你确实要退出 “$(^Name)” 安装程序?" IDYES +2
  	Abort
FunctionEnd

另存附件