cocos2dx-3.x 用脚本生成 AssetsManagerEx自动更新所需的manifest文件

该博客介绍了一种使用Python脚本的方法,用于生成Cocos2dx 3.x版本中AssetsManagerEx自动更新所需的manifest文件。脚本遍历指定目录计算文件的MD5值,并将结果写入manifest文件,包括project.manifest和version.manifest。这两个文件包含了文件的URL、版本信息和MD5校验和,以便于Cocos2dx游戏资源的自动更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import os
import hashlib
import time
#
def getFileMd5(filename):
    if not os.path.isfile(filename):
        return
    myhash = hashlib.md5()# create a md5 object
    f = file(filename,'rb')
    while True:
        b = f.read(8096)# get file content.
        if not b :
            break
        myhash.update(b)#encrypt the file
    f.close()
    return myhash.hexdigest()

def walk(path, prefix):
    global xml
    fl = os.listdir(path) # get what we have in the dir.
    for f in fl:
        if os.path.isdir(os.path.join(path,f)): # if is a dir.
            if prefix == '':
                walk(os.path.join(path,f), f)
            else:
                walk(os.path.join(path,f), prefix + '/' + f)
        else:
            md5 = getFileMd5(os.path.join(path,f))
            xml += "\n\t\t\"%s\" : {\n\t\t\t\"md5\" : \"%s\"\n\t\t}, " % (prefix + '/' + f, md5) # output to the md5 value to a string in xml format.
if __name__ == "__main__": 
    timeStr = time.strftime("%Y%m%d%H%M%S",time.localtime(time.time()))
    if not os.path.exists(os.getcwd() + '\\manifest'):
        os.mkdir(os.getcwd() + '\\manifest')
    #generate project.manifest
    xml = '{\
    \n\t"packageUrl" : "http://192.168.2.50/version/",\
    \n\t"remoteVersionUrl" : "http://192.168.2.50/manifest/version.manifest",\
    \n\t"remoteManifestUrl" : "http://192.168.2.50/manifest/project.manifest",\
    \n\t"version" : "0.0.%s",\
    \n\t"engineVersion" : "Cocos2d-x v3.10",\
    \n\n\t"assets" : {' % timeStr
    walk(os.getcwd() + '\\version', '')
    xml = xml[:-2]
    xml += '\n\t},\
    \n\t"searchPaths" : [\
    \n\t]\
    \n}'
    f = file("manifest\project.manifest", "w+")
    f.write(xml)
    print 'generate version.manifest finish.'
    #generate version.manifest
    xml = '{\
    \n\t"packageUrl" : "http://192.168.2.50/api/version/",\
    \n\t"remoteVersionUrl" : "http://192.168.2.50/api/manifest/version.manifest",\
    \n\t"remoteManifestUrl" : "http://192.168.2.50/api/manifest/project.manifest",\
    \n\t"version" : "0.0.%s",\
    \n\t"engineVersion" : "Cocos2d-x v3.10"\n}' % timeStr
    f = file("manifest\\version.manifest", "w+")
    f.write(xml)
    print 'generate version.manifest finish.'

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值