HotUpdate.js.map
23.1 KB
{"version":3,"sources":["assets/script/game/HotUpdate.js"],"names":["EventCenter","require","g_check","cc","Class","Component","properties","_searchPath","manifestUrl","type","Asset","_checkUpdate","_checkUpdateNum","_updating","_isForceUpdate","_loadFiles","byteProgress","ProgressBar","fileProgress","info","Label","fileLabel","byteLabel","forceUpdate","Layout","ensureBut","Button","_forceHotUpdate","start","sys","isNative","startGame","hotUpdateInit","hotUpdateLogic","delay","delayTime","finishedAll","callFunc","overTimeStartGame","node","runAction","sequence","checkCb","event","getEventCode","jsb","EventAssetsManager","ERROR_NO_LOCAL_MANIFEST","showUpDateInfo","ERROR_DOWNLOAD_MANIFEST","ERROR_PARSE_MANIFEST","ALREADY_UP_TO_DATE","NEW_VERSION_FOUND","checkUpdate","hotUpdate","active","log","GameStart","emit","self","on","ensureButCallBack","director","end","initAssetsManager","forceUpdateLogic","fileUtils","getWritablePath","versionCompareHandle","versionA","versionB","vA","split","vB","length","parseInt","localStorage","getItem","i","a","b","setItem","_am","AssetsManager","setVerifyCallback","path","asset","compressed","expectedMD5","md5","relativePath","size","os","OS_ANDROID","setMaxConcurrentTask","setEventCallback","bind","getState","State","UNINITED","url","nativeUrl","loader","md5Pipe","transformURL","loadLocalManifest","updateCb","update","needRestart","failed","UPDATE_PROGRESSION","progress","getPercent","getPercentByFile","string","getDownloadedFiles","getTotalFiles","getDownloadedBytes","getTotalBytes","msg","getMessage","UPDATE_FINISHED","UPDATE_FAILED","ERROR_UPDATING","getAssetId","ERROR_DECOMPRESS","restartGame","onDestroy","searchPaths","getSearchPaths","newPaths","getLocalManifest","Array","prototype","unshift","JSON","stringify","setSearchPaths","audioEngine","stopAll","game","restart","strInfo"],"mappings":";;;;;;AAAA;AACA,IAAKA,WAAW,GAAGC,OAAO,CAAC,aAAD,CAA1B;;AACA,IAAIC,OAAO,GAAG,KAAd;AACAC,EAAE,CAACC,KAAH,CAAS;AACL,aAASD,EAAE,CAACE,SADP;AAGLC,EAAAA,UAAU,EAAE;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/H,IAAAA,EAAE,CAAC0B,GAAH,CAAO+C,YAAP,CAAoBK,OAApB,CAA4B,sBAA5B,EAAoDsD,IAAI,CAACC,SAAL,CAAeR,WAAf,CAApD;AACA7H,IAAAA,EAAE,CAAC0B,GAAH,CAAO+C,YAAP,CAAoBK,OAApB,CAA4B,iBAA5B,EAA+C,KAAKtD,eAApD;AACAkB,IAAAA,GAAG,CAACqB,SAAJ,CAAcuE,cAAd,CAA6BT,WAA7B;AACA7H,IAAAA,EAAE,CAACuI,WAAH,CAAeC,OAAf;AACAxI,IAAAA,EAAE,CAACyI,IAAH,CAAQC,OAAR;AACH,GAxTI;AAyTL;AACA7F,EAAAA,cAAc,EAAE,wBAAU8F,OAAV,EAAmB;AAC/B,SAAK3H,IAAL,CAAU+F,MAAV,GAAmB4B,OAAnB;AACH;AA5TI,CAAT","sourceRoot":"/","sourcesContent":["// var md5 = require(\"md5\")\nlet EventCenter = require(\"EventCenter\")\nvar g_check = false;\ncc.Class({\n extends: cc.Component,\n\n properties: {\n _searchPath: \"\",//搜索路径\n manifestUrl: {\n type: cc.Asset, // use 'type:' to declare an object reference\n default: null, // object's default value is null\n },\n\n _checkUpdate: false,\n _checkUpdateNum: 5,//检查更新次数\n _updating: false,//正在检查更新或者更新中\n _isForceUpdate: false,\n\n _loadFiles: \"yybs-remote-asset\",\n\n byteProgress: cc.ProgressBar,//字节进度\n fileProgress: cc.ProgressBar,//文件进度\n info: cc.Label,//信息显示\n fileLabel: cc.Label,//文件个数\n byteLabel: cc.Label,//字节个数\n\n // retryBtn: cc.Button,//重置按钮\n // checkBtn: cc.Button,//检查更新按钮 目前是自动得\n // updateBtn: cc.Button,//更新按钮 目前是自动的\n\n forceUpdate: cc.Layout,//强更界面\n ensureBut: cc.Button,//确定按钮\n _forceHotUpdate: \"\",\n },\n start() {\n // if (CC_DEBUG) {//发布debug模式apk跳过热更\n\n // this.startGame();//隐藏当前ui//多场景时 这直接加载下一个场景\n // }\n if (!cc.sys.isNative)//web//跳过热更 \n {\n this.startGame();//隐藏当前ui//多场景时 这直接加载下一个场景\n }\n else {\n this.hotUpdateInit();\n this.hotUpdateLogic();//热更逻辑\n var delay = cc.delayTime(10);\n var finishedAll = cc.callFunc(this.overTimeStartGame, this);\n this.node.runAction(cc.sequence(delay, finishedAll));\n }\n },\n\n checkCb: function (event) {\n this._checkUpdate = false;//检测更新完毕\n this._updating = false;//更新中\n switch (event.getEventCode()) {\n case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:\n this.showUpDateInfo('检查更新失败');\n g_check = true;\n break;\n case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:\n case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST:\n this.showUpDateInfo('检查更新失败');\n g_check = true;\n break;\n case jsb.EventAssetsManager.ALREADY_UP_TO_DATE:\n this.showUpDateInfo('已是最新版本');\n if (this._isForceUpdate == false) {\n this.startGame();\n return;\n }\n break;\n case jsb.EventAssetsManager.NEW_VERSION_FOUND:\n this.showUpDateInfo('发现新版本,正在更新...');\n g_check = false;\n break;\n default:\n return;\n }\n if (g_check == true) {\n this.checkUpdate();\n }\n else {\n this.hotUpdate();\n }\n\n },\n\n overTimeStartGame: function () {\n if (this.node.active == true && this._checkUpdate == true) {\n this.startGame();\n }\n },\n startGame: function ()//开始游戏\n {\n this.node.active = false;\n cc.log(\"开始游戏\");\n EventCenter.EventCenter.GameStart.emit();\n },\n hotUpdateInit: function () {\n\n var self = this;\n this.ensureBut.node.on('click', function (event) {\n self.ensureButCallBack();\n }, this);\n },\n ensureButCallBack: function ()//确定按钮回掉\n {\n // cc.sys.openURL('http://formal.share.idj66nm.com/down/link?gameId=200001&gameState=1');//强更下载地址\n cc.director.end();\n },\n hotUpdateLogic: function ()//热更逻辑\n {\n this.initAssetsManager();\n this.checkUpdate();\n },\n forceUpdateLogic: function ()//强更逻辑\n {\n this._isForceUpdate = true;\n this.forceUpdate.node.active = true;\n },\n initAssetsManager: function ()//初始化\n {\n this._searchPath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/') + this._loadFiles);//获取热更时得搜索路径\n cc.log('hotUpdate searchPath =' + this._searchPath);\n var self = this;\n var versionCompareHandle = function (versionA, versionB) //版本对比函数(检查本地mainfest和远端mainfes时,如果返回值大于0 会自动更新)\n {\n cc.log(\"JS Custom Version Compare: version A is \" + versionA + ', version B is ' + versionB);\n var vA = versionA.split('.');\n var vB = versionB.split('.');\n if (vA.length != vB.length || vA.length < 3)\n return 0;\n if ((parseInt(vA[0]) != parseInt(vB[0])))//前两位控制大版本更新\n {\n //强制更新\n self.forceUpdateLogic();\n return 0;\n }\n self._forceHotUpdate = vA[0] + \"\" + vA[1];\n var forceUpdate = cc.sys.localStorage.getItem('forceupdateyybs');\n cc.log(\"initAssetsManager forceupdate \" + forceUpdate);\n self._forceHotUpdate = vB[0] + \"\" + vB[1];\n for (var i = 0; i < vA.length; ++i) {\n var a = parseInt(vA[i]);\n var b = parseInt(vB[i] || 0);\n if (a === b) {\n continue;\n }\n return -1;\n }\n if (vB.length > vA.length) {\n return -1;\n }\n cc.sys.localStorage.setItem('forceupdateyybs', self._forceHotUpdate);\n return 0;\n };\n this._am = new jsb.AssetsManager(this.manifestUrl, this._searchPath, versionCompareHandle);//初始化 创建 AssetsManager\n // if (!cc.sys.ENABLE_GC_FOR_NATIVE_OBJECTS)\n // {\n // this._am.retain();\n // }\n //用户文件校验接口 由于下载过程中仍然有小概率可能由于网络原因或其他网络库的问题导致下载的文件内容有问题,\n //在文件下载完成后热更新管理器会调用这个接口,如果返回 true 表示文件正常,返回 false 表示文件有问题\n this._am.setVerifyCallback(function (path, asset) {\n var compressed = asset.compressed;// 是压缩文件 不需要检查它的md5\n var expectedMD5 = asset.md5;//检索md5值。\n var relativePath = asset.path;// asset.path 是相对路径 path 绝对路径.\n var size = asset.size;//文件的大小,但是这个值可能不存在\n if (compressed) {\n return true;\n }\n else {\n return true;\n // //使用绝对路径来加载文件,之后计算md5值\n // var data = jsb.fileUtils.getDataFromFile(path);\n // var curMD5 = md5(data);\n // if (curMD5 == asset.md5) {\n // //md5检验通过\n // return true;\n // } else {\n // //md5检验失败\n // //this.info.string = relativePath + \"文件MD5校验失败\";\n // cc.log(\"md5检验失败\");\n // return false;\n // }\n }\n });\n if (cc.sys.os === cc.sys.OS_ANDROID) {//控制下载并发数量的 API 有些Android设备可能会在并发任务太多时减慢下载速度。设置适合游戏的值。\n this._am.setMaxConcurrentTask(2);\n }\n },\n\n\n\n checkUpdate: function ()//检查更新\n {\n this._checkUpdateNum = this._checkUpdateNum - 1;\n if (this._checkUpdateNum <= 0) {\n //直接登陆\n this.startGame();\n return;\n }\n if (this._updating) {\n this.showUpDateInfo('正在检测或者更新中,请耐心等待...');\n return;\n }\n this._am.setEventCallback(this.checkCb.bind(this));\n\n if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {\n var url = this.manifestUrl.nativeUrl;\n if (cc.loader.md5Pipe) {\n url = cc.loader.md5Pipe.transformURL(url);\n }\n cc.log('加载本地Manifest', url);\n this._am.loadLocalManifest(url);\n }\n this._am.checkUpdate();\n this._checkUpdate = true;//正在检测更新\n this.showUpDateInfo('正在检测更新,请耐心等待...');\n },\n\n\n hotUpdate: function () {\n if (this._am == null) {\n return;\n }\n\n this._am.setEventCallback(this.updateCb.bind(this));\n\n if (this._am.getState() === jsb.AssetsManager.State.UNINITED) {\n this._am.loadLocalManifest(this.manifestUrl);\n }\n this._am.update();\n this._updating = true;\n },\n updateCb: function (event) {\n var needRestart = false;\n var failed = false;\n switch (event.getEventCode()) {\n case jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST:\n cc.log('错误:没找到本地manifest文件');\n failed = true;\n break;\n case jsb.EventAssetsManager.UPDATE_PROGRESSION://更新进度\n this.byteProgress.progress = event.getPercent();\n this.fileProgress.progress = event.getPercentByFile();\n this.fileLabel.node.active = true;\n this.fileLabel.string = event.getDownloadedFiles() + ' / ' + event.getTotalFiles();\n this.byteLabel.string = event.getDownloadedBytes() / 1024 + ' / ' + event.getTotalBytes() / 1024;\n var msg = event.getMessage();\n if (msg) {\n // cc.log(event.getPercent()/100 + '% : ' + msg);\n }\n break;\n case jsb.EventAssetsManager.ERROR_DOWNLOAD_MANIFEST:\n case jsb.EventAssetsManager.ERROR_PARSE_MANIFEST:\n cc.log('错误:下载或解析MANIFEST文件失败');\n failed = true;\n break;\n case jsb.EventAssetsManager.ALREADY_UP_TO_DATE:\n this.showUpDateInfo('与服务器版本一致');\n if (this._isForceUpdate == false)\n this.startGame();\n break;\n case jsb.EventAssetsManager.UPDATE_FINISHED:\n this.showUpDateInfo('更新完成');\n this._updating = false;\n needRestart = true;\n break;\n case jsb.EventAssetsManager.UPDATE_FAILED://更新失败\n this._updating = false;\n failed = true;\n break;\n case jsb.EventAssetsManager.ERROR_UPDATING:\n if (event.getMessage()) {\n this.info.string = '更新' + event.getAssetId() + '时发生错误.' + event.getMessage();\n } else {\n this.info.string = '更新' + event.getAssetId() + '时发生错误';\n }\n needRestart = true;\n break;\n case jsb.EventAssetsManager.ERROR_DECOMPRESS:\n this.showUpDateInfo('解压发生错误.' + event.getMessage());\n break;\n default:\n break;\n }\n if (needRestart) {\n this.restartGame();\n return;\n }\n if (failed) {\n\n this._updating = false;\n this.checkUpdate();\n }\n },\n onDestroy: function () {\n if (this._am)\n this._am.setEventCallback(null);\n },\n restartGame: function ()//重启游戏\n {\n\n this.fileProgress.progress = 1;\n this.byteProgress.progress = 1\n var searchPaths = jsb.fileUtils.getSearchPaths();\n var newPaths = this._am.getLocalManifest().getSearchPaths();\n Array.prototype.unshift(searchPaths, newPaths);\n cc.sys.localStorage.setItem('HotUpdateSearchPaths', JSON.stringify(searchPaths));\n cc.sys.localStorage.setItem('forceupdateyybs', this._forceHotUpdate);\n jsb.fileUtils.setSearchPaths(searchPaths);\n cc.audioEngine.stopAll();\n cc.game.restart();\n },\n //显示更新信息\n showUpDateInfo: function (strInfo) {\n this.info.string = strInfo;\n }\n});\n\n"]}