forked from vcmi/vcmi-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_internal_assets.py
More file actions
52 lines (44 loc) · 1.6 KB
/
update_internal_assets.py
File metadata and controls
52 lines (44 loc) · 1.6 KB
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
import zipfile
import os
import sys
import hashlib
import shutil
p = os.path
def writeFolder(archive, folderPath, rootPath):
for root, dirs, filenames in os.walk(folderPath):
for name in filenames:
archive.write(p.normpath(p.join(root, name)), root[len(rootPath):] + "/" + name)
def createHash(path, outPath):
blocksize = 65536
hasher = hashlib.md5()
with open(path, "rb") as file:
buf = file.read(blocksize)
while len(buf) > 0:
hasher.update(buf)
buf = file.read(blocksize)
with open(outPath, "w") as file:
file.write(hasher.hexdigest())
dir = p.dirname(p.realpath(sys.argv[0]))
pathAssets = dir + "/project/vcmi-app/src/main/assets"
pathOutInternalData = pathAssets + "/internalData.zip"
pathOutHash = pathAssets + "/internalDataHash.txt"
pathBase = dir + "/ext/vcmi"
pathConfig = pathBase + "/config"
pathMods = pathBase + "/Mods"
assetsPaths = [
[pathConfig, pathBase],
[pathMods, pathBase],
[p.abspath(dir + "/../data/vcmi_submods/Mods"), p.abspath(dir + "/../data/vcmi_submods")] # templates + extra res
]
with zipfile.ZipFile(pathOutInternalData, "w", zipfile.ZIP_DEFLATED) as zf:
for path in assetsPaths:
if not p.exists(path[0]):
print("Skipping path " + path[0] + " (not found)")
continue
writeFolder(zf, path[0], path[1])
createHash(pathOutInternalData, pathOutHash)
#copy authors file into app resources so that we can display it in about view
try:
shutil.copy2(dir + "/ext/vcmi/AUTHORS", dir + "/project/vcmi-app/src/main/res/raw/authors.txt")
except IOError as e:
print("Could not update authors file: " + e.strerror)