-
Notifications
You must be signed in to change notification settings - Fork 1
/
buildResc.py
95 lines (74 loc) · 2.87 KB
/
buildResc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#
# This file is part of the KandVST synthesizer.
#
# Copyright (c) 2018 Lukas Rahmn, Anton Fredriksson,
# Sarosh Nasir, Stanisław Zwierzchowski,
# Klas Ludvigsson and Andreas Kuszli
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
import sys
from os import walk
import os
from os import path
writeDir='Source'
if not os.path.exists(writeDir):
os.makedirs(writeDir)
__writeFile_h = open (writeDir+"/Util/Resources_files.h",'w')
__writeFile_cpp = open (writeDir+"/Util/Resources_files.cpp",'w')
__writeFile_h.write("#ifndef RESOURCES_FILES_H\n#define RESOURCES_FILES_H\n")
__writeFile_cpp.write("#include \"Resources_files.h\"\n")
rowBreak =30
def createResourceFile(fullDir,__fileList,__name,__namespace):
__namespace += "::" + __name
if (len(__fileList)==0):
return
for __fileName in __fileList:
__file = open(os.path.join(fullDir,__fileName),'rb')
data = __file.read()
#WriteHeader
filename,ext= os.path.splitext(__fileName)
__writeFile_h.write("extern unsigned char " + filename+"_"+ext[1:] +"[" + str(os.path.getsize(os.path.join(fullDir,__fileName))) +"];\n")
__writeFile_cpp.write("unsigned char " + __namespace+"::"+filename+"_"+ext[1:] +"[] = {")
count = 0
for byte in data:
if (count == len(data)-1):
__writeFile_cpp.write(hex(byte))
break
__writeFile_cpp.write(hex(byte)+",")
count +=1
if (rowBreak > 0):
if (count % rowBreak == 0):
__writeFile_cpp.write("\n")
#WriteFooter
__writeFile_cpp.write("};\n\n")
print (__fileName + " : " + str(count) + " bytes")
return
def walkDir(dir,namespace):
files = [f for f in os.listdir(dir) if path.isfile(path.join(dir,f))]
dirs = [f for f in os.listdir(dir) if (not f in files)]
name= os.path.basename(dir)
__writeFile_h.write("namespace " + name + "{\n")
for _dir in dirs:
ns = ""
if (namespace !=""):
ns = namespace + "::"
walkDir(path.join(dir,_dir),ns+dir)
name= os.path.basename(dir)
createResourceFile(dir,files,name,namespace)
__writeFile_h.write("}\n")
return
walkDir(sys.argv[1],"")
__writeFile_h.write("#endif")