【Cocos2d-x】实现资源热更新

前端之家收集整理的这篇文章主要介绍了【Cocos2d-x】实现资源热更新前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

http://www.cnblogs.com/tuituier/articles/3859501.html 这也是一篇热更新的文章

cocos-x 热更新探索

来到园子这么久了,竟然连博客博客的权限才开通,相当的汗颜啊,之前在百度空间写的博客,发现还是术业有专攻最好,程序员还是老老实实呆在程序员的圈子里吧!对了,之前百度空间的地址顺便宣传下,哈哈:

http://hi.baidu.com/awming520

---------------------------------正文分割线------------------------------------

本文是探索cocos-x热更新,其实就是探索cocos-lua或者js的脚本和资源热更新,热更的作用也不用我在这里为大家普及了。

文中主要使用python作为服务器的脚本,lua作为客户端脚本,是用cocos code ide作为开发环境。

在此之前可以参考我之前发表在cocoachina上关于热更新后台的实现,里面大概讲解了实现与原理(文件结构有小小变动,现在增加了项目名称,可以发布多个项目):

http://www.cocoachina.com/bbs/read.php?tid=213054

后台环境:
python 2.7 + webpy0.37
webpy安装:
1、解压webpy,cmd至webpy路径下
2、cmd运行python setup.py install
详细了解webpy,请访问其官网:http://webpy.org/


为了保持客户端最安全与最小化热更新,我们需要判断出每个版本的差异,将差异文件下载到客户端。为了差异识别,我们将生产res与src下所有文件的MD5,并将其保存至相关文件夹,保存内容如下:
src/test1.lua:e6e8feb29a41a0d83c29c834c10a42a2
src/test2.lua:b87957f382a4a292db91bd937b66a000
res/ani/enemy/monster.csb:6a42885d985f777418d97ef956758f2e
res/ani/enemy/monster.exportjson:1c26ec5818281794e98a4d05c3d871c4
后面我们只需要对比客户端当前版本与服务器最新版本的资源列表的md5以及判断哪些是新增文件,这样我们就可最小化获取需要更新的列表。
到此,我们可以将此文件连同当前版本文件放至服务器,让客户端下载更新列表,并在客户端判断需要下载那些文件,但是这样真的好么,如果一次更新n个文件,那样的连接将会有n次,可能是我多虑了。但我考虑到我们的版本不可能无限次发布,因此我决定将版本差异的包放在服务器,这样客户端只用告诉我们他当前什么版本,就可以获取升级至最新版本的更新包。
比如客户端当前版本为1.0,服务器最新版本为2.0,通过url传至服务器,客户端就可以获取一个1.0升级到2.0的资源包,客户端通过assertManager可以文件解压,我们再将解压目录文件移动至我们的查找目录就ok了。
服务器通过各个版本的资源列表,获取改动和新增的文件,并将其打包压缩至zip文件。而且由于我们发布的版本是确定的,因此这些更新文件在服务器只会生成一次,对服务器来说基本没什么压力,而且我们可以将其预先生成,保存至服务器。

在服务端,我采用如下路径配置:
App:(项目名称
--project:(保存最新项目资源,手工配置)
----res:(资源路径)
----src:(脚本路径)
--publish:(更新包路径,目录下文件自动生成
----version.txt(当前最新版本号,手工修改)
----1.0(1.0版本包)
------list.txt(当前版本1.0的资源列表及MD5)
------update.zip(只有基本版本才会在当前路径层级下有更新包)
----2.0
------list.txt
------1.0
--------update.zip(1.0升级到2.0需要的更新资源包)
...
我们需要手工配置下project文件,这里面保存我们所发布的最新资源和脚本;publish下保存的是各种版本的更新包。
最终我们运行程序后,可以通过url访问版本与获取更新资源包:
获取最新版本号:http://127.0.0.1:8080/?action=ver
下载更新包:http://127.0.0.1:8080/?action=update.zip&ver=1.1(ver为本地当前版本,url中需要有.zip,cocos2d-x终对url做了判断)


下载地址:http://pan.baidu.com/s/1eQ7WJxK
其余信息可以阅读readme.txt

简单说下思路就是,将客户端当前版本与服务器最新版本做md5比对,将最新版本与客户端版本差异的文件打包,并下载至客户端,完成资源的热更新。

这种后台实现主要解决一下几个问题:

1.如果将资源包完全打包为一个文件,需要下载的文件势必会大很多,每次都会下载很多相同的文体。

2.如果按照版本差异更新,则需要将最新版本的资源包挨个下载一遍,多麻烦呀!

3.如果对服务器文件作md5记录,而单独下载相关文件。这样将会造成复杂的客户端代码,而且每个需要更新的文件都去连接服务器,给服务器造成了压力,而且包的传输肯定要比单个小文件来的快,而且更不容易出错吧!(这完全是个人猜想)

4.第三条也说了,我想让客户端代码变得简单。最简单的方式就是不写或者少些代码,我就想是用cocos-x自带的assertmanager来实现热更新。(其实我是偷懒而已)

说说我认为这样做的好处吧:

1.需要更新的资源减少了。

2.服务器需要保存的版本减少了,只需要保存最新两个版本就ok了。

3.支持版本回退(只需要将上一个版本编号改为最新版本号,并生成更新资源包)。

4.客户端代码减少,并且安全。

--------------------------------------------------------------------------------

今天我带来的是我将之前在cocoachina发表的版本完善后东西,包括服务端与客户端实现:

服务端包含了assertmanager需要的两个链接(版本与包地址的url,而且包地址必须还有.zip这样的字符串,不然会被判断无效,郁闷!)

也有预生成资源包的接口,可以在新版本发布的时候调用,用来生成最新的版本差异包。

客户端代码我是用了cocos code ide,不过也没怎么用它framework里面的东西,修改起来很简单,其实我提供的客户端代码更多算个代码示例(demo)。

废话不多说了。服务端使用可以参考server.zip中的readme.txt。

对了:欢迎大家对我这个新手批评与指正!

------------------------------------下载地址-----------------------------------

server:http://pan.baidu.com/s/1dD8Faxj

client:http://pan.baidu.com/s/1qW16ZZA

--------------------------------------------------------------------------------

注:由于code ide中对lua自带文件系统lfs不支持,因此我使用了cocos2d-x自带luatest中的文件创建的接口,并将其导出至项目中。因此如果要使用客户端项目时需要注意将createDownloadDir与deleteDownloadDir两个函数导出,c++代码位置为:%engine_root%\tests\lua-tests\project\Classes\lua_assetsmanager_test_sample.cpp(.h),当然你可以选择不创建文件夹,而将更新文件直接解压到可写路径之下!貌似assertmanager可以自己创建存储路径,不过我还未测试。

另外,强烈希望cocos2d-lua能支持lfs或者写出自己功能更强的文件系统!



================================================================================================================================================================




转载于http://blog.csdn.net/linchaolong/article/details/42321767



在cocos2dx 3.4 运行通过


下载地址为:在我的下载里面


【Cocos2d-x】实现资源热更新

分类Cocos2d-x 461人阅读 评论(0) 收藏 举报

目录(?)[+]


热更新介绍


什么是热更新?

游戏客户端启动时,主动请求服务端检查版本号,并更新资源到本地。


应用场景:

情况一:游戏客户端已经发布了,但突然发现有个比较严重的bug需要修复。这时需要更新游戏的代码(Lua代码)。

情况二:情人节到了,需要搞个活动,在游戏中营造一个节日氛围。这时,需要更新游戏资源或增加一些功能


好处:不需要重新打包和提交应用到市场等待审核



热更新流程





AssetsManager


在Cocos2d-x中已经封装了用于实现热更新功能的类,就是AssetsManager。


api说明:

// 检测是否有版本更新
virtual bool checkUpdate();

// 下载更新的资源包并解压到下载路径
virtual void update();

// 获取当前客户端版本号
std::string getVersion();

// 删除客户端版本号
void deleteVersion();

// 设置下载回调(AssetsManagerDelegateProtocol)
void setDelegate(AssetsManagerDelegateProtocol *delegate);

// 设置连接超时时间(单位:秒)
void setConnectionTimeout(unsigned int timeout);

// 设置从服务端下载资源包的url
void setPackageUrl(const char* packageUrl);

// 设置服务端获取版本号的url
void setVersionFileUrl(const char* versionFileUrl);

// 设置资源保存路径
void setStoragePath(const char* storagePath);


因为AssetsManager使用了pthread库,所以需要在win32工程中需要包含pthread库所在目录。

VS在工程属性——C/C++——常规——附加包含目录中添加:$(ProjectDir)..\..\..\cocos2dx\platform\third_party\win32\pthread



示例工程


该工程使用Cocos2d-x2.1.6和VS2012。【点击下载源码】


把工程放到引擎projects目录下即可。


  1. <a target=_blank id="L1" href="http://blog.csdn.net/linchaolong/article/details/42321767#L1" rel="#L1" style="text-decoration: none; color: rgb(12,207);"> 1</a>
  2. <a target=_blank id="L2" href="http://blog.csdn.net/linchaolong/article/details/42321767#L2" rel="#L2" style="text-decoration: none; color: rgb(12,207);"> 2</a>
  3. <a target=_blank id="L3" href="http://blog.csdn.net/linchaolong/article/details/42321767#L3" rel="#L3" style="text-decoration: none; color: rgb(12,207);"> 3</a>
  4. <a target=_blank id="L4" href="http://blog.csdn.net/linchaolong/article/details/42321767#L4" rel="#L4" style="text-decoration: none; color: rgb(12,207);"> 4</a>
  5. <a target=_blank id="L5" href="http://blog.csdn.net/linchaolong/article/details/42321767#L5" rel="#L5" style="text-decoration: none; color: rgb(12,207);"> 5</a>
  6. <a target=_blank id="L6" href="http://blog.csdn.net/linchaolong/article/details/42321767#L6" rel="#L6" style="text-decoration: none; color: rgb(12,207);"> 6</a>
  7. <a target=_blank id="L7" href="http://blog.csdn.net/linchaolong/article/details/42321767#L7" rel="#L7" style="text-decoration: none; color: rgb(12,207);"> 7</a>
  8. <a target=_blank id="L8" href="http://blog.csdn.net/linchaolong/article/details/42321767#L8" rel="#L8" style="text-decoration: none; color: rgb(12,207);"> 8</a>
  9. <a target=_blank id="L9" href="http://blog.csdn.net/linchaolong/article/details/42321767#L9" rel="#L9" style="text-decoration: none; color: rgb(12,207);"> 9</a>
  10. <a target=_blank id="L10" href="http://blog.csdn.net/linchaolong/article/details/42321767#L10" rel="#L10" style="text-decoration: none; color: rgb(12,207);"> 10</a>
  11. <a target=_blank id="L11" href="http://blog.csdn.net/linchaolong/article/details/42321767#L11" rel="#L11" style="text-decoration: none; color: rgb(12,207);"> 11</a>
  12. <a target=_blank id="L12" href="http://blog.csdn.net/linchaolong/article/details/42321767#L12" rel="#L12" style="text-decoration: none; color: rgb(12,207);"> 12</a>
  13. <a target=_blank id="L13" href="http://blog.csdn.net/linchaolong/article/details/42321767#L13" rel="#L13" style="text-decoration: none; color: rgb(12,207);"> 13</a>
  14. <a target=_blank id="L14" href="http://blog.csdn.net/linchaolong/article/details/42321767#L14" rel="#L14" style="text-decoration: none; color: rgb(12,207);"> 14</a>
  15. <a target=_blank id="L15" href="http://blog.csdn.net/linchaolong/article/details/42321767#L15" rel="#L15" style="text-decoration: none; color: rgb(12,207);"> 15</a>
  16. <a target=_blank id="L16" href="http://blog.csdn.net/linchaolong/article/details/42321767#L16" rel="#L16" style="text-decoration: none; color: rgb(12,207);"> 16</a>
  17. <a target=_blank id="L17" href="http://blog.csdn.net/linchaolong/article/details/42321767#L17" rel="#L17" style="text-decoration: none; color: rgb(12,207);"> 17</a>
  18. <a target=_blank id="L18" href="http://blog.csdn.net/linchaolong/article/details/42321767#L18" rel="#L18" style="text-decoration: none; color: rgb(12,207);"> 18</a>
  19. <a target=_blank id="L19" href="http://blog.csdn.net/linchaolong/article/details/42321767#L19" rel="#L19" style="text-decoration: none; color: rgb(12,207);"> 19</a>
  20. <a target=_blank id="L20" href="http://blog.csdn.net/linchaolong/article/details/42321767#L20" rel="#L20" style="text-decoration: none; color: rgb(12,207);"> 20</a>
  21. <a target=_blank id="L21" href="http://blog.csdn.net/linchaolong/article/details/42321767#L21" rel="#L21" style="text-decoration: none; color: rgb(12,207);"> 21</a>
  22. <a target=_blank id="L22" href="http://blog.csdn.net/linchaolong/article/details/42321767#L22" rel="#L22" style="text-decoration: none; color: rgb(12,207);"> 22</a>
  23. <a target=_blank id="L23" href="http://blog.csdn.net/linchaolong/article/details/42321767#L23" rel="#L23" style="text-decoration: none; color: rgb(12,207);"> 23</a>
  24. <a target=_blank id="L24" href="http://blog.csdn.net/linchaolong/article/details/42321767#L24" rel="#L24" style="text-decoration: none; color: rgb(12,207);"> 24</a>
  25. <a target=_blank id="L25" href="http://blog.csdn.net/linchaolong/article/details/42321767#L25" rel="#L25" style="text-decoration: none; color: rgb(12,207);"> 25</a>
  26. <a target=_blank id="L26" href="http://blog.csdn.net/linchaolong/article/details/42321767#L26" rel="#L26" style="text-decoration: none; color: rgb(12,207);"> 26</a>
  27. <a target=_blank id="L27" href="http://blog.csdn.net/linchaolong/article/details/42321767#L27" rel="#L27" style="text-decoration: none; color: rgb(12,207);"> 27</a>
  28. <a target=_blank id="L28" href="http://blog.csdn.net/linchaolong/article/details/42321767#L28" rel="#L28" style="text-decoration: none; color: rgb(12,207);"> 28</a>
  29. <a target=_blank id="L29" href="http://blog.csdn.net/linchaolong/article/details/42321767#L29" rel="#L29" style="text-decoration: none; color: rgb(12,207);"> 29</a>
  30. <a target=_blank id="L30" href="http://blog.csdn.net/linchaolong/article/details/42321767#L30" rel="#L30" style="text-decoration: none; color: rgb(12,207);"> 30</a>
  31. <a target=_blank id="L31" href="http://blog.csdn.net/linchaolong/article/details/42321767#L31" rel="#L31" style="text-decoration: none; color: rgb(12,207);"> 31</a>
  32. <a target=_blank id="L32" href="http://blog.csdn.net/linchaolong/article/details/42321767#L32" rel="#L32" style="text-decoration: none; color: rgb(12,207);"> 32</a>
  33. <a target=_blank id="L33" href="http://blog.csdn.net/linchaolong/article/details/42321767#L33" rel="#L33" style="text-decoration: none; color: rgb(12,207);"> 33</a>
  34. <a target=_blank id="L34" href="http://blog.csdn.net/linchaolong/article/details/42321767#L34" rel="#L34" style="text-decoration: none; color: rgb(12,207);"> 34</a>
  35. <a target=_blank id="L35" href="http://blog.csdn.net/linchaolong/article/details/42321767#L35" rel="#L35" style="text-decoration: none; color: rgb(12,207);"> 35</a>
  36. <a target=_blank id="L36" href="http://blog.csdn.net/linchaolong/article/details/42321767#L36" rel="#L36" style="text-decoration: none; color: rgb(12,207);"> 36</a>
  37. <a target=_blank id="L37" href="http://blog.csdn.net/linchaolong/article/details/42321767#L37" rel="#L37" style="text-decoration: none; color: rgb(12,207);"> 37</a>
  38. <a target=_blank id="L38" href="http://blog.csdn.net/linchaolong/article/details/42321767#L38" rel="#L38" style="text-decoration: none; color: rgb(12,207);"> 38</a>
  39. <a target=_blank id="L39" href="http://blog.csdn.net/linchaolong/article/details/42321767#L39" rel="#L39" style="text-decoration: none; color: rgb(12,207);"> 39</a>
  40. <a target=_blank id="L40" href="http://blog.csdn.net/linchaolong/article/details/42321767#L40" rel="#L40" style="text-decoration: none; color: rgb(12,207);"> 40</a>
  41. <a target=_blank id="L41" href="http://blog.csdn.net/linchaolong/article/details/42321767#L41" rel="#L41" style="text-decoration: none; color: rgb(12,207);"> 41</a>
  42. <a target=_blank id="L42" href="http://blog.csdn.net/linchaolong/article/details/42321767#L42" rel="#L42" style="text-decoration: none; color: rgb(12,207);"> 42</a>
  43. <a target=_blank id="L43" href="http://blog.csdn.net/linchaolong/article/details/42321767#L43" rel="#L43" style="text-decoration: none; color: rgb(12,207);"> 43</a>
  44. <a target=_blank id="L44" href="http://blog.csdn.net/linchaolong/article/details/42321767#L44" rel="#L44" style="text-decoration: none; color: rgb(12,207);"> 44</a>
  45. <a target=_blank id="L45" href="http://blog.csdn.net/linchaolong/article/details/42321767#L45" rel="#L45" style="text-decoration: none; color: rgb(12,207);"> 45</a>
  46. <a target=_blank id="L46" href="http://blog.csdn.net/linchaolong/article/details/42321767#L46" rel="#L46" style="text-decoration: none; color: rgb(12,207);"> 46</a>
  47. <a target=_blank id="L47" href="http://blog.csdn.net/linchaolong/article/details/42321767#L47" rel="#L47" style="text-decoration: none; color: rgb(12,207);"> 47</a>
  48. <a target=_blank id="L48" href="http://blog.csdn.net/linchaolong/article/details/42321767#L48" rel="#L48" style="text-decoration: none; color: rgb(12,207);"> 48</a>
  49. <a target=_blank id="L49" href="http://blog.csdn.net/linchaolong/article/details/42321767#L49" rel="#L49" style="text-decoration: none; color: rgb(12,207);"> 49</a>
  50. <a target=_blank id="L50" href="http://blog.csdn.net/linchaolong/article/details/42321767#L50" rel="#L50" style="text-decoration: none; color: rgb(12,207);"> 50</a>
  51. <a target=_blank id="L51" href="http://blog.csdn.net/linchaolong/article/details/42321767#L51" rel="#L51" style="text-decoration: none; color: rgb(12,207);"> 51</a>
  52. <a target=_blank id="L52" href="http://blog.csdn.net/linchaolong/article/details/42321767#L52" rel="#L52" style="text-decoration: none; color: rgb(12,207);"> 52</a>
  53. <a target=_blank id="L53" href="http://blog.csdn.net/linchaolong/article/details/42321767#L53" rel="#L53" style="text-decoration: none; color: rgb(12,207);"> 53</a>
  54. <a target=_blank id="L54" href="http://blog.csdn.net/linchaolong/article/details/42321767#L54" rel="#L54" style="text-decoration: none; color: rgb(12,207);"> 54</a>
  55. <a target=_blank id="L55" href="http://blog.csdn.net/linchaolong/article/details/42321767#L55" rel="#L55" style="text-decoration: none; color: rgb(12,207);"> 55</a>
  56. <a target=_blank id="L56" href="http://blog.csdn.net/linchaolong/article/details/42321767#L56" rel="#L56" style="text-decoration: none; color: rgb(12,207);"> 56</a>
  57. <a target=_blank id="L57" href="http://blog.csdn.net/linchaolong/article/details/42321767#L57" rel="#L57" style="text-decoration: none; color: rgb(12,207);"> 57</a>
  58. <a target=_blank id="L58" href="http://blog.csdn.net/linchaolong/article/details/42321767#L58" rel="#L58" style="text-decoration: none; color: rgb(12,207);"> 58</a>
  59. <a target=_blank id="L59" href="http://blog.csdn.net/linchaolong/article/details/42321767#L59" rel="#L59" style="text-decoration: none; color: rgb(12,207);"> 59</a>
  60. <a target=_blank id="L60" href="http://blog.csdn.net/linchaolong/article/details/42321767#L60" rel="#L60" style="text-decoration: none; color: rgb(12,207);"> 60</a>
  61. <a target=_blank id="L61" href="http://blog.csdn.net/linchaolong/article/details/42321767#L61" rel="#L61" style="text-decoration: none; color: rgb(12,207);"> 61</a>
  62. <a target=_blank id="L62" href="http://blog.csdn.net/linchaolong/article/details/42321767#L62" rel="#L62" style="text-decoration: none; color: rgb(12,207);"> 62</a>
  63. <a target=_blank id="L63" href="http://blog.csdn.net/linchaolong/article/details/42321767#L63" rel="#L63" style="text-decoration: none; color: rgb(12,207);"> 63</a>
  64. <a target=_blank id="L64" href="http://blog.csdn.net/linchaolong/article/details/42321767#L64" rel="#L64" style="text-decoration: none; color: rgb(12,207);"> 64</a>
  65. <a target=_blank id="L65" href="http://blog.csdn.net/linchaolong/article/details/42321767#L65" rel="#L65" style="text-decoration: none; color: rgb(12,207);"> 65</a>
  66. <a target=_blank id="L66" href="http://blog.csdn.net/linchaolong/article/details/42321767#L66" rel="#L66" style="text-decoration: none; color: rgb(12,207);"> 66</a>
  67. <a target=_blank id="L67" href="http://blog.csdn.net/linchaolong/article/details/42321767#L67" rel="#L67" style="text-decoration: none; color: rgb(12,207);"> 67</a>
  68. <a target=_blank id="L68" href="http://blog.csdn.net/linchaolong/article/details/42321767#L68" rel="#L68" style="text-decoration: none; color: rgb(12,207);"> 68</a>
  69. <a target=_blank id="L69" href="http://blog.csdn.net/linchaolong/article/details/42321767#L69" rel="#L69" style="text-decoration: none; color: rgb(12,207);"> 69</a>
  70. <a target=_blank id="L70" href="http://blog.csdn.net/linchaolong/article/details/42321767#L70" rel="#L70" style="text-decoration: none; color: rgb(12,207);"> 70</a>
  71. <a target=_blank id="L71" href="http://blog.csdn.net/linchaolong/article/details/42321767#L71" rel="#L71" style="text-decoration: none; color: rgb(12,207);"> 71</a>
  72. <a target=_blank id="L72" href="http://blog.csdn.net/linchaolong/article/details/42321767#L72" rel="#L72" style="text-decoration: none; color: rgb(12,207);"> 72</a>
  73. <a target=_blank id="L73" href="http://blog.csdn.net/linchaolong/article/details/42321767#L73" rel="#L73" style="text-decoration: none; color: rgb(12,207);"> 73</a>
  74. <a target=_blank id="L74" href="http://blog.csdn.net/linchaolong/article/details/42321767#L74" rel="#L74" style="text-decoration: none; color: rgb(12,207);"> 74</a>
  75. <a target=_blank id="L75" href="http://blog.csdn.net/linchaolong/article/details/42321767#L75" rel="#L75" style="text-decoration: none; color: rgb(12,207);"> 75</a>
  76. <a target=_blank id="L76" href="http://blog.csdn.net/linchaolong/article/details/42321767#L76" rel="#L76" style="text-decoration: none; color: rgb(12,207);"> 76</a>
  77. <a target=_blank id="L77" href="http://blog.csdn.net/linchaolong/article/details/42321767#L77" rel="#L77" style="text-decoration: none; color: rgb(12,207);"> 77</a>
  78. <a target=_blank id="L78" href="http://blog.csdn.net/linchaolong/article/details/42321767#L78" rel="#L78" style="text-decoration: none; color: rgb(12,207);"> 78</a>
  79. <a target=_blank id="L79" href="http://blog.csdn.net/linchaolong/article/details/42321767#L79" rel="#L79" style="text-decoration: none; color: rgb(12,207);"> 79</a>
  80. <a target=_blank id="L80" href="http://blog.csdn.net/linchaolong/article/details/42321767#L80" rel="#L80" style="text-decoration: none; color: rgb(12,207);"> 80</a>
  81. <a target=_blank id="L81" href="http://blog.csdn.net/linchaolong/article/details/42321767#L81" rel="#L81" style="text-decoration: none; color: rgb(12,207);"> 81</a>
  82. <a target=_blank id="L82" href="http://blog.csdn.net/linchaolong/article/details/42321767#L82" rel="#L82" style="text-decoration: none; color: rgb(12,207);"> 82</a>
  83. <a target=_blank id="L83" href="http://blog.csdn.net/linchaolong/article/details/42321767#L83" rel="#L83" style="text-decoration: none; color: rgb(12,207);"> 83</a>
  84. <a target=_blank id="L84" href="http://blog.csdn.net/linchaolong/article/details/42321767#L84" rel="#L84" style="text-decoration: none; color: rgb(12,207);"> 84</a>
  85. <a target=_blank id="L85" href="http://blog.csdn.net/linchaolong/article/details/42321767#L85" rel="#L85" style="text-decoration: none; color: rgb(12,207);"> 85</a>
  86. <a target=_blank id="L86" href="http://blog.csdn.net/linchaolong/article/details/42321767#L86" rel="#L86" style="text-decoration: none; color: rgb(12,207);"> 86</a>
  87. <a target=_blank id="L87" href="http://blog.csdn.net/linchaolong/article/details/42321767#L87" rel="#L87" style="text-decoration: none; color: rgb(12,207);"> 87</a>
  88. <a target=_blank id="L88" href="http://blog.csdn.net/linchaolong/article/details/42321767#L88" rel="#L88" style="text-decoration: none; color: rgb(12,207);"> 88</a>
  89. <a target=_blank id="L89" href="http://blog.csdn.net/linchaolong/article/details/42321767#L89" rel="#L89" style="text-decoration: none; color: rgb(12,207);"> 89</a>
  90. <a target=_blank id="L90" href="http://blog.csdn.net/linchaolong/article/details/42321767#L90" rel="#L90" style="text-decoration: none; color: rgb(12,207);"> 90</a>
  91. <a target=_blank id="L91" href="http://blog.csdn.net/linchaolong/article/details/42321767#L91" rel="#L91" style="text-decoration: none; color: rgb(12,207);"> 91</a>
  92. <a target=_blank id="L92" href="http://blog.csdn.net/linchaolong/article/details/42321767#L92" rel="#L92" style="text-decoration: none; color: rgb(12,207);"> 92</a>
  93. <a target=_blank id="L93" href="http://blog.csdn.net/linchaolong/article/details/42321767#L93" rel="#L93" style="text-decoration: none; color: rgb(12,207);"> 93</a>
  94. <a target=_blank id="L94" href="http://blog.csdn.net/linchaolong/article/details/42321767#L94" rel="#L94" style="text-decoration: none; color: rgb(12,207);"> 94</a>
  95. <a target=_blank id="L95" href="http://blog.csdn.net/linchaolong/article/details/42321767#L95" rel="#L95" style="text-decoration: none; color: rgb(12,207);"> 95</a>
  96. <a target=_blank id="L96" href="http://blog.csdn.net/linchaolong/article/details/42321767#L96" rel="#L96" style="text-decoration: none; color: rgb(12,207);"> 96</a>
  97. <a target=_blank id="L97" href="http://blog.csdn.net/linchaolong/article/details/42321767#L97" rel="#L97" style="text-decoration: none; color: rgb(12,207);"> 97</a>
  98. <a target=_blank id="L98" href="http://blog.csdn.net/linchaolong/article/details/42321767#L98" rel="#L98" style="text-decoration: none; color: rgb(12,207);"> 98</a>
  99. <a target=_blank id="L99" href="http://blog.csdn.net/linchaolong/article/details/42321767#L99" rel="#L99" style="text-decoration: none; color: rgb(12,207);"> 99</a>
  100. <a target=_blank id="L100" href="http://blog.csdn.net/linchaolong/article/details/42321767#L100" rel="#L100" style="text-decoration: none; color: rgb(12,207);"> 100</a>
  101. <a target=_blank id="L101" href="http://blog.csdn.net/linchaolong/article/details/42321767#L101" rel="#L101" style="text-decoration: none; color: rgb(12,207);"> 101</a>
  102. <a target=_blank id="L102" href="http://blog.csdn.net/linchaolong/article/details/42321767#L102" rel="#L102" style="text-decoration: none; color: rgb(12,207);"> 102</a>
  103. <a target=_blank id="L103" href="http://blog.csdn.net/linchaolong/article/details/42321767#L103" rel="#L103" style="text-decoration: none; color: rgb(12,207);"> 103</a>
  104. <a target=_blank id="L104" href="http://blog.csdn.net/linchaolong/article/details/42321767#L104" rel="#L104" style="text-decoration: none; color: rgb(12,207);"> 104</a>
  105. <a target=_blank id="L105" href="http://blog.csdn.net/linchaolong/article/details/42321767#L105" rel="#L105" style="text-decoration: none; color: rgb(12,207);"> 105</a>
  106. <a target=_blank id="L106" href="http://blog.csdn.net/linchaolong/article/details/42321767#L106" rel="#L106" style="text-decoration: none; color: rgb(12,207);"> 106</a>
  107. <a target=_blank id="L107" href="http://blog.csdn.net/linchaolong/article/details/42321767#L107" rel="#L107" style="text-decoration: none; color: rgb(12,207);"> 107</a>
  108. <a target=_blank id="L108" href="http://blog.csdn.net/linchaolong/article/details/42321767#L108" rel="#L108" style="text-decoration: none; color: rgb(12,207);"> 108</a>
  109. <a target=_blank id="L109" href="http://blog.csdn.net/linchaolong/article/details/42321767#L109" rel="#L109" style="text-decoration: none; color: rgb(12,207);"> 109</a>
  110. <a target=_blank id="L110" href="http://blog.csdn.net/linchaolong/article/details/42321767#L110" rel="#L110" style="text-decoration: none; color: rgb(12,207);"> 110</a>
  111. <a target=_blank id="L111" href="http://blog.csdn.net/linchaolong/article/details/42321767#L111" rel="#L111" style="text-decoration: none; color: rgb(12,207);"> 111</a>
  112. <a target=_blank id="L112" href="http://blog.csdn.net/linchaolong/article/details/42321767#L112" rel="#L112" style="text-decoration: none; color: rgb(12,207);"> 112</a>
  113. <a target=_blank id="L113" href="http://blog.csdn.net/linchaolong/article/details/42321767#L113" rel="#L113" style="text-decoration: none; color: rgb(12,207);"> 113</a>
  114. <a target=_blank id="L114" href="http://blog.csdn.net/linchaolong/article/details/42321767#L114" rel="#L114" style="text-decoration: none; color: rgb(12,207);"> 114</a>
  115. <a target=_blank id="L115" href="http://blog.csdn.net/linchaolong/article/details/42321767#L115" rel="#L115" style="text-decoration: none; color: rgb(12,207);"> 115</a>
  116. <a target=_blank id="L116" href="http://blog.csdn.net/linchaolong/article/details/42321767#L116" rel="#L116" style="text-decoration: none; color: rgb(12,207);"> 116</a>
  117. <a target=_blank id="L117" href="http://blog.csdn.net/linchaolong/article/details/42321767#L117" rel="#L117" style="text-decoration: none; color: rgb(12,207);"> 117</a>
  118. <a target=_blank id="L118" href="http://blog.csdn.net/linchaolong/article/details/42321767#L118" rel="#L118" style="text-decoration: none; color: rgb(12,207);"> 118</a>
  119. <a target=_blank id="L119" href="http://blog.csdn.net/linchaolong/article/details/42321767#L119" rel="#L119" style="text-decoration: none; color: rgb(12,207);"> 119</a>
  120. <a target=_blank id="L120" href="http://blog.csdn.net/linchaolong/article/details/42321767#L120" rel="#L120" style="text-decoration: none; color: rgb(12,207);"> 120</a>
  121. <a target=_blank id="L121" href="http://blog.csdn.net/linchaolong/article/details/42321767#L121" rel="#L121" style="text-decoration: none; color: rgb(12,207);"> 121</a>
  122. <a target=_blank id="L122" href="http://blog.csdn.net/linchaolong/article/details/42321767#L122" rel="#L122" style="text-decoration: none; color: rgb(12,207);"> 122</a>
  123. <a target=_blank id="L123" href="http://blog.csdn.net/linchaolong/article/details/42321767#L123" rel="#L123" style="text-decoration: none; color: rgb(12,207);"> 123</a>
  124. <a target=_blank id="L124" href="http://blog.csdn.net/linchaolong/article/details/42321767#L124" rel="#L124" style="text-decoration: none; color: rgb(12,207);"> 124</a>
  125. <a target=_blank id="L125" href="http://blog.csdn.net/linchaolong/article/details/42321767#L125" rel="#L125" style="text-decoration: none; color: rgb(12,207);"> 125</a>
  126. <a target=_blank id="L126" href="http://blog.csdn.net/linchaolong/article/details/42321767#L126" rel="#L126" style="text-decoration: none; color: rgb(12,207);"> 126</a>
  127. <a target=_blank id="L127" href="http://blog.csdn.net/linchaolong/article/details/42321767#L127" rel="#L127" style="text-decoration: none; color: rgb(12,207);"> 127</a>
  128. <a target=_blank id="L128" href="http://blog.csdn.net/linchaolong/article/details/42321767#L128" rel="#L128" style="text-decoration: none; color: rgb(12,207);"> 128</a>
  129. <a target=_blank id="L129" href="http://blog.csdn.net/linchaolong/article/details/42321767#L129" rel="#L129" style="text-decoration: none; color: rgb(12,207);"> 129</a>
  130. <a target=_blank id="L130" href="http://blog.csdn.net/linchaolong/article/details/42321767#L130" rel="#L130" style="text-decoration: none; color: rgb(12,207);"> 130</a>
  131. <a target=_blank id="L131" href="http://blog.csdn.net/linchaolong/article/details/42321767#L131" rel="#L131" style="text-decoration: none; color: rgb(12,207);"> 131</a>
  132. <a target=_blank id="L132" href="http://blog.csdn.net/linchaolong/article/details/42321767#L132" rel="#L132" style="text-decoration: none; color: rgb(12,207);"> 132</a>
  133. <a target=_blank id="L133" href="http://blog.csdn.net/linchaolong/article/details/42321767#L133" rel="#L133" style="text-decoration: none; color: rgb(12,207);"> 133</a>
  134. <a target=_blank id="L134" href="http://blog.csdn.net/linchaolong/article/details/42321767#L134" rel="#L134" style="text-decoration: none; color: rgb(12,207);"> 134</a>
  135. <a target=_blank id="L135" href="http://blog.csdn.net/linchaolong/article/details/42321767#L135" rel="#L135" style="text-decoration: none; color: rgb(12,207);"> 135</a>
  136. <a target=_blank id="L136" href="http://blog.csdn.net/linchaolong/article/details/42321767#L136" rel="#L136" style="text-decoration: none; color: rgb(12,207);"> 136</a>
  137. <a target=_blank id="L137" href="http://blog.csdn.net/linchaolong/article/details/42321767#L137" rel="#L137" style="text-decoration: none; color: rgb(12,207);"> 137</a>
  138. <a target=_blank id="L138" href="http://blog.csdn.net/linchaolong/article/details/42321767#L138" rel="#L138" style="text-decoration: none; color: rgb(12,207);"> 138</a>
  139. <a target=_blank id="L139" href="http://blog.csdn.net/linchaolong/article/details/42321767#L139" rel="#L139" style="text-decoration: none; color: rgb(12,207);"> 139</a>
  140. <a target=_blank id="L140" href="http://blog.csdn.net/linchaolong/article/details/42321767#L140" rel="#L140" style="text-decoration: none; color: rgb(12,207);"> 140</a>
  141. <a target=_blank id="L141" href="http://blog.csdn.net/linchaolong/article/details/42321767#L141" rel="#L141" style="text-decoration: none; color: rgb(12,207);"> 141</a>
  142. <a target=_blank id="L142" href="http://blog.csdn.net/linchaolong/article/details/42321767#L142" rel="#L142" style="text-decoration: none; color: rgb(12,207);"> 142</a>
  143. <a target=_blank id="L143" href="http://blog.csdn.net/linchaolong/article/details/42321767#L143" rel="#L143" style="text-decoration: none; color: rgb(12,207);"> 143</a>
  144. <a target=_blank id="L144" href="http://blog.csdn.net/linchaolong/article/details/42321767#L144" rel="#L144" style="text-decoration: none; color: rgb(12,207);"> 144</a>
  145. <a target=_blank id="L145" href="http://blog.csdn.net/linchaolong/article/details/42321767#L145" rel="#L145" style="text-decoration: none; color: rgb(12,207);"> 145</a>
  146. <a target=_blank id="L146" href="http://blog.csdn.net/linchaolong/article/details/42321767#L146" rel="#L146" style="text-decoration: none; color: rgb(12,207);"> 146</a>
  147. <a target=_blank id="L147" href="http://blog.csdn.net/linchaolong/article/details/42321767#L147" rel="#L147" style="text-decoration: none; color: rgb(12,207);"> 147</a>
  148. <a target=_blank id="L148" href="http://blog.csdn.net/linchaolong/article/details/42321767#L148" rel="#L148" style="text-decoration: none; color: rgb(12,207);"> 148</a>
  149. <a target=_blank id="L149" href="http://blog.csdn.net/linchaolong/article/details/42321767#L149" rel="#L149" style="text-decoration: none; color: rgb(12,207);"> 149</a>
  150. <a target=_blank id="L150" href="http://blog.csdn.net/linchaolong/article/details/42321767#L150" rel="#L150" style="text-decoration: none; color: rgb(12,207);"> 150</a>
  151. <a target=_blank id="L151" href="http://blog.csdn.net/linchaolong/article/details/42321767#L151" rel="#L151" style="text-decoration: none; color: rgb(12,207);"> 151</a>
  152. <a target=_blank id="L152" href="http://blog.csdn.net/linchaolong/article/details/42321767#L152" rel="#L152" style="text-decoration: none; color: rgb(12,207);"> 152</a>
  153. <a target=_blank id="L153" href="http://blog.csdn.net/linchaolong/article/details/42321767#L153" rel="#L153" style="text-decoration: none; color: rgb(12,207);"> 153</a>
  154. <a target=_blank id="L154" href="http://blog.csdn.net/linchaolong/article/details/42321767#L154" rel="#L154" style="text-decoration: none; color: rgb(12,207);"> 154</a>
  155. <a target=_blank id="L155" href="http://blog.csdn.net/linchaolong/article/details/42321767#L155" rel="#L155" style="text-decoration: none; color: rgb(12,207);"> 155</a>
  156. <a target=_blank id="L156" href="http://blog.csdn.net/linchaolong/article/details/42321767#L156" rel="#L156" style="text-decoration: none; color: rgb(12,207);"> 156</a>
  157. <a target=_blank id="L157" href="http://blog.csdn.net/linchaolong/article/details/42321767#L157" rel="#L157" style="text-decoration: none; color: rgb(12,207);"> 157</a>
  158. <a target=_blank id="L158" href="http://blog.csdn.net/linchaolong/article/details/42321767#L158" rel="#L158" style="text-decoration: none; color: rgb(12,207);"> 158</a>
  159. <a target=_blank id="L159" href="http://blog.csdn.net/linchaolong/article/details/42321767#L159" rel="#L159" style="text-decoration: none; color: rgb(12,207);"> 159</a>
  160. <a target=_blank id="L160" href="http://blog.csdn.net/linchaolong/article/details/42321767#L160" rel="#L160" style="text-decoration: none; color: rgb(12,207);"> 160</a>
  161. <a target=_blank id="L161" href="http://blog.csdn.net/linchaolong/article/details/42321767#L161" rel="#L161" style="text-decoration: none; color: rgb(12,207);"> 161</a>
  162. <a target=_blank id="L162" href="http://blog.csdn.net/linchaolong/article/details/42321767#L162" rel="#L162" style="text-decoration: none; color: rgb(12,207);"> 162</a>
  163. <a target=_blank id="L163" href="http://blog.csdn.net/linchaolong/article/details/42321767#L163" rel="#L163" style="text-decoration: none; color: rgb(12,207);"> 163</a>
  164. <a target=_blank id="L164" href="http://blog.csdn.net/linchaolong/article/details/42321767#L164" rel="#L164" style="text-decoration: none; color: rgb(12,207);"> 164</a>
  165. <a target=_blank id="L165" href="http://blog.csdn.net/linchaolong/article/details/42321767#L165" rel="#L165" style="text-decoration: none; color: rgb(12,207);"> 165</a>
  166. <a target=_blank id="L166" href="http://blog.csdn.net/linchaolong/article/details/42321767#L166" rel="#L166" style="text-decoration: none; color: rgb(12,207);"> 166</a>
  167. <a target=_blank id="L167" href="http://blog.csdn.net/linchaolong/article/details/42321767#L167" rel="#L167" style="text-decoration: none; color: rgb(12,207);"> 167</a>
  168. <a target=_blank id="L168" href="http://blog.csdn.net/linchaolong/article/details/42321767#L168" rel="#L168" style="text-decoration: none; color: rgb(12,207);"> 168</a>
  169. <a target=_blank id="L169" href="http://blog.csdn.net/linchaolong/article/details/42321767#L169" rel="#L169" style="text-decoration: none; color: rgb(12,207);"> 169</a>
  170. <a target=_blank id="L170" href="http://blog.csdn.net/linchaolong/article/details/42321767#L170" rel="#L170" style="text-decoration: none; color: rgb(12,207);"> 170</a>
  171. <a target=_blank id="L171" href="http://blog.csdn.net/linchaolong/article/details/42321767#L171" rel="#L171" style="text-decoration: none; color: rgb(12,207);"> 171</a>
  172. <a target=_blank id="L172" href="http://blog.csdn.net/linchaolong/article/details/42321767#L172" rel="#L172" style="text-decoration: none; color: rgb(12,207);"> 172</a>
  173. <a target=_blank id="L173" href="http://blog.csdn.net/linchaolong/article/details/42321767#L173" rel="#L173" style="text-decoration: none; color: rgb(12,207);"> 173</a>
  174. <a target=_blank id="L174" href="http://blog.csdn.net/linchaolong/article/details/42321767#L174" rel="#L174" style="text-decoration: none; color: rgb(12,207);"> 174</a>
  175. <a target=_blank id="L175" href="http://blog.csdn.net/linchaolong/article/details/42321767#L175" rel="#L175" style="text-decoration: none; color: rgb(12,207);"> 175</a>
  176. <a target=_blank id="L176" href="http://blog.csdn.net/linchaolong/article/details/42321767#L176" rel="#L176" style="text-decoration: none; color: rgb(12,207);"> 176</a>
  177. <a target=_blank id="L177" href="http://blog.csdn.net/linchaolong/article/details/42321767#L177" rel="#L177" style="text-decoration: none; color: rgb(12,207);"> 177</a>
  178. <a target=_blank id="L178" href="http://blog.csdn.net/linchaolong/article/details/42321767#L178" rel="#L178" style="text-decoration: none; color: rgb(12,207);"> 178</a>
  179. <a target=_blank id="L179" href="http://blog.csdn.net/linchaolong/article/details/42321767#L179" rel="#L179" style="text-decoration: none; color: rgb(12,207);"> 179</a>
  180. <a target=_blank id="L180" href="http://blog.csdn.net/linchaolong/article/details/42321767#L180" rel="#L180" style="text-decoration: none; color: rgb(12,207);"> 180</a>
  181. <a target=_blank id="L181" href="http://blog.csdn.net/linchaolong/article/details/42321767#L181" rel="#L181" style="text-decoration: none; color: rgb(12,207);"> 181</a>
  182. <a target=_blank id="L182" href="http://blog.csdn.net/linchaolong/article/details/42321767#L182" rel="#L182" style="text-decoration: none; color: rgb(12,207);"> 182</a>
  183. <a target=_blank id="L183" href="http://blog.csdn.net/linchaolong/article/details/42321767#L183" rel="#L183" style="text-decoration: none; color: rgb(12,207);"> 183</a>
  184. <a target=_blank id="L184" href="http://blog.csdn.net/linchaolong/article/details/42321767#L184" rel="#L184" style="text-decoration: none; color: rgb(12,207);"> 184</a>
  185. <a target=_blank id="L185" href="http://blog.csdn.net/linchaolong/article/details/42321767#L185" rel="#L185" style="text-decoration: none; color: rgb(12,207);"> 185</a>
  186. <a target=_blank id="L186" href="http://blog.csdn.net/linchaolong/article/details/42321767#L186" rel="#L186" style="text-decoration: none; color: rgb(12,207);"> 186</a>
  1. #include "UpdateLayer.h"
  2. #include "HelloWorldScene.h"
  3. #if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
  4. #include <dirent.h>
  5. #include <sys/stat.h>
  6. #endif
  7. bool
  8. UpdateLayer
  9. ::
  10. init
  11. (){
  12. if
  13. (
  14. CCLayer
  15. ::
  16. init
  17. ())
  18. {
  19. // 设置资源包下载目录
  20. m_downloadDir
  21. =
  22. CCFileUtils
  23. ::
  24. sharedFileUtils
  25. ()
  26. ->
  27. getWritablePath
  28. ();
  29. m_downloadDir
  30. +=
  31. "download"
  32. ;
  33. // 设置代理
  34. getAssetsManager
  35. ()
  36. ->
  37. setDelegate
  38. (
  39. this
  40. );
  41. // 添加资源包下载路径到搜索路径,优先搜索更新的资源
  42. std
  43. ::
  44. vector
  45. <
  46. std
  47. ::
  48. string
  49. >
  50. searchPaths
  51. =
  52. CCFileUtils
  53. ::
  54. sharedFileUtils
  55. ()
  56. ->
  57. getSearchPaths
  58. ();
  59. searchPaths
  60. .
  61. insert
  62. (
  63. searchPaths
  64. .
  65. begin
  66. (),
  67. m_downloadDir
  68. );
  69. CCFileUtils
  70. ::
  71. sharedFileUtils
  72. ()
  73. ->
  74. setSearchPaths
  75. (
  76. searchPaths
  77. );
  78. // 提示
  79. m_label
  80. =
  81. CCLabelTTF
  82. ::
  83. create
  84. (
  85. ""
  86. ,
  87. "Arial"
  88. ,
  89. 18
  90. );
  91. m_label
  92. ->
  93. setAnchorPoint
  94. (
  95. ccp
  96. (
  97. 1
  98. ,
  99. 0.5
  100. ));
  101. m_label
  102. ->
  103. setPosition
  104. (
  105. ccp
  106. (
  107. 465
  108. ,
  109. 20
  110. ));
  111. addChild
  112. (
  113. m_label
  114. );
  115. // 菜单
  116. CCMenu
  117. *
  118. menu
  119. =
  120. CCMenu
  121. ::
  122. create
  123. ();
  124. menu
  125. ->
  126. setPosition
  127. (
  128. CCPointZero
  129. );
  130. addChild
  131. (
  132. menu
  133. );
  134. CCSize
  135. visibleSize
  136. =
  137. CCDirector
  138. ::
  139. sharedDirector
  140. ()
  141. ->
  142. getVisibleSize
  143. ();
  144. // 重置
  145. CCMenuItemFont
  146. *
  147. itemReset
  148. =
  149. CCMenuItemFont
  150. ::
  151. create
  152. (
  153. "reset"
  154. ,
  155. this
  156. ,
  157. menu_selector
  158. (
  159. UpdateLayer
  160. ::
  161. reset
  162. ));
  163. itemReset
  164. ->
  165. setPosition
  166. (
  167. ccp
  168. (
  169. visibleSize
  170. .
  171. width
  172. /
  173. 2
  174. ,153)">50
  175. ));
  176. menu
  177. ->
  178. addChild
  179. (
  180. itemReset
  181. );
  182. // 获取当前版本号
  183. CCMenuItemFont
  184. *
  185. itemGetClientVersion
  186. =
  187. CCMenuItemFont
  188. ::
  189. create
  190. (
  191. "getClientVersion"
  192. ,
  193. menu_selector
  194. (
  195. UpdateLayer
  196. ::
  197. getClientVersion
  198. ));
  199. itemGetClientVersion
  200. ->
  201. setPosition
  202. (
  203. ccp
  204. (
  205. visibleSize
  206. .
  207. width
  208. /
  209. 100
  210. ));
  211. menu
  212. ->
  213. addChild
  214. (
  215. itemGetClientVersion
  216. );
  217. // 获取服务器最新版本
  218. CCMenuItemFont
  219. *
  220. itemGetServerVersion
  221. =
  222. CCMenuItemFont
  223. ::
  224. create
  225. (
  226. "checkUpdate"
  227. ,
  228. menu_selector
  229. (
  230. UpdateLayer
  231. ::
  232. checkUpdate
  233. ));
  234. itemGetServerVersion
  235. ->
  236. setPosition
  237. (
  238. ccp
  239. (
  240. visibleSize
  241. .
  242. width
  243. /
  244. 150
  245. ));
  246. menu
  247. ->
  248. addChild
  249. (
  250. itemGetServerVersion
  251. );
  252. // 更新版本
  253. CCMenuItemFont
  254. *
  255. itemUpdateVersion
  256. =
  257. CCMenuItemFont
  258. ::
  259. create
  260. (
  261. "updateVersion"
  262. ,
  263. menu_selector
  264. (
  265. UpdateLayer
  266. ::
  267. update
  268. ));
  269. itemUpdateVersion
  270. ->
  271. setPosition
  272. (
  273. ccp
  274. (
  275. visibleSize
  276. .
  277. width
  278. /
  279. 200
  280. ));
  281. menu
  282. ->
  283. addChild
  284. (
  285. itemUpdateVersion
  286. );
  287. // 进入场景
  288. CCMenuItemFont
  289. *
  290. itemEnterScene
  291. =
  292. CCMenuItemFont
  293. ::
  294. create
  295. (
  296. "enterScene"
  297. ,
  298. menu_selector
  299. (
  300. UpdateLayer
  301. ::
  302. enterScene
  303. ));
  304. itemEnterScene
  305. ->
  306. setPosition
  307. (
  308. ccp
  309. (
  310. visibleSize
  311. .
  312. width
  313. /
  314. 250
  315. ));
  316. menu
  317. ->
  318. addChild
  319. (
  320. itemEnterScene
  321. );
  322. return
  323. true
  324. ;
  325. }
  326. false
  327. ;
  328. }
  329. AssetsManager
  330. *
  331. UpdateLayer
  332. ::
  333. getAssetsManager
  334. (){
  335. static
  336. AssetsManager
  337. *
  338. s_assetsManager
  339. =
  340. NULL
  341. ;
  342. if
  343. (
  344. s_assetsManager
  345. ==
  346. NULL
  347. )
  348. {
  349. s_assetsManager
  350. =
  351. new
  352. AssetsManager
  353. (
  354. "https://coding.net/u/linchaolong/p/Cocos2d-x_HotUpdate/git/raw/master/test.zip"
  355. ,
  356. //下载资源包的url
  357. "https://coding.net/u/linchaolong/p/Cocos2d-x_HotUpdate/git/raw/master/version"
  358. ,
  359. // 获取服务端版本号的url
  360. m_downloadDir
  361. .
  362. c_str
  363. ());
  364. // 资源保存路径
  365. s_assetsManager
  366. ->
  367. setDelegate
  368. (
  369. this
  370. );
  371. s_assetsManager
  372. ->
  373. setConnectionTimeout
  374. (
  375. 3
  376. );
  377. }
  378. CCLOG
  379. (
  380. "save path : %s"
  381. ,
  382. s_assetsManager
  383. ->
  384. getStoragePath
  385. ());
  386. return
  387. s_assetsManager
  388. ;
  389. }
  390. void
  391. UpdateLayer
  392. ::
  393. initDownloadDir
  394. (){
  395. // 如果下载目录不存在,则创建下载目录
  396. #if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
  397. DIR
  398. *
  399. pDir
  400. =
  401. NULL
  402. ;
  403. pDir
  404. =
  405. opendir
  406. (
  407. m_downloadDir
  408. .
  409. c_str
  410. ());
  411. if
  412. (
  413. !
  414. pDir
  415. )
  416. {
  417. mkdir
  418. (
  419. m_downloadDir
  420. .
  421. c_str
  422. (),
  423. S_IRWXU
  424. |
  425. S_IRWXG
  426. |
  427. S_IRWXO
  428. );
  429. }
  430. #else
  431. if
  432. ((
  433. GetFileAttributesA
  434. (
  435. m_downloadDir
  436. .
  437. c_str
  438. ()))
  439. ==
  440. INVALID_FILE_ATTRIBUTES
  441. )
  442. {
  443. CreateDirectoryA
  444. (
  445. m_downloadDir
  446. .
  447. c_str
  448. (),153)">0
  449. );
  450. }
  451. #endif
  452. }
  453. void
  454. UpdateLayer
  455. ::
  456. deleteDir
  457. (
  458. std
  459. ::
  460. string
  461. dir
  462. ){
  463. // Remove downloaded files
  464. #if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
  465. std
  466. ::
  467. string
  468. command
  469. =
  470. "rm -r "
  471. ;
  472. // Path may include space.
  473. command
  474. +=
  475. "
  476. \"
  477. "
  478. +
  479. dir
  480. +
  481. "
  482. ;
  483. system
  484. (
  485. command
  486. .
  487. c_str
  488. ());
  489. #else
  490. std
  491. ::
  492. string
  493. command
  494. =
  495. "rd /s /q "
  496. ;
  497. // Path may include space.
  498. command
  499. +=
  500. "
  501. ;
  502. system
  503. (
  504. command
  505. .
  506. c_str
  507. ());
  508. #endif
  509. }
  510. void
  511. UpdateLayer
  512. ::
  513. onError
  514. (
  515. cocos2d
  516. ::
  517. extension
  518. ::
  519. AssetsManager
  520. ::
  521. ErrorCode
  522. errorCode
  523. ){
  524. switch
  525. (
  526. errorCode
  527. )
  528. {
  529. case
  530. cocos2d:
  531. :
  532. extension
  533. ::
  534. AssetsManager
  535. ::
  536. kCreateFile
  537. :
  538. CCLOG
  539. (
  540. "error : create file failure"
  541. );
  542. m_label
  543. ->
  544. setString
  545. (
  546. "error : create file failure"
  547. );
  548. break
  549. ;
  550. case
  551. cocos2d:
  552. :
  553. extension
  554. ::
  555. AssetsManager
  556. ::
  557. kNetwork
  558. :
  559. CCLOG
  560. (
  561. "error : no network"
  562. );
  563. m_label
  564. ->
  565. setString
  566. (
  567. "error : no network"
  568. );
  569. break
  570. ;
  571. case
  572. cocos2d:
  573. :
  574. extension
  575. ::
  576. AssetsManager
  577. ::
  578. kNoNewVersion
  579. :
  580. CCLOG
  581. (
  582. "error : no new version"
  583. );
  584. m_label
  585. ->
  586. setString
  587. (
  588. "error : no new version"
  589. );
  590. break
  591. ;
  592. case
  593. cocos2d:
  594. :
  595. extension
  596. ::
  597. AssetsManager
  598. ::
  599. kUncompress
  600. :
  601. CCLOG
  602. (
  603. "error : uncompress file error"
  604. );
  605. m_label
  606. ->
  607. setString
  608. (
  609. "error : uncompress file error"
  610. );
  611. break
  612. ;
  613. default:
  614. break
  615. ;
  616. }
  617. }
  618. void
  619. UpdateLayer
  620. ::
  621. onProgress
  622. (
  623. int
  624. percent
  625. ){
  626. char
  627. progress
  628. [
  629. 80
  630. ];
  631. memset
  632. (
  633. progress
  634. ,
  635. '\0'
  636. ,
  637. sizeof
  638. (
  639. progress
  640. )
  641. );
  642. snprintf
  643. (
  644. progress
  645. ,0); font-weight:bold">sizeof
  646. (
  647. progress
  648. ),240)">"hotupdate downloading %d%%"
  649. ,
  650. percent
  651. );
  652. CCLOG
  653. (
  654. "percent=%d %s"
  655. ,
  656. percent
  657. ,
  658. progress
  659. );
  660. m_label
  661. ->
  662. setString
  663. (
  664. progress
  665. );
  666. }
  667. void
  668. UpdateLayer
  669. ::
  670. onSuccess
  671. (){
  672. CCLOG
  673. (
  674. "download success."
  675. );
  676. m_label
  677. ->
  678. setString
  679. (
  680. "download success."
  681. );
  682. }
  683. void
  684. UpdateLayer
  685. ::
  686. update
  687. (
  688. CCObject
  689. *
  690. pSender
  691. ){
  692. // 初始化下载目录
  693. initDownloadDir
  694. ();
  695. // 下载更新包
  696. getAssetsManager
  697. ()
  698. ->
  699. update
  700. ();
  701. }
  702. void
  703. UpdateLayer
  704. ::
  705. reset
  706. (
  707. CCObject
  708. *
  709. pSender
  710. ){
  711. if
  712. (
  713. ""
  714. !=
  715. m_downloadDir
  716. )
  717. {
  718. // 删除下载目录
  719. deleteDir
  720. (
  721. m_downloadDir
  722. );
  723. }
  724. // 删除版本号
  725. getAssetsManager
  726. ()
  727. ->
  728. deleteVersion
  729. ();
  730. }
  731. void
  732. UpdateLayer
  733. ::
  734. getClientVersion
  735. (
  736. CCObject
  737. *
  738. pSender
  739. ){
  740. CCString
  741. *
  742. msg
  743. =
  744. CCString
  745. ::
  746. createWithFormat
  747. (
  748. "current client version : %s"
  749. ,
  750. getAssetsManager
  751. ()
  752. ->
  753. getVersion
  754. ().
  755. c_str
  756. ());
  757. CCLOG
  758. (
  759. "%s"
  760. ,
  761. msg
  762. ->
  763. getCString
  764. ());
  765. m_label
  766. ->
  767. setString
  768. (
  769. msg
  770. ->
  771. getCString
  772. ());
  773. }
  774. void
  775. UpdateLayer
  776. ::
  777. checkUpdate
  778. (
  779. CCObject
  780. *
  781. pSender
  782. ){
  783. @H_956_2301@
  784. if
  785. (
  786. getAssetsManager
  787. ()
  788. ->
  789. checkUpdate
  790. ())
{
CCLOG ( "has new version" );
m_label -> setString ( "has new version" );
} else {
CCLOG ( "has not new version" );
m_label -> setString ( "has not new version" );
}
}
void UpdateLayer :: enterScene ( CCObject * pSender ){
CCDirector :: sharedDirector () -> replaceScene ( HelloWorld :: scene ());
}
来自CODE的代码片
UpdateLayer.cpp
<a target=_blank id="L1" href="http://blog.csdn.net/linchaolong/article/details/42321767#L1" rel="#L1" style="text-decoration: none; color: rgb(12,207);"> 1</a> <a target=_blank id="L2" href="http://blog.csdn.net/linchaolong/article/details/42321767#L2" rel="#L2" style="text-decoration: none; color: rgb(12,207);"> 2</a> <a target=_blank id="L3" href="http://blog.csdn.net/linchaolong/article/details/42321767#L3" rel="#L3" style="text-decoration: none; color: rgb(12,207);"> 3</a> <a target=_blank id="L4" href="http://blog.csdn.net/linchaolong/article/details/42321767#L4" rel="#L4" style="text-decoration: none; color: rgb(12,207);"> 4</a> <a target=_blank id="L5" href="http://blog.csdn.net/linchaolong/article/details/42321767#L5" rel="#L5" style="text-decoration: none; color: rgb(12,207);"> 5</a> <a target=_blank id="L6" href="http://blog.csdn.net/linchaolong/article/details/42321767#L6" rel="#L6" style="text-decoration: none; color: rgb(12,207);"> 6</a> <a target=_blank id="L7" href="http://blog.csdn.net/linchaolong/article/details/42321767#L7" rel="#L7" style="text-decoration: none; color: rgb(12,207);"> 7</a> <a target=_blank id="L8" href="http://blog.csdn.net/linchaolong/article/details/42321767#L8" rel="#L8" style="text-decoration: none; color: rgb(12,207);"> 8</a> <a target=_blank id="L9" href="http://blog.csdn.net/linchaolong/article/details/42321767#L9" rel="#L9" style="text-decoration: none; color: rgb(12,207);"> 9</a> <a target=_blank id="L10" href="http://blog.csdn.net/linchaolong/article/details/42321767#L10" rel="#L10" style="text-decoration: none; color: rgb(12,207);"> 10</a> <a target=_blank id="L11" href="http://blog.csdn.net/linchaolong/article/details/42321767#L11" rel="#L11" style="text-decoration: none; color: rgb(12,207);"> 11</a> <a target=_blank id="L12" href="http://blog.csdn.net/linchaolong/article/details/42321767#L12" rel="#L12" style="text-decoration: none; color: rgb(12,207);"> 12</a> <a target=_blank id="L13" href="http://blog.csdn.net/linchaolong/article/details/42321767#L13" rel="#L13" style="text-decoration: none; color: rgb(12,207);"> 13</a> <a target=_blank id="L14" href="http://blog.csdn.net/linchaolong/article/details/42321767#L14" rel="#L14" style="text-decoration: none; color: rgb(12,207);"> 14</a> <a target=_blank id="L15" href="http://blog.csdn.net/linchaolong/article/details/42321767#L15" rel="#L15" style="text-decoration: none; color: rgb(12,207);"> 15</a> <a target=_blank id="L16" href="http://blog.csdn.net/linchaolong/article/details/42321767#L16" rel="#L16" style="text-decoration: none; color: rgb(12,207);"> 16</a> <a target=_blank id="L17" href="http://blog.csdn.net/linchaolong/article/details/42321767#L17" rel="#L17" style="text-decoration: none; color: rgb(12,207);"> 17</a> <a target=_blank id="L18" href="http://blog.csdn.net/linchaolong/article/details/42321767#L18" rel="#L18" style="text-decoration: none; color: rgb(12,207);"> 18</a> <a target=_blank id="L19" href="http://blog.csdn.net/linchaolong/article/details/42321767#L19" rel="#L19" style="text-decoration: none; color: rgb(12,207);"> 19</a> <a target=_blank id="L20" href="http://blog.csdn.net/linchaolong/article/details/42321767#L20" rel="#L20" style="text-decoration: none; color: rgb(12,207);"> 20</a> <a target=_blank id="L21" href="http://blog.csdn.net/linchaolong/article/details/42321767#L21" rel="#L21" style="text-decoration: none; color: rgb(12,207);"> 21</a> <a target=_blank id="L22" href="http://blog.csdn.net/linchaolong/article/details/42321767#L22" rel="#L22" style="text-decoration: none; color: rgb(12,207);"> 22</a> <a target=_blank id="L23" href="http://blog.csdn.net/linchaolong/article/details/42321767#L23" rel="#L23" style="text-decoration: none; color: rgb(12,207);"> 23</a> <a target=_blank id="L24" href="http://blog.csdn.net/linchaolong/article/details/42321767#L24" rel="#L24" style="text-decoration: none; color: rgb(12,207);"> 24</a> <a target=_blank id="L25" href="http://blog.csdn.net/linchaolong/article/details/42321767#L25" rel="#L25" style="text-decoration: none; color: rgb(12,207);"> 25</a> <a target=_blank id="L26" href="http://blog.csdn.net/linchaolong/article/details/42321767#L26" rel="#L26" style="text-decoration: none; color: rgb(12,207);"> 26</a> <a target=_blank id="L27" href="http://blog.csdn.net/linchaolong/article/details/42321767#L27" rel="#L27" style="text-decoration: none; color: rgb(12,207);"> 27</a> <a target=_blank id="L28" href="http://blog.csdn.net/linchaolong/article/details/42321767#L28" rel="#L28" style="text-decoration: none; color: rgb(12,207);"> 28</a> <a target=_blank id="L29" href="http://blog.csdn.net/linchaolong/article/details/42321767#L29" rel="#L29" style="text-decoration: none; color: rgb(12,207);"> 29</a> <a target=_blank id="L30" href="http://blog.csdn.net/linchaolong/article/details/42321767#L30" rel="#L30" style="text-decoration: none; color: rgb(12,207);"> 30</a> <a target=_blank id="L31" href="http://blog.csdn.net/linchaolong/article/details/42321767#L31" rel="#L31" style="text-decoration: none; color: rgb(12,207);"> 31</a> <a target=_blank id="L32" href="http://blog.csdn.net/linchaolong/article/details/42321767#L32" rel="#L32" style="text-decoration: none; color: rgb(12,207);"> 32</a> <a target=_blank id="L33" href="http://blog.csdn.net/linchaolong/article/details/42321767#L33" rel="#L33" style="text-decoration: none; color: rgb(12,207);"> 33</a> <a target=_blank id="L34" href="http://blog.csdn.net/linchaolong/article/details/42321767#L34" rel="#L34" style="text-decoration: none; color: rgb(12,207);"> 34</a> <a target=_blank id="L35" href="http://blog.csdn.net/linchaolong/article/details/42321767#L35" rel="#L35" style="text-decoration: none; color: rgb(12,207);"> 35</a> <a target=_blank id="L36" href="http://blog.csdn.net/linchaolong/article/details/42321767#L36" rel="#L36" style="text-decoration: none; color: rgb(12,207);"> 36</a> <a target=_blank id="L37" href="http://blog.csdn.net/linchaolong/article/details/42321767#L37" rel="#L37" style="text-decoration: none; color: rgb(12,207);"> 37</a> <a target=_blank id="L38" href="http://blog.csdn.net/linchaolong/article/details/42321767#L38" rel="#L38" style="text-decoration: none; color: rgb(12,207);"> 38</a> <a target=_blank id="L39" href="http://blog.csdn.net/linchaolong/article/details/42321767#L39" rel="#L39" style="text-decoration: none; color: rgb(12,207);"> 39</a> <a target=_blank id="L40" href="http://blog.csdn.net/linchaolong/article/details/42321767#L40" rel="#L40" style="text-decoration: none; color: rgb(12,207);"> 40</a> <a target=_blank id="L41" href="http://blog.csdn.net/linchaolong/article/details/42321767#L41" rel="#L41" style="text-decoration: none; color: rgb(12,207);"> 41</a> <a target=_blank id="L42" href="http://blog.csdn.net/linchaolong/article/details/42321767#L42" rel="#L42" style="text-decoration: none; color: rgb(12,207);"> 42</a> <a target=_blank id="L43" href="http://blog.csdn.net/linchaolong/article/details/42321767#L43" rel="#L43" style="text-decoration: none; color: rgb(12,207);"> 43</a> <a target=_blank id="L44" href="http://blog.csdn.net/linchaolong/article/details/42321767#L44" rel="#L44" style="text-decoration: none; color: rgb(12,207);"> 44</a> <a target=_blank id="L45" href="http://blog.csdn.net/linchaolong/article/details/42321767#L45" rel="#L45" style="text-decoration: none; color: rgb(12,207);"> 45</a> <a target=_blank id="L46" href="http://blog.csdn.net/linchaolong/article/details/42321767#L46" rel="#L46" style="text-decoration: none; color: rgb(12,207);"> 46</a> <a target=_blank id="L47" href="http://blog.csdn.net/linchaolong/article/details/42321767#L47" rel="#L47" style="text-decoration: none; color: rgb(12,207);"> 47</a> <a target=_blank id="L48" href="http://blog.csdn.net/linchaolong/article/details/42321767#L48" rel="#L48" style="text-decoration: none; color: rgb(12,207);"> 48</a> <a target=_blank id="L49" href="http://blog.csdn.net/linchaolong/article/details/42321767#L49" rel="#L49" style="text-decoration: none; color: rgb(12,207);"> 49</a> <a target=_blank id="L50" href="http://blog.csdn.net/linchaolong/article/details/42321767#L50" rel="#L50" style="text-decoration: none; color: rgb(12,207);"> 50</a> <a target=_blank id="L51" href="http://blog.csdn.net/linchaolong/article/details/42321767#L51" rel="#L51" style="text-decoration: none; color: rgb(12,207);"> 51</a> <a target=_blank id="L52" href="http://blog.csdn.net/linchaolong/article/details/42321767#L52" rel="#L52" style="text-decoration: none; color: rgb(12,207);"> 52</a> <a target=_blank id="L53" href="http://blog.csdn.net/linchaolong/article/details/42321767#L53" rel="#L53" style="text-decoration: none; color: rgb(12,207);"> 53</a> <a target=_blank id="L54" href="http://blog.csdn.net/linchaolong/article/details/42321767#L54" rel="#L54" style="text-decoration: none; color: rgb(12,207);"> 54</a>
#ifndef __HOTUPDATER_H__
#define __HOTUPDATER_H__
#include "cocos2d.h"
USING_NS_CC ;
#include "cocos-ext.h"
USING_NS_CC_EXT ;
#include "AssetsManager/AssetsManager.h"
// 热更新实现示例
class UpdateLayer : public CCLayer ,0); font-weight:bold">public AssetsManagerDelegateProtocol
{
public:
static CCScene * scene (){
CCScene * scene = CCScene :: create ();
scene -> addChild ( UpdateLayer :: create ());
return scene ;
};
static UpdateLayer * create (){
UpdateLayer * pLayer = new UpdateLayer ;
if ( pLayer && pLayer -> init ())
{
pLayer -> autorelease ();
return pLayer ;
}
delete pLayer ;
NULL ;
};
// 初始化
bool init ();
// 下载回调函数
virtual void onError ( cocos2d :: extension :: AssetsManager :: ErrorCode errorCode );
onProgress ( int percent );
onSuccess ();
// 菜单回调函数
reset ( CCObject * pSender ); // 重置版本
getClientVersion ( CCObject * pSender ); // 获取当前客户端版本号
checkUpdate ( CCObject * pSender ); // 检查是否有版本更新
update ( CCObject * pSender ); // 更新版本
enterScene ( CCObject * pSender ); // 进入场景,如果未更新屏幕中间会显示叹号的图片,更新后会显示另一张图片
protected:
// 初始化下载目录
initDownloadDir ();
// 删除目录
deleteDir ( std :: string dir );
private:
CCLabelTTF * m_label ;
std :: string m_downloadDir ;
AssetsManager * getAssetsManager ();
};
#endif
来自CODE的代码片
UpdateLayer.h


项目地址:https://coding.net/u/linchaolong/p/Cocos2d-x_HotUpdate/git

猜你在找的Cocos2d-x相关文章