1.4.0 自定义本地 manifest文件 已实现 感谢panda大大

  • Creator 版本号:1.4.0
    因为要检测子游戏的更新,所以本地子游戏的manifest文件肯定要按文件夹放置,虽然不大,但是如果子游戏多了,那不是要很多个文件夹。 所以想通过代码生成本地默认的manifest文件。代码如下:
 this._storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/')+"asset/"+wKindID);

var UIRLFILE = s_Path_Url+wKindID;
var filees = this._storagePath+"/project.manifest";
this.manifestUrl = filees;
 var customManifestStr = JSON.stringify(
 {
    "packageUrl": UIRLFILE,
     "remoteManifestUrl": UIRLFILE+"/project.manifest",
     "remoteVersionUrl" : UIRLFILE+"/version.manifest",
      "version": szFirstVersion,
      "assets": {},
       "searchPaths": []
});

var versionCompareHandle = function (versionA, versionB) 
        {
            var vA = versionA.split('.');
            var vB = versionB.split('.');
            for (var i = 0; i < vA.length; ++i) 
            {
                var a = parseInt(vA[i]);
                var b = parseInt(vB[i] || 0);
                if (a === b) 
                {
                    continue;
                }
                else 
                {
                    return a - b;
                }
            }
            if (vB.length > vA.length)
            {
                return -1;
            }
            else 
            {
                return 0;
            }
        };

        this._am = new jsb.AssetsManager('', this._storagePath,  versionCompareHandle);

        if (!cc.sys.ENABLE_GC_FOR_NATIVE_OBJECTS) 
        {
            this._am.retain();
        }

        if (cc.sys.os === cc.sys.OS_ANDROID) 
        {
            this._am.setMaxConcurrentTask(2);
        }

        if (this._am.getState() === jsb.EventAssetsManager.ERROR_NO_LOCAL_MANIFEST)
        {
           
            var bExist = jsb.fileUtils.isFileExist(filees);
            if( bExist )
            {
                this._am.loadLocalManifest(this.manifestUrl);
            }
            else
            {   
                var manifest = new jsb.Manifest(customManifestStr); //这里开始出错了 new失败了。
                this._am.loadLocalManifest( manifest );
            }
        }

大周末的 有大佬逛论坛没 求助啊!

1赞

周一了。。跪求大佬解决问题。人工置顶!

你也没贴错误 log 啊,什么错误都不知道怎么定位?

手机上没有错误输出 。。。 我用弹框弹得 ,new jsb.Manifest()这没有成功;

换过了一种方式 。

    //******************************** 代码设置本地manifest文件******************************************
    let UIRLFILE = s_Path_Url+wKindID;
    let customManifestStr = 
    {
        "packageUrl": UIRLFILE,
        "remoteManifestUrl": UIRLFILE+"/project.manifest",
        "remoteVersionUrl" : UIRLFILE+"/version.manifest",
        "version": szFirstVersion,
        "assets": {},
        "searchPaths": []
    }; //JSON.stringify(
    let storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/')+"asset/"+wKindID);
    let filees = storagePath+"/project.manifest";
    let bExist = jsb.fileUtils.isFileExist(filees);
    if(!bExist) 
    {    
        if( !jsb.fileUtils.isDirectoryExist(storagePath))
        {   
            jsb.fileUtils.createDirectory(storagePath);
        }
        var bWrite = jsb.fileUtils.writeDataToFile(customManifestStr, storagePath);   // 这里提示传入的参数错误
        if(bWrite)
            ManagerHelp_SetSystemAlert("生成成功");
    }

    this.manifestUrl = filees;
    this._am = new jsb.AssetsManager(this.manifestUrl, storagePath);

    if (!cc.sys.ENABLE_GC_FOR_NATIVE_OBJECTS) 
    {
        this._am.retain();
    }
    if (cc.sys.os === cc.sys.OS_ANDROID) 
    {
        this._am.setMaxConcurrentTask(2);
    }
    this._needUpdate = false

错误log : 07-17 19:33:48.118: E/cocos js error:(28379): E:\creator\Developer2017\Creator_1\XZMJ_Develop\build\jsb-link\src\project.js line:10 msg:Error: js_cocos2dx_CCFileUtils_writeDataToFile : Error processing arguments

函数我换成 writeStringToFile( ) 也提示传入的参数有误。 请问该传怎么样的参数?

JSON.stringify(customManifestStr)

用这种方式也可以:
var manifest = new jsb.Manifest(customManifestStr, this._storagePath);
this._am.loadLocalManifest(manifest, this._storagePath);

这个customManifestStr变量在初始化的时候我就加了 JSON.stringfy() 了, 用这个方法没有成功能 在new的时候失败的了

应该都是 API 使用的问题,下面是 Manifest 的 constructor 定义

Manifest(const std::string& content, const std::string& manifestRoot);

所以你用 new jsb.Manifest(customManifestStr); 缺少第二个参数。而 jsb.fileUtils.writeDataToFile(customManifestStr, storagePath); 明显是因为 writeDataToFile 不是用来保存 string 的,而是用来保存二进制 ArrayBuffer 的,你应该用 writeStringToFile

3赞

谢谢panda大大 。 用 jsb.fileUtils.writeStringToFile(customManifestStr, filees); 可以写入。 但是再更新完后,
let storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : ‘/’)+“asset/”+wKindID);
let filees = storagePath+"/project.manifest";
let bExist = jsb.fileUtils.isFileExist(filees);
前面这个判断还是为false , 这是为啥 ?

把路径打印出来检查一下吧

会跟版本有关系么? 我现在用的是 1.4.0 版本的 是打印这个路径 storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : ‘/’)+“asset/”+wKindID); ?

谢谢大大 是存储路径的问题 。 路径改成了
let s_Path_localManifest = storagePath + “/resources/HotUpdate”+s_Path_GameModel + wKindID;
let localProject = s_Path_localManifest+"/project.manifest";

这样就实现了

附上实现的完整代码 :

  var s_Path_Url = "";
        var s_Path_GameModel ="";
        if(YQ_SUB_GAME_MODEL_TEST == GameModel)
        {
            s_Path_GameModel = "/Test_Manifest/";
            s_Path_Url = "http://*******/HotUpdate_Test/"
        }
        else if (YQ_SUB_GAME_MODEL_PUBILC == GameModel)
        {
            s_Path_GameModel = "/Public_Manifest/";
            s_Path_Url = "http://******/HotUpdate/";
        }
        this.wLocalKindID = wKindID; 
       
        if (!cc.sys.isNative) {
            window.yqConfig.bNeedUpdate = false;
            return ;
        }
let UIRLFILE = s_Path_Url+wKindID;
        let customManifestStr = JSON.stringify(
        {
            "packageUrl": UIRLFILE,
            "remoteManifestUrl": UIRLFILE+"/project.manifest",
            "remoteVersionUrl" : UIRLFILE+"/version.manifest",
            "version": szFirstVersion,
            "assets": {},
            "searchPaths": []
        });
        let storagePath = ((jsb.fileUtils ? jsb.fileUtils.getWritablePath() : '/')+"asset/"+wKindID);
        let s_Path_localManifest = storagePath + "/resources/HotUpdate"+s_Path_GameModel + wKindID;
        let localProject = s_Path_localManifest+"/project.manifest";
        let bExist = jsb.fileUtils.isFileExist(localProject);
        var searchPaths = jsb.fileUtils.getSearchPaths();
        if(!bExist) 
        {    
            if( !jsb.fileUtils.isDirectoryExist(s_Path_localManifest))
            {   
                jsb.fileUtils.createDirectory(s_Path_localManifest);
            }
           jsb.fileUtils.writeStringToFile(customManifestStr, localProject);
        }
 this.manifestUrl = localProject;
        this._am = new jsb.AssetsManager(this.manifestUrl, storagePath);
        this._am.retain();
        
        if (cc.sys.os === cc.sys.OS_ANDROID) 
        {
            this._am.setMaxConcurrentTask(2);
        }
        this._needUpdate = false

我想问一下 在1.4的版本 你是如何实现 子游戏和主大厅的切换?是不是 不重启游戏可以实现?