|
推荐
楼主 |
发表于 2011-4-10 01:56:50
|
只看该作者
这是一个关于安装内置fba包的安装器脚本。
- ##开源的故事一直鼓励着我不断的学习这些知识,
- ##这是一个可以安装fba包的u盘启动安装器源码,
- ##大家看到很多的类似软件比如"大白菜""一键U盘工作室"等等,就是用这个原理做出来的。
- ##fbinstool的其中一部分原理,也是类似的
- ##触类旁通,如果你熟练了,就大胆的修改这些代码,设计成你想要的样子吧
- ##资源包src里面的slitaz4.fba是一个空文件,请用自己的fba包替换。
- ##=====================================
- ##本源码由teasiu@163.com创建。请保留此信息。
- ##=====================================
- !define NAME "SlitazUSB"
- !define DISTRO "SlitazUSB"
- !define FILENAME "SlitazUSB"
- !define VERSION "0.3"
- !define MUI_ICON "usb48.ico"
- RequestExecutionLevel highest
- SetCompressor LZMA
- CRCCheck On
- XPStyle on
- ShowInstDetails show
- BrandingText "USB启动通用安装器 神雕teasiu作品"
- CompletedText "安装结束,欢迎使用和收藏本工具! --神雕teasiu"
- InstallButtonText "创 建"
- Name "${NAME} ${VERSION}"
- OutFile "${FILENAME} ${VERSION}.exe"
- !include "nsDialogs.nsh"
- !include "MUI2.nsh"
- !include "FileFunc.nsh"
- !include "WordFunc.nsh" ;DriveList
- ; Interface settings
- !define MUI_HEADERIMAGE
- !define MUI_HEADERIMAGE_BITMAP "usb-logo2.bmp"
- !define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
- !define MUI_HEADERIMAGE_RIGHT
- ; Drive page
- Var DestDriveTxt
- Var DestDrive
- Var DestDisk
- Var LabelDrivePageText
- Var LabelDriveSelect
- Var Format
- Var FormatMe
- Var Hddmode
- Var Zipmode
- Var HddmodeMe
- Var ZipmodeMe
- Var Warning
- Var Soft
- Var Link
- Var Links
- Var Image
- Var hImage
- #Page custom SetCustom LeaveCustom
- Page custom drivePage
- !define MUI_INSTFILESPAGE_COLORS "00FF00 000000"
- ; Instfiles page
- !define MUI_TEXT_INSTALLING_TITLE $(Install_Title)
- !define MUI_TEXT_INSTALLING_SUBTITLE $(Install_SubTitle)
- !define MUI_TEXT_FINISH_SUBTITLE $(Install_Finish_Sucess)
- !insertmacro MUI_PAGE_INSTFILES
- ; Language files
- !insertmacro MUI_LANGUAGE "SimpChinese"
- LangString DrivePage_Title ${LANG_SIMPCHINESE} "【SlitazUSB】USB移动系统安装器"
- LangString DrivePage_Title2 ${LANG_SIMPCHINESE} "先插入一个USB盘,然后再打开本软件进行安装."
- LangString DrivePage_Text ${LANG_SIMPCHINESE} "本工具将使您的U盘完美启动."
- LangString DrivePage_Input ${LANG_SIMPCHINESE} "第一步:点击下拉菜单选择您的U盘"
- LangString Soft_Text ${LANG_SIMPCHINESE} "第二步:选择USB设备启动引导模式。必选。"
- LangString Iso_Text ${LANG_SIMPCHINESE} "第三步:选择您的ISO镜像文件。"
- LangString WarningPage_Text ${LANG_SIMPCHINESE} "注意:请确保U盘资料已备份。原资料将被完全覆写并不可恢复!"
- LangString Install_Title ${LANG_SIMPCHINESE} "安装中 ${DISTRO}"
- LangString Install_SubTitle ${LANG_SIMPCHINESE} "请稍后 ${NAME} 安装 ${DISTRO} 到 $DestDisk"
- LangString Install_Finish_Sucess ${LANG_SIMPCHINESE} "$\t ${NAME} 已经完成安装${DISTRO}到$DestDisk"
- Function .onInit
- InitPluginsDir
- File /oname=$PLUGINSDIR\ad.bmp "ad.bmp" ; 嵌入bmp位图以便后面调用
- FunctionEnd
- Function drivePage
- !insertmacro MUI_HEADER_TEXT $(DrivePage_Title) $(DrivePage_Title2)
- nsDialogs::Create 1018
- ${If} $DestDrive == ""
- GetDlgItem $6 $HWNDPARENT 1 ; Get next control handle
- EnableWindow $6 0 ; disable next
- ${EndIf}
- ;创建bmp位图
- ${NSD_CreateBitmap} 75% 0 20% 100% ""
- Pop $Image
- ${NSD_SetImage} $Image $PLUGINSDIR\ad.bmp $hImage
- ${NSD_CreateLabel} 0 0 70% 30 $(DrivePage_Text)
- Pop $LabelDrivePageText
- ${NSD_CreateLabel} 0 20 70% 15 $(DrivePage_Input)
- Pop $LabelDriveSelect
- SetCtlColors $LabelDriveSelect /Branding 0000BD
-
- ${NSD_CreateDroplist} 0 40 30% 25 ""
- Pop $DestDriveTxt
- ${NSD_OnChange} $DestDriveTxt db_select.onchange
- ${GetDrives} "FDD" driveList ; FDD代表移动磁盘,本地磁盘用HDD,所有磁盘用ALL
- ${If} $DestDrive != ""
- ${NSD_CB_SelectString} $DestDriveTxt $DestDrive
- ${EndIf}
- ; Add Help Link
- ${NSD_CreateLink} 85% 190 15% 14 "软件更新" ; 创建一个链接地址 85%代表位置横坐标,190代表位置纵坐标,15%代表内容横坐标,14代表内容纵坐标
- Pop $Link
- ${NSD_OnClick} $Link onClickMyLink
- ; Format Drive Option
- ${NSD_CreateButton} 32% 38 38% 22 "(可选)FAT32格式化此U盘"
- Pop $Format
- ${NSD_OnClick} $Format FormatIt
- ; Soft Label
- ${NSD_CreateLabel} 0 70 70% 15 $(Soft_Text) ;软件内容 0代表位置横坐标,70代表位置纵坐标,70%代表内容横坐标,15代表内容纵坐标
- Pop $Soft
- SetCtlColors $Soft /Branding 0000BD
-
- ; 磁盘启动模式选项
- ${NSD_CreateCheckBox} 0 90 36% 15 "HDD启动模式."
- Pop $Hddmode
- ${NSD_Check} $Hddmode
- ${NSD_OnClick} $Hddmode HddmodeIt
- ${NSD_CreateCheckBox} 38% 90 36% 15 "ZIP启动模式."
- Pop $Zipmode
- ${NSD_OnClick} $Zipmode ZipmodeIt
- ; Warning Label
- ${NSD_CreateLabel} 0 190 80% 14 $(WarningPage_Text)
- Pop $Warning
- EnableWindow $Format 0
- EnableWindow $Hddmode 0
- EnableWindow $Zipmode 0
- ShowWindow $Warning 0
- GetDlgItem $6 $HWNDPARENT 3
- ShowWindow $6 0 ; Disable Back
- nsDialogs::Show
- ${NSD_FreeImage} $hImage
- FunctionEnd
- Function onClickMyLink
- Pop $Links ; pop something to prevent corruption
- ExecShell "open" "http://www.ecoo168.com"
- FunctionEnd
- Function db_select.onchange
- Pop $DestDriveTxt
- ${NSD_GetText} $DestDriveTxt $0
- StrCpy $DestDrive "$0"
- StrCpy $DestDisk "$DestDrive" -1
- GetDlgItem $6 $HWNDPARENT 1 ; Get "Next" control handle
- EnableWindow $6 1 ; enable "Next" control
- EnableWindow $Format 1
- EnableWindow $Hddmode 1
- EnableWindow $Zipmode 1
- ShowWindow $Warning 1
- SetCtlColors $Warning /Branding FF0000
- Call HddmodeIt
- Call ZipmodeIt
- FunctionEnd
- Function driveList ; 磁盘列表,表示形式为盘符CDE等
- SendMessage $DestDriveTxt ${CB_ADDSTRING} 0 "STR:$9"
- Push 1
- FunctionEnd
- ;下面2个方程的意思是:无论用户怎么点击,都必须要选中一个
- Function HddmodeIt
- ${NSD_GetState} $Hddmode $HddmodeMe
-
- ${If} $HddmodeMe == ${BST_CHECKED}
- ${NSD_Check} $Hddmode
- StrCpy $HddmodeMe "Yes"
- ${NSD_SetText} $Hddmode "(已选)HDD启动模式"
- ${NSD_Uncheck} $Zipmode
- StrCpy $ZipmodeMe "No"
- ${NSD_SetText} $Zipmode "ZIP启动模式"
-
- ${ElseIf} $HddmodeMe == ${BST_UNCHECKED}
- ${NSD_Uncheck} $Hddmode
- StrCpy $HddmodeMe "No"
- ${NSD_SetText} $Hddmode "HDD启动模式"
- ${NSD_Check} $Zipmode
- StrCpy $ZipmodeMe "Yes"
- ${NSD_SetText} $Zipmode "(已选)ZIP启动模式"
- ${EndIf}
- FunctionEnd
- Function ZipmodeIt ; Set Format Option
- ${NSD_GetState} $Zipmode $ZipmodeMe
- ${If} $ZipmodeMe == ${BST_CHECKED}
- ${NSD_Check} $Zipmode
- StrCpy $ZipmodeMe "Yes"
- ${NSD_SetText} $Zipmode "(已选)ZIP启动模式"
- ${NSD_Uncheck} $Hddmode
- StrCpy $HddmodeMe "No"
- ${NSD_SetText} $Hddmode "HDD启动模式"
- ${ElseIf} $ZipmodeMe == ${BST_UNCHECKED}
- ${NSD_Uncheck} $Zipmode
- StrCpy $ZipmodeMe "No"
- ${NSD_SetText} $Zipmode "ZIP启动模式"
- ${NSD_Check} $Hddmode
- StrCpy $HddmodeMe "Yes"
- ${NSD_SetText} $Hddmode "(已选)HDD启动模式"
- ${EndIf}
- FunctionEnd
- Function FormatIt ; Set Format Option这里增加询问框,更加人性化
- Pop $FormatMe
- MessageBox MB_YESNO "格式化U盘可以取回全部空间,继续吗?" IDYES true IDNO false
- true:
- Goto next
- false:
- MessageBox MB_OK|MB_ICONSTOP "不格式化,退出"
- Abort
- next:
- MessageBox MB_YESNO "真的格式化吗?(请确保您的U盘资料已经备份,格式化将擦除U盘资料且不可恢复)" /SD IDYES IDNO false2
- Goto next2
- false2:
- MessageBox MB_OK|MB_ICONSTOP "不格式化,退出"
- Abort
- next2:
- InitPluginsDir
- File /oname=$PLUGINSDIR\fbinst.exe "src\fbinst.exe" ;调用一下src文件夹里面的fbinst.exe用于格式化
- nsExec::ExecToLog '"cmd" /c "echo y|$PLUGINSDIR\fbinst $DestDisk format --raw --force --fat32"'
- MessageBox MB_OK "格式化完成,恢复U盘全部空间。"
- FunctionEnd
- Function InstallEYes
- InitPluginsDir
- SetOutPath "$PLUGINSDIR"
- File /r "src\*.*" ;文件夹src里面必须包含2个文件,fbinst.exe和你的fba包,在这个例子里名字为slitaz4.fba,下面要相对应名字
- ${If} $HddmodeMe == "Yes"
- DetailPrint "创建HDD模式的引导和复制slitaz系统到 $DestDisk, 请稍后"
- ;下面这段请根据您的fba包大小来填写UD扩展分区的大小extended ?m,UD主分区默认大小是8m,否则会出现安装错误。
- ;fba包目前使用fbinstool工具比较方便,假如你很掌握fbinst命令,也完全可以使用命令在这里创建fba包然后安装它,写起来比较复杂。
- nsExec::ExecToLog '"cmd" /c "echo y|$PLUGINSDIR\fbinst $DestDisk format --extended 80m --force --align --primary 8m --archive $PLUGINSDIR\slitaz4.fba"'
- DetailPrint "Slitaz系统已经安装到$DestDisk的隐藏区占88M"
- ${ElseIf} $ZipmodeMe == "Yes"
- DetailPrint "创建Zip模式的引导和复制slitaz系统到 $DestDisk, 请稍后"
- nsExec::ExecToLog '"cmd" /c "echo y|$PLUGINSDIR\fbinst $DestDisk format --extended 80m --force --zip --align --primary 8m --archive $PLUGINSDIR\slitaz4.fba"'
- DetailPrint "Slitaz系统zip模式已经安装到$DestDisk的隐藏区占88M"
- ${EndIf}
- FunctionEnd
- Section "Install" main
- Call InstallEYes ;指令安装进程程式
- nsExec::ExecToLog '"cmd" /c "echo y|$PLUGINSDIR\fbinst $DestDisk pack"' ;安装完成后整理碎片
- SectionEnd
复制代码
[ 本帖最后由 2010teasiu 于 2011-4-13 04:24 编辑 ] |
评分
-
查看全部评分
|