杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2743|回复: 0

NSIS 仿QQ安装包

[复制链接]
发表于 2018-8-12 19:55:03 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x

  1. # ====================== 自定义宏 ==============================
  2. !define PRODUCT_NAME           "腾讯QQ"
  3. !define EXE_NAME               "QQ.exe"
  4. !define PRODUCT_VERSION        "1.0.0.1"
  5. !define PRODUCT_PUBLISHER      "Tencent"
  6. !define PRODUCT_LEGAL          "Copyright (C) 1999-2014 Tencent, All Rights Reserved"


  7. # ===================== 外部插件以及宏 =============================
  8. !include "LogicLib.nsh"
  9. !include "nsDialogs.nsh"
  10. !include "..\..\include\common.nsh"

  11. # ===================== 安装包版本 =============================
  12. VIProductVersion                    "${PRODUCT_VERSION}"
  13. VIAddVersionKey "ProductVersion"    "${PRODUCT_VERSION}"
  14. VIAddVersionKey "ProductName"       "${PRODUCT_NAME}"
  15. VIAddVersionKey "CompanyName"       "${PRODUCT_PUBLISHER}"
  16. VIAddVersionKey "FileVersion"       "${PRODUCT_VERSION}"
  17. VIAddVersionKey "InternalName"      "${EXE_NAME}"
  18. VIAddVersionKey "FileDescription"   "${PRODUCT_NAME}"
  19. VIAddVersionKey "LegalCopyright"    "${PRODUCT_LEGAL}"

  20. # ==================== NSIS属性 ================================

  21. #SetCompressor zlib

  22. ; 安装包名字.
  23. Name "${PRODUCT_NAME}"

  24. # 安装程序文件名.
  25. OutFile "QQ Setup.exe"

  26. # 默认安装位置.
  27. InstallDir "$PROGRAMFILES\Tencent\${PRODUCT_NAME}"


  28. # 针对Vista和win7 的UAC进行权限请求.
  29. # RequestExecutionLevel none|user|highest|admin
  30. RequestExecutionLevel admin

  31. # 安装和卸载程序图标
  32. Icon              "image\logo.ico"
  33. UninstallIcon     "image\logo.ico"



  34. # 自定义页面
  35. Page custom DUIPage


  36. # 卸载程序显示进度
  37. UninstPage instfiles

  38. # ======================= DUILIB 自定义页面 =========================
  39. Var hInstallDlg

  40. Function DUIPage
  41.     !insertmacro Trace "$TEMP $PLUGINSDIR"
  42.     nsDui::InitDUISetup
  43.     Pop $hInstallDlg
  44.    
  45.     # License页面
  46.     nsDui::FindControl "btnLicenseClose"
  47.     Pop $0
  48.     ${If} $0 == 0
  49.         GetFunctionAddress $0 OnExitDUISetup
  50.         nsDui::OnControlBindNSISScript "btnLicenseClose" $0
  51.     ${EndIf}
  52.    
  53.     nsDui::FindControl "btnLicenseMin"
  54.     Pop $0
  55.     ${If} $0 == 0
  56.         GetFunctionAddress $0 OnBtnMin
  57.         nsDui::OnControlBindNSISScript "btnLicenseMin" $0
  58.     ${EndIf}
  59.    
  60.     nsDui::FindControl "btnLicenseNext"
  61.     Pop $0
  62.     ${If} $0 == 0
  63.         GetFunctionAddress $0 OnBtnLicenseNextClick
  64.         nsDui::OnControlBindNSISScript "btnLicenseNext" $0
  65.     ${EndIf}
  66.    
  67.     # 目录选择 页面
  68.     nsDui::FindControl "btnDirClose"
  69.     Pop $0
  70.     ${If} $0 == 0
  71.         GetFunctionAddress $0 OnExitDUISetup
  72.         nsDui::OnControlBindNSISScript "btnDirClose" $0
  73.     ${EndIf}
  74.    
  75.     nsDui::FindControl "btnDirMin"
  76.     Pop $0
  77.     ${If} $0 == 0
  78.         GetFunctionAddress $0 OnBtnMin
  79.         nsDui::OnControlBindNSISScript "btnDirMin" $0
  80.     ${EndIf}
  81.    
  82.     nsDui::FindControl "btnSelectDir"
  83.     Pop $0
  84.     ${If} $0 == 0
  85.         GetFunctionAddress $0 OnBtnSelectDir
  86.         nsDui::OnControlBindNSISScript "btnSelectDir" $0
  87.     ${EndIf}
  88.    
  89.     nsDui::FindControl "btnDirPre"
  90.     Pop $0
  91.     ${If} $0 == 0
  92.         GetFunctionAddress $0 OnBtnDirPre
  93.         nsDui::OnControlBindNSISScript "btnDirPre" $0
  94.     ${EndIf}
  95.    
  96.     nsDui::FindControl "btnDirCancel"
  97.     Pop $0
  98.     ${If} $0 == 0
  99.         GetFunctionAddress $0 OnBtnCancel
  100.         nsDui::OnControlBindNSISScript "btnDirCancel" $0
  101.     ${EndIf}
  102.         
  103.     nsDui::FindControl "btnDirInstall"
  104.     Pop $0
  105.     ${If} $0 == 0
  106.         GetFunctionAddress $0 OnBtnInstall
  107.         nsDui::OnControlBindNSISScript "btnDirInstall" $0
  108.     ${EndIf}
  109.    

  110.    
  111.     # 安装进度 页面
  112.     nsDui::FindControl "btnDetailClose"
  113.     Pop $0
  114.     ${If} $0 == 0
  115.         GetFunctionAddress $0 OnExitDUISetup
  116.         nsDui::OnControlBindNSISScript "btnDetailClose" $0
  117.     ${EndIf}
  118.    
  119.     nsDui::FindControl "btnDetailMin"
  120.     Pop $0
  121.     ${If} $0 == 0
  122.         GetFunctionAddress $0 OnBtnMin
  123.         nsDui::OnControlBindNSISScript "btnDetailMin" $0
  124.     ${EndIf}

  125.     # 安装完成 页面
  126.     nsDui::FindControl "btnFinished"
  127.     Pop $0
  128.     ${If} $0 == 0
  129.         GetFunctionAddress $0 OnFinished
  130.         nsDui::OnControlBindNSISScript "btnFinished" $0
  131.     ${EndIf}
  132.    
  133.     nsDui::FindControl "btnFinishedMin"
  134.     Pop $0
  135.     ${If} $0 == 0
  136.         GetFunctionAddress $0 OnBtnMin
  137.         nsDui::OnControlBindNSISScript "btnFinishedMin" $0
  138.     ${EndIf}
  139.    
  140.     nsDui::FindControl "btnFinishedClose"
  141.     Pop $0
  142.     ${If} $0 == 0
  143.         GetFunctionAddress $0 OnExitDUISetup
  144.         nsDui::OnControlBindNSISScript "btnFinishedClose" $0
  145.     ${EndIf}
  146.    
  147.     nsDui::ShowPage
  148. FunctionEnd

  149. Function OnBtnLicenseNextClick
  150.     nsDui::GetCheckboxStatus "chkAgree"
  151.     Pop $0
  152.     ${If} $0 == "1"
  153.         nsDui::SetDirValue "$INSTDIR"
  154.         nsDui::NextPage "wizardTab"
  155.     ${EndIf}
  156. FunctionEnd

  157. # 开始安装
  158. Function OnBtnInstall
  159.     nsDui::GetDirValue
  160.     Pop $0
  161.     StrCmp $0 "" InstallAbort 0
  162.     StrCpy $INSTDIR "$0"
  163.     nsDui::NextPage "wizardTab"
  164.     nsDui::SetSliderRange "slrProgress" 0 100
  165.    
  166.     # 覆盖安装时,指定不覆盖的文件
  167.     # 将这些文件暂存到临时目录
  168.     CreateDirectory "$TEMP\qq_file_translate"
  169.     CopyFiles /SILENT "$INSTDIR\gf-config.xml" "$TEMP\qq_file_translate"
  170.    
  171.     #启动一个低优先级的后台线程
  172.     GetFunctionAddress $0 ExtractFunc
  173.     BgWorker::CallAndWait
  174.    
  175.     # 文件释放完成以后,还原暂存的文件
  176.     CopyFiles /SILENT "$TEMP\qq_file_translate\gf-config.xml" "$INSTDIR"
  177.     RMDir /r "$TEMP\qq_file_translate"
  178.    
  179.     Call CreateShortcut
  180.     Call CreateUninstall
  181. InstallAbort:
  182. FunctionEnd

  183. Function ExtractFunc
  184.     SetOutPath $INSTDIR
  185.     File "app\app.7z"
  186.     GetFunctionAddress $R9 ExtractCallback
  187.     Nsis7z::ExtractWithCallback "$INSTDIR\app.7z" $R9
  188.     #Delete "$INSTDIR\app.7z"
  189. FunctionEnd


  190. Function ExtractCallback
  191.     Pop $1
  192.     Pop $2
  193.     System::Int64Op $1 * 100
  194.     Pop $3
  195.     System::Int64Op $3 / $2
  196.     Pop $0
  197.    
  198.     nsDui::SetSliderValue "slrProgress" $0

  199.     ${If} $1 == $2
  200.         nsDui::SetSliderValue "slrProgress" 100
  201.         nsDui::NextPage "wizardTab"
  202.     ${EndIf}
  203. FunctionEnd


  204. Function OnExitDUISetup
  205.     nsDui::ExitDUISetup
  206. FunctionEnd

  207. Function OnBtnMin
  208.     SendMessage $hInstallDlg ${WM_SYSCOMMAND} 0xF020 0
  209. FunctionEnd

  210. Function OnBtnCancel
  211. FunctionEnd

  212. Function OnFinished
  213.     # 开机启动
  214.     nsDui::GetCheckboxStatus "chkBootStart"
  215.     Pop $R0
  216.     ${If} $R0 == "1"
  217.         SetShellVarContext all
  218.         CreateShortCut "$SMSTARTUP\QQ.lnk" "$INSTDIR\Bin\QQ.exe"
  219.     ${EndIf}
  220.    
  221.     # 立即启动
  222.     nsDui::GetCheckboxStatus "chkStartNow"
  223.     Pop $R0
  224.     ${If} $R0 == "1"
  225.         Exec "$INSTDIR\Bin\QQ.exe"
  226.     ${EndIf}
  227.    
  228.     # 设置主页
  229.     nsDui::GetCheckboxStatus "chkSetHomePage"
  230.     Pop $R0
  231.     ${If} $R0 == "1"
  232.         WriteRegStr HKCU "Software\Microsoft\Internet Explorer\Main" "Start Page" "http://www.qq.com"
  233.     ${EndIf}
  234.    
  235.     # 显示新特征
  236.     nsDui::GetCheckboxStatus "chkShowFeature"
  237.     Pop $R0
  238.     ${If} $R0 == "1"
  239.         ExecShell "open" "$INSTDIR\QQWhatsnew.txt"
  240.     ${EndIf}
  241.    
  242.     Call OnExitDUISetup
  243. FunctionEnd

  244. Function OnBtnSelectDir
  245.     nsDui::SelectInstallDir
  246.     Pop $0
  247. FunctionEnd

  248. Function OnBtnDirPre
  249.     nsDui::PrePage "wizardTab"
  250. FunctionEnd


  251. # ========================= 安装步骤 ===============================

  252. Function CreateShortcut
  253.   SetShellVarContext all
  254.   CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
  255.   CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk" "$INSTDIR\Bin\${EXE_NAME}"
  256.   CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\卸载${PRODUCT_NAME}.lnk" "$INSTDIR\uninst.exe"
  257.   CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\Bin\${EXE_NAME}"
  258.   SetShellVarContext current
  259. FunctionEnd



  260. Function CreateUninstall

  261.         # 生成卸载程序
  262.         WriteUninstaller "$INSTDIR\uninst.exe"
  263.         
  264.         # 添加卸载信息到控制面板
  265.         WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayName" "${PRODUCT_NAME}"
  266.         WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "UninstallString" "$INSTDIR\uninst.exe"
  267.         WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "DisplayIcon" "$INSTDIR\${EXE_NAME}"
  268.         WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" "Publisher" "$INSTDIR\${PRODUCT_PUBLISHER}"
  269. FunctionEnd

  270. # 添加一个空的Section,防止编译器报错
  271. Section "None"
  272. SectionEnd


  273. # 卸载区段
  274. Section "Uninstall"

  275.   ; 删除快捷方式
  276.   SetShellVarContext all
  277.   Delete "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk"
  278.   Delete "$SMPROGRAMS\${PRODUCT_NAME}\卸载${PRODUCT_NAME}.lnk"
  279.   RMDir "$SMPROGRAMS\${PRODUCT_NAME}"
  280.   Delete "$DESKTOP\${PRODUCT_NAME}.lnk"
  281.   SetShellVarContext current
  282.   
  283.   SetOutPath "$INSTDIR"

  284.   ; 删除安装的文件
  285.   Delete "$INSTDIR\*.*"

  286.   SetOutPath "$DESKTOP"

  287.   RMDir /r "$INSTDIR"
  288.   RMDir "$INSTDIR"
  289.   
  290.   SetAutoClose true
  291. SectionEnd





  292. # ============================== 回调函数 ====================================

  293. # 函数名以“.”开头的一般作为回调函数保留.
  294. # 函数名以“un.”开头的函数将会被创建在卸载程序里,因此,普通安装区段和函数不能调用卸载函数,而卸载区段和卸载函数也不能调用普通函数。

  295. Function .onInit

  296. FunctionEnd


  297. # 安装成功以后.
  298. Function .onInstSuccess

  299. FunctionEnd

  300. # 在安装失败后用户点击“取消”按钮时被调用.
  301. Function .onInstFailed
  302.     MessageBox MB_ICONQUESTION|MB_YESNO "安装成功!" /SD IDYES IDYES +2 IDNO +1
  303. FunctionEnd


  304. # 每次用户更改安装路径的时候这段代码都会被调用一次.
  305. Function .onVerifyInstDir

  306. FunctionEnd

  307. # 卸载操作开始前.
  308. Function un.onInit
  309.     MessageBox MB_ICONQUESTION|MB_YESNO "您确定要卸载${PRODUCT_NAME}吗?" /SD IDYES IDYES +2 IDNO +1
  310.     Abort
  311. FunctionEnd

  312. # 卸载成功以后.
  313. Function un.onUninstSuccess

  314. FunctionEnd


复制代码
全额附件
游客,本帖隐藏的内容需要积分高于 500 才可浏览,您当前积分为 0

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-18 00:20 , Processed in 0.107818 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表