#用来修改导出生成的.h 文件和 。cpp文件
import os
#导出后的文件目录
path = "C:\\Users\\Administrator\\Desktop\\code\\"
#.h 中添加的代码段
res_include_str = '#include "../tui_playercard_sub_widget_interface.h"\n'
class_str = ", public TUIPlayercard_sub_widget\n"
ui_wnd_def = "\tvirtual TUIWnd* GetTUIWnd() { return this; }"
#.cpp 中添加的代码段
define_format = "DEFINE_PSW_CRERATE(TUIplayercard_sub_widget%s);\n"
#打印出类的声明和注册,最后直接复制粘贴到 tui_playercard_sub_widget_manager.cpp 中
declare_format = "DECLARE_PSW_CRERATE(TUIplayercard_sub_widget%s);"
register_format = '__CREATE_PSW__("widget%s", TUIplayercard_sub_widget%s);'
#后缀列表
suffix_list= []
#获得文件列表
files = os.listdir(path)
file_all_path = []
for file in files:
file_all_path.append(path + file);
#获得后缀
def get_suffix(filename):
index = filename.find('_sk')
index2 = filename.find('.')
suffix_list.append(filename[index:index2])
return filename[index:index2]
#修改.h文件
def change_file_h(filename):
p = open(filename, 'r+')
lines = p.readlines();
p.seek(0)
line_num = 1
for line in lines:
if line_num == 9:
line = line + res_include_str;
if line_num == 15:
line = line + class_str
if line_num == 22:
line = line + ui_wnd_def
line_num += 1
p.write(line)
p.close();
#修改.cpp文件
def change_fild_cpp(filename):
p = open(filename, 'r+')
lines = p.readlines();
p.seek(0)
line_num = 1
for line in lines:
if line_num == 40:
create_def_str = define_format % get_suffix(filename)
line = line + create_def_str;
line_num += 1
p.write(line)
p.close();
if __name__ == '__main__':
for filename in file_all_path:
if filename.find('.h') > 0 and filename.find('res') < 0 :
change_file_h(filename)
elif filename.find('.cpp') > 0 and filename.find('res') < 0 :
change_fild_cpp(filename)
print ("---DECLARE---")
for suffix in suffix_list:
print(declare_format % suffix)
print("---REGISTER---")
for suffix in suffix_list:
print(register_format % (suffix,suffix))