Проверка хэша при установке

This commit is contained in:
Евгений Титаренко 2023-07-23 18:47:01 +03:00
parent 109168160c
commit 699b7c5f14
2 changed files with 33 additions and 5 deletions

13
mcfs.py
View file

@ -3,7 +3,7 @@ from sys import platform
import shutil
import zipfile
import json
from hashlib import sha512
class MCVersion:
def __init__(self, version_number, is_modified=False, modloader=None):
@ -118,3 +118,14 @@ def get_installed_mc_versions():
pass
versions.append(mc_ver)
return sorted(versions, reverse=True)
def check_file_hash(path, ref_hash):
buffer_size = 65536
hash = sha512()
with open(path, 'rb') as f:
data = True
while data:
data = f.read(buffer_size)
hash.update(data)
return hash.hexdigest() == ref_hash