Hot update mechanism under cocos2d-js

Hot update mechanism under cocos2d-js

First introduce project.manifest: For example

{
"packageUrl" : "http://192.168.1.108/games/dragon_gold",
"remoteManifestUrl" : "http://192.168.1.108/games/dragon_gold/project.manifest",
"remoteVersionUrl" : "http://192.168.1.108/games/dragon_gold/version.manifest",
"version" : "1.0.2",
"groupVersions" : {
        "1" : "1.0.1",
"2" : "1.0.2"
    },
"engineVersion" : "3.6",
"assets" : {
        "update1" : {
            "path" : "dragon_gold1.zip",
            "md5" : "140caaa2a4508912424e807a941bf71",
            "compressed" : true,
            "group" : "1"
        },

"update2" : {
            "path" : "dragon_gold2.zip",
            "md5" : "140caaa2a4508912424e807a941bf7bc",
            "compressed" : true,
            "group" : "2"
        }
 
    },
   
  "searchPaths" : [
   
     ]

   }


  • packageUrl : The download root path of the remote resource. (It is for " dragon_gold1.zip ", without this root path we can't find the package to download)
  • remoteVersionUrl : The path of the remote version file, used to determine whether there is a new version of the resource on the server side.
  • remoteManifestUrl : The path of the remote configuration file, including version information and all resource information.
  • version : The version corresponding to the configuration file. (This is used to determine whether there is a new update package)
  • assets : This is more important: the value inside corresponds to the package to be updated, where path is the package name of the updated package, and md5: used to compare the md5 code of the corresponding package in the manifest file downloaded this time and the last downloaded manifest file in the next update. compressed is used to determine whether the downloaded package needs to be decompressed. group is the most important, it is used to achieve incremental and new, and its value corresponds to groupVersions .
举个例子:有这么两个用户,第一个用户下载app之后一直没玩,第二个用户一直在玩每次有更新时第二个用户都会跟着更新,现在第二个用户当前的version为1.0.1时,他会去更新update2这个包,但是第一个用户一直没玩所以他的更新包version是1.0.0,这时他需要去更新update1和update2这两个包, 这就是一个简单的实现增量更新的例子。
(备注:当时用2.x版本引擎没提供这个功能,自己做了个增量更新功能坑了一段时间,现在引擎已经提供这个功能方便多了)。

我一直再讲project.manifest这个文件却没有说version.manifest,它其实是个简化版 的project.manifest,当我们版本已经有了几十个甚至几百个更新包时,显然下载project.manifest来判断是否有无更新是不明智的(因为更新包越多project.manifest体积变得越大,对于手机这么贵的流量下载这么大的东西是不划算的),因此此时的version.manifest用处就明显了,无论project.manifest体积多大,它永远只需要这么几行代码就可以了:

{
"packageUrl" : "http://192.168.1.108/games/dragon_gold",
"remoteManifestUrl" : "http://192.168.1.108/games/dragon_gold/project.manifest",
"remoteVersionUrl" : "http://192.168.1.108/games/dragon_gold/version.manifest",
"version" : "1.0.2",
"groupVersions" : {
        "1" : "1.0.1",
"2" : "1.0.2"
...
    }
}

Guess you like

Origin blog.csdn.net/wwlchuangye/article/details/78215806