_ㄨ.Ian 发表于 2012-8-23 14:06
天意老师 能不能给我 天意U盘维护系统 3.0网络增强版 的源代码啊 - ##这是一个可以安装fba包的u盘启动安装器源码,
- ##资源包src里面的ty.fba是一个空文件,请用自己的fba包替换。
- ##=====================================
- ##本源码由teasiu@163.com创建。请保留此信息。
- ##=====================================
- !define NAME "天意U盘维护系统"
- !define DISTRO "天意U盘维护系统"
- !define FILENAME "天意U盘维护系统"
- !define VERSION "网络增强V2012版"
- !define MUI_ICON "AUTORUN.ICO"
- RequestExecutionLevel highest
- SetCompressor LZMA
- CRCCheck On
- XPStyle on
- ShowInstDetails show
- BrandingText "天意U盘维护系统安装器"
- CompletedText "安装结束,欢迎使用和收藏本工具! "
- 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-logo.bmp"
- !define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
- !define MUI_HEADERIMAGE_RIGHT
- ; Drive page
- Var Dialog
- Var DestDriveTxt
- Var DestDrive
- Var DestDisk
- Var LabelDrivePageText
- Var LabelDriveSelect
- Var AllDriveOption
- Var DisplayAll
- Var Format
- Var FormatMe
- Var Hddmode
- Var Zipmode
- Var HddmodeMe
- Var ZipmodeMe
- Var Warning
- Var Soft
- Var Link
- Var Links
- Var Image
- Var hImage
- Var size
- #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} "【天意作品】天意U盘维护系统安装器"
- LangString DrivePage_Title2 ${LANG_SIMPCHINESE} "先插入您的U盘或移动硬盘,然后再打开本软件进行安装。"
- LangString DrivePage_Text ${LANG_SIMPCHINESE} "本工具将使您的USB设备完美启动。"
- LangString DrivePage_Input ${LANG_SIMPCHINESE} "第一步:点击下拉菜单选择磁盘"
- LangString Soft_Text ${LANG_SIMPCHINESE} "第二步:选择USB设备启动引导模式。必选。"
- 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
- Pop $Dialog
- ${If} $DestDrive == ""
- GetDlgItem $6 $HWNDPARENT 1 ; Get next control handle
- EnableWindow $6 0 ; disable next
- ${EndIf}
- ;创建bmp位图
- ${NSD_CreateBitmap} 78% 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% 25 $(DrivePage_Input)
- Pop $LabelDriveSelect
- SetCtlColors $LabelDriveSelect /Branding 0000BD
- ${NSD_CreateCheckBox} 33% 43 45% 14 "显示全部驱动盘 (慎用)"
- Pop $AllDriveOption
- ${NSD_OnClick} $AllDriveOption ListAllDrives
- ${NSD_CreateDroplist} 0 40 30% 25 ""
- Pop $DestDriveTxt
- Call ListAllDrives
- ${NSD_OnChange} $DestDriveTxt db_select.onchange
- ${If} $DestDrive != ""
- ${NSD_CB_SelectString} $DestDriveTxt $DestDrive
- ${EndIf}
- ; Add Help Link
- ${NSD_CreateLink} 84% 192 15% 14 "软件更新" ; 创建一个链接地址 84%代表位置横坐标,190代表位置纵坐标,15%代表内容横坐标,14代表内容纵坐标
- Pop $Link
- ${NSD_OnClick} $Link onClickMyLink
- ; Format Drive Option
- ${NSD_CreateButton} 33% 64 32% 22 "(可选)格式化回收空间"
- Pop $Format
- ${NSD_OnClick} $Format FormatIt
- ; Soft Label
- ${NSD_CreateLabel} 0 100 70% 15 $(Soft_Text) ;软件内容 0代表位置横坐标,70代表位置纵坐标,70%代表内容横坐标,15代表内容纵坐标
- Pop $Soft
- SetCtlColors $Soft /Branding 0000BD
- ; 磁盘启动模式选项
- ${NSD_CreateCheckBox} 0 120 36% 15 "HDD启动模式."
- Pop $Hddmode
- ${NSD_Check} $Hddmode
- ${NSD_OnClick} $Hddmode HddmodeIt
- ${NSD_CreateCheckBox} 38% 120 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 ListAllDrives ; Set to Display All Drives
- SendMessage $DestDriveTxt ${CB_RESETCONTENT} 0 0
- ${NSD_GetState} $AllDriveOption $DisplayAll
- ${If} $DisplayAll == ${BST_CHECKED}
- ${NSD_Check} $AllDriveOption
- ${NSD_SetText} $AllDriveOption "现在显示所有驱动盘 (小心)"
- ${GetDrives} "ALL" DrivesList ; All Drives Listed
- ${ElseIf} $DisplayAll == ${BST_UNCHECKED}
- ${NSD_Uncheck} $AllDriveOption
- ${NSD_SetText} $AllDriveOption "显示所有驱动盘 (慎用)"
- ${GetDrives} "FDD" DrivesList ; FDD+HDD reduce to FDD for removable media only
- ${EndIf}
- FunctionEnd
- Function onClickMyLink
- Pop $Links ; pop something to prevent corruption
- ExecShell "open" "http://www.winpe.cc"
- 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 DrivesList ; 磁盘列表,表示形式为盘符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包,在这个例子里名字为ty.fba,下面要相对应名字
- ${GetSize} "$PLUGINSDIR" "/M=ty.fba /S=0M /G=0" $0 $1 $2
- StrCpy $size "$0"
- DetailPrint "fba包大小为$sizeMB"
- ${If} $HddmodeMe == "Yes"
- DetailPrint "创建HDD模式的引导和复制天意U盘维护系统到 $DestDisk, 请稍候"
- ;下面这段请根据您的fba包大小来填写UD扩展分区的大小extended ?m,UD主分区默认大小是8m,否则会出现安装错误。
- ;fba包目前使用fbinstool工具比较方便,假如你很掌握fbinst命令,也完全可以使用命令在这里创建fba包然后安装它,写起来比较复杂。
- nsExec::ExecToLog '"cmd" /c "echo y|$PLUGINSDIR\fbinst $DestDisk format --extended $sizeM --force --align --primary 8m --archive $PLUGINSDIR\ty.fba"'
- DetailPrint "天意U盘维护系统已经安装到$DestDisk的隐藏区占 $size MB + 8 MB"
- ${ElseIf} $ZipmodeMe == "Yes"
- DetailPrint "创建Zip模式的引导和复制天意U盘维护系统到 $DestDisk, 请稍候"
- nsExec::ExecToLog '"cmd" /c "echo y|$PLUGINSDIR\fbinst $DestDisk format --extended $sizeM --force --zip --align --primary 8m --archive $PLUGINSDIR\ty.fba"'
- DetailPrint "天意U盘维护系统zip模式已经安装到$DestDisk的隐藏区占 $size MB + 8 MB"
- ${EndIf}
- FunctionEnd
- Section "Install" main
- Call InstallEYes ;指令安装进程程式
- nsExec::ExecToLog '"cmd" /c "echo y|$PLUGINSDIR\fbinst $DestDisk pack"' ;安装完成后整理碎片
- SectionEnd
复制代码 |