mirror of https://github.com/sm64pc/sm64pc.git
Added md5 validation to the resource copy
This commit is contained in:
parent
78d5c1b7b6
commit
c9fe88e193
|
@ -5,6 +5,14 @@ import os
|
|||
import os.path
|
||||
import zipfile
|
||||
from shutil import copyfile
|
||||
import hashlib
|
||||
|
||||
def md5(fname):
|
||||
hash_md5 = hashlib.md5()
|
||||
with open(fname, "rb") as f:
|
||||
for chunk in iter(lambda: f.read(4096), b""):
|
||||
hash_md5.update(chunk)
|
||||
return hash_md5.hexdigest()
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print('usage: mkzip <lstfile> <dstpath>')
|
||||
|
@ -21,9 +29,11 @@ with open(sys.argv[1], 'r') as f:
|
|||
|
||||
for (fname, aname) in lst:
|
||||
path = os.path.join(sys.argv[2], aname)
|
||||
if not os.path.exists(path):
|
||||
old_md5 = md5(fname);
|
||||
new_md5 = md5(path);
|
||||
if not os.path.exists(path) or old_md5 != new_md5:
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
copyfile(fname, path)
|
||||
print("Copying: " + path)
|
||||
else:
|
||||
print("Skipping: " + path)
|
||||
print("Skipping: " + path + " - MD5: "+md5(fname))
|
||||
|
|
Loading…
Reference in New Issue