-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiconapk2hwt.py
136 lines (116 loc) · 3.57 KB
/
iconapk2hwt.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# coding utf-8
'''
create by bigzhu
qq:228812066
2018.2.24
'''
import os
import shutil
import zipfile
import tarfile
# param
ind = []
def read_ind():
global ind
with open('ind.txt', 'r') as f:
lines = f.readlines()
le = len(lines)
for i in range(le):
line = lines[i]
rows = line.split('\n')[0].split(',')
if len(rows) == 3:
ind.append(rows[0] + ',' + rows[1] + '.png,' + rows[2] + '.png')
def delDir(delDir):
delList = os.listdir(delDir)
for f in delList:
filePath = os.path.join(delDir, f)
if os.path.isfile(filePath):
os.remove(filePath)
# print(filePath + " was removed!")
elif os.path.isdir(filePath):
shutil.rmtree(filePath, True)
# print("Directory: " + filePath + " was removed!")
def make_zip(source_dir, output_filename):
zipf = zipfile.ZipFile(output_filename, 'w')
pre_len = len(os.path.dirname(source_dir))
for parent, dirnames, filenames in os.walk(source_dir):
for filename in filenames:
pathfile = os.path.join(parent, filename)
arcname = pathfile[pre_len:].strip(os.path.sep) # 相对路径
zipf.write(pathfile, arcname)
zipf.close()
def make_targz(source_dir, output_filename):
with tarfile.open(output_filename, "w:gz") as tar:
tar.add(source_dir, arcname=os.path.basename(source_dir))
if __name__ == '__main__':
# 准备数据,解压
z = zipfile.ZipFile('theme.hwt', 'r')
z.extractall(path='theme/')
z.close()
print('theme.hwt exted.')
z2 = zipfile.ZipFile('theme/icons', 'r')
z2.extractall(path='icons/')
z2.close()
print('icon exted.')
fnlist = os.listdir('icons')
for f in fnlist:
if 'icon_' not in f:
os.remove('icons/' + f)
print('del somepng.')
z3 = zipfile.ZipFile('icon.apk', 'r')
z3.extractall(path='.apk/')
z3.close()
print('apk exted.')
src_s = '.apk/res/drawable-nodpi-v4/'
dst_s = 'icons/'
read_ind()
# print(ind)
srcfs = []
for fn in os.listdir(src_s):
srcfs.append(fn)
e0, e1, e2 = 0, 0, 0
notmatchlist = []
tol = len(ind)
for i in range(tol):
match = False
vs = ind[i].split(',')
appname, srcf, dstf = vs[0], vs[1], vs[2]
if srcf in srcfs:
oldfn = src_s + srcf
newfn = dst_s + dstf
shutil.copyfile(oldfn, newfn)
e0 += 1
match = True
elif 'huawei_' in srcf:
srcf_ = srcf.split('_')[1]
if srcf_ in srcfs:
oldfn = src_s + srcf_
newfn = dst_s + dstf
shutil.copyfile(oldfn, newfn)
e1 += 1
match = True
else:
for j in range(len(srcfs)):
if srcf in srcfs[j]:
oldfn = src_s + srcfs[j]
newfn = dst_s + dstf
shutil.copyfile(oldfn, newfn)
e2 += 1
match = True
break
if match == False:
notmatchlist.append(appname)
# 压缩
make_zip('icons/', 'theme/icons')
make_zip('theme/', 'theme_new.hwt')
delDir('.apk/')
delDir('icons/')
delDir('theme/')
os.rmdir('.apk/')
os.rmdir('icons/')
os.rmdir('theme/')
print('\nfinished!')
print("total:{}\ne0:{}\ne1:{}\ne2:{}\nnot match:{}".format(len(ind), e0, e1, e2, len(ind) - e0 - e1 - e2))
if len(notmatchlist) > 0:
print('not match list:')
print(notmatchlist)