123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- let AppFlyerUtil = require("AppFlyerUtil");
- let WebAPIMd5 = require("WebAPIMd5");
- cc.Class({
- extends: cc.Component,
- properties: {
- loadingBg: cc.Node,
- loadingSprite: cc.Node,
- label1: cc.Node,
- label2: cc.Node,
- },
- // start() {
- // AppFlyerUtil.init();
- // this.getLoginAddress();
- // jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "clearWelcomeImage", "()V");
- // },
- // checkLoadingSceneBool() {
- // if (Troy_ReviewApk == "0" || cc.Troy.ReviewApk == false) {
- // cc.Troy.ReviewApk = false;
- // this.initApkPack();
- // } else if (window.loadingSceneBool != null) {
- // cc.Troy.ReviewApk = !window.loadingSceneBool;
- // this.initApkPack();
- // } else {
- // setTimeout(() => {
- // this.checkLoadingSceneBool();
- // }, 1000);
- // }
- //
- // },
- start() {
-
- },
- doSth(){
- console.log("HotLoad=========>"+1);
- if (cc.sys.os == cc.sys.OS_ANDROID && cc.sys.isNative) {
- console.log("HotLoad=========>"+2);
- // if (fsUtils && fsUtils.initJsbDownloader)
- // fsUtils.initJsbDownloader();
- // this.packageName = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/Native", "getAppId", "()Ljava/lang/String;");
- // this.appPackName = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "getAppId", "()Ljava/lang/String;");
- // this.initApkPack();
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity",
- "initConfigLoader",
- "()V",
- );
- setTimeout(()=>{
- this.initApkPack1();
- }, 1000)
- // this.initApkPack();
- return;
- }
- },
- buttonTest() {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "googleReferrer", "()V");
- },
- getLoginAddress() {
- // let appPackName = "com.brazil.xfnb";
- // let URL = "http://web-cb1d5017dd23866d.elb.sa-east-1.amazonaws.com/api/login_ip_map?" + "PackageName=" + appPackName;
- // URL = WebAPIMd5(URL);
- // let xhr = new XMLHttpRequest();
- // xhr.timeout = 8000;
- // xhr.ontimeout = () => { this.getLoginAddress(); }
- // xhr.open("GET", URL);
- // xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- // xhr.onreadystatechange = () => {
- // if (xhr.readyState !== 4) { return; }
- // if (xhr.status === 200) {
- // let json = JSON.parse(xhr.responseText);
- // cc.log(json);
- // this.LoginIndex = 0;
- // this.LoginAddress = json.data;
- // this.LoginWebSocket();
- // }
- // };
- // xhr.send();
- },
- LoginWebSocket() {
- // let data = this.LoginAddress[this.LoginIndex]
- // let url = "ws://" + data.LoginAddr + ":" + data.LoginPort;
- // let ws = new WebSocket(url);
- // ws.onopen = (event) => {
- // cc.log("onopen", event);
- // this.makeGetVerinfoReq();
- // this.sendCMD(1, 13);
- // };
- // ws.onmessage = (event) => {
- // cc.log("onmessage", event);
- // };
- // ws.onclose = (event) => {
- // cc.log("onclose", event);
- // };
- // ws.onerror = (event) => {
- // cc.log("onerror", event);
- // };
- // ws.ontimeout = (event) => {
- // cc.log("ontimeout", event);
- // };
- },
- // makeGetVerinfoReq() {
- // let VersionInfo = {};
- // VersionInfo.UserID = 0;
- // VersionInfo.Channel
- // },
- // sendCMD(main, sub, dv = new DataView(new ArrayBuffer(8))) {
- // dv.pos = 0;
- // Global.SetUint8(dv, 2);
- // Global.SetUint8(dv, 0);
- // Global.SetUint16(dv, dv.byteLength);
- // Global.SetUint16(dv, main);
- // Global.SetUint16(dv, sub);
- // Global.print("SendSocketData main:" + main + " sub:" + sub);
- // return this.mSocketEngine.send(dv.buffer);
- // },
- initApkPack1(){
- window.unZipNextGo = (taskID) => { this.unZipNextGo(); }
- // this.checkReviewApk();
- this.passWord = "52%^##11%";
- this.localPath = "gameJsonData.bin";
- this.inputString = "gameJsonData/gameJsonData.bin";
- this.outputString = "/blackjack-remote-asset";
- this.downloadPath = "gameJsonData.bin";
- let bool1 = this.checkHasTargetZip();
- if (bool1) {
- this.unZipLocal();
- } else {
- let bool2 = jsb.fileUtils.isFileExist(jsb.fileUtils.getWritablePath() + this.inputString);
- if (bool2) {
- this.unZipDownload();
- } else {
- this.downloadZip();
- }
- }
- },
- initApkPack() {
- console.log("HotLoad=========>"+3);
- this.initGlobalFunc();
- this.checkReviewApk();
- let bool1 = this.checkHasTargetZip();
- if (bool1) {
- console.log("HotLoad=========>"+3.1);
- this.unZipLocal();
- } else {
- console.log("HotLoad=========>"+3.2);
- let bool2 = jsb.fileUtils.isFileExist(jsb.fileUtils.getWritablePath() + this.inputString);
- if (bool2) {
- this.unZipDownload();
- } else {
- this.downloadZip();
- }
- }
- },
- initGlobalFunc() {
- window.unZipNextGo = () => { this.unZipNextGo(); }
- this.loadSprite = this.loadingSprite.getComponent(cc.Sprite);
- },
- checkReviewApk() {
- if (cc.Troy.ReviewApk) {
- this.passWord = cc.Troy.APack_PassWord;
- this.localPath = cc.Troy.APack_LocalPath;
- this.inputString = cc.Troy.APack_IutPutString;
- this.outputString = cc.Troy.APack_OutPutString;
- this.downloadPath = cc.Troy.APack_DownloadPath;
- } else {
- this.passWord = cc.Troy.BPack_PassWord;
- this.localPath = cc.Troy.BPack_LocalPath;
- this.inputString = cc.Troy.BPack_IutPutString;
- this.outputString = cc.Troy.BPack_OutPutString;
- this.downloadPath = cc.Troy.BPack_DownloadPath;
- }
- },
- checkHasTargetZip() {
- let bool = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity",
- "checkHasZip",
- "(Ljava/lang/String;)Z",
- this.localPath
- );
- return bool;
- },
- unZipDownload() {
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity",
- "unZipPack1",
- "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
- this.inputString,
- this.outputString,
- this.passWord,
- );
- },
- unZipLocal() {
- console.log("HotLoad=========>"+4);
- jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity",
- "unZipPack0",
- "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
- this.localPath,
- this.outputString,
- this.passWord,
- );
- },
- // unZipLocal() {
- // console.log("HotLoad=========>"+4);
- // jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity",
- // "unZipPack2",
- // "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
- // this.localPath,
- // this.outputString,
- // this.passWord,
- // );
- // },
- downloadZip() {
- let index = 0;
- let arr = ["Look before you leap", "The best is the enemy of the good", "When one door shuts anther opens"];
- this.loadingBg.active = true;
- this.loadingSprite.active = true;
- this.label1.active = true;
- this.label2.active = true;
- let func = () => {
- this.label2.getComponent(cc.Label).string = arr[index];
- index += 1;
- index = index > 2 ? 0 : index;
- }
- func();
- this.schedule(func, 5, 99999);
- let url = cc.Troy.DownloadPath + this.downloadPath;
- cc.log(url);
- cc.assetManager.loadRemote(url, {
- ext: ".bin",
- onFileProgress: (current, total) => {
- this.current = current;
- this.total = total;
- this.loadSprite.fillRange = this.current / this.total;
- }
- }, (err, bufferAsset) => {
- this.loadingBg.active = false;
- this.loadingSprite.active = false;
- this.label1.active = false;
- this.label2.active = false;
- let data = bufferAsset._buffer;
- let dirpath = jsb.fileUtils.getWritablePath() + 'zips/';
- let filepath = dirpath + this.inputString.split("zips/")[1];
- if (!jsb.fileUtils.isDirectoryExist(dirpath)) {
- jsb.fileUtils.createDirectory(dirpath);
- } if (jsb.fileUtils.writeDataToFile(new Uint8Array(data), filepath)) {
- this.unZipDownload();
- }
- })
- },
- unZipNextGo() {
- console.log("HotLoad=========>"+5);
- let path = [
- jsb.fileUtils.getWritablePath() + "blackjack-remote-asset/",
- ]
- jsb.fileUtils.setSearchPaths(path);
- cc.sys.localStorage.setItem('HotUpdateSearchPaths', JSON.stringify(path));
- // setTimeout(()=>{
- // cc.game.restart();
- // },3000)
- cc.audioEngine.stopAll();
- //延迟0.5秒重启
- setTimeout(()=>{
- cc.game.restart();
- }, 500)
- },
- });
|