前言
使用CocosCreator打包了好多项目,但是一个一个改为全屏显示太慢,干脆自动化修改了。
源码
import os
# 所有打包后的文件路径
changeparent_filepath=r"C:\Users\Administrator\Desktop\all"
def bianliwaiceng(waicengPath):
filepaths=[]
dirs=os.listdir(waicengPath)
for file in dirs:
# file_name=file[:-4] # 去除文件后缀
print("遍历到"+file)
filepath=changeparent_filepath+"\\"+file
if os.path.isdir(filepath):
# print("是文件夹就进来"+file)
filepaths.append(filepath)
return filepaths
# 从文件夹中找到所有index.html的路径
def zhaodaoIndex(wenjianliebiaoList,mingzi):
indexFilePath=[]
for path in wenjianliebiaoList:
# print(path)
dirs=os.listdir(path)
for file in dirs:
# print(file)
if file == mingzi:
indexFilePath.append(path+"\\"+file)
return indexFilePath
def chuliIndex(allindexList):
for path in allindexList:
print("需要处理:"+path)
# 打开一个文件
fo = open(path, "r")
# print(fo.tell())
lines = fo.readlines()
# count = len(lines) #文件的总行数
# print(count)
# print(lines[22])
lines[22]='<!-- <h1 class="header">hello_world</h1> -->\n'
lines[24]='<div id="GameDiv" style="width:100%; height: 100%;">\n'
lines[25]=' <canvas id="GameCanvas" width="100%" height="100%"></canvas>\n'
lines[26]=' <div id="splash">\n'
lines[27]=' <div class="progress-bar stripes">\n'
lines[28]=' <span style="width: 0%"></span>\n'
lines[29]=' </div>\n'
lines[30]=' </div>\n'
lines[31]='</div>\n'
lines[33]='<!-- <p class="footer">Made with <a href="https://www.cocos.com/products#CocosCreator" title="cocos creator">Cocos Creator</a></p> -->\n'
# 关闭打开的文件
fo.close()
fo = open(path, "w")
for line in lines:
fo.writelines(line)
fo.close()
def chuliCss(allindexList):
for path in allindexList:
print("需要处理:"+path)
# 打开一个文件
fo = open(path, "r")
# print(fo.tell())
lines = fo.readlines()
# count = len(lines) #文件的总行数
# print(count)
lines[106]='/* '+lines[106]
lines[115]=lines[115]+' */'
lines.insert(0,'html,body{width: 100%;height: 100%;overflow: hidden;}\n')
# 关闭打开的文件
fo.close()
fo = open(path, "w")
for line in lines:
fo.writelines(line)
fo.close()
pathList = bianliwaiceng(changeparent_filepath)
allIndexPath=zhaodaoIndex(pathList,"index.html")
chuliIndex(allIndexPath)
allCssPath=zhaodaoIndex(pathList,"style-desktop.css")
chuliCss(allCssPath)