Skip to content

Commit 535614d

Browse files
committed
check sha1 for forge/neoforge maven
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
1 parent b95b599 commit 535614d

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

meta/common/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,12 @@ def default_session():
8686
sess.headers.update({"User-Agent": "PrismLauncherMeta/1.0"})
8787

8888
return sess
89+
90+
91+
def remove_files(file_paths):
92+
for file_path in file_paths:
93+
try:
94+
if os.path.isfile(file_path):
95+
os.remove(file_path)
96+
except Exception as e:
97+
print(e)

meta/run/update_forge.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616

1717
from pydantic import ValidationError
1818

19-
from meta.common import upstream_path, ensure_upstream_dir, default_session
19+
from meta.common import (
20+
upstream_path,
21+
ensure_upstream_dir,
22+
default_session,
23+
remove_files,
24+
)
2025
from meta.common.forge import (
2126
JARS_DIR,
2227
INSTALLER_INFO_DIR,
@@ -292,6 +297,19 @@ def main():
292297
UPSTREAM_DIR + "/forge/version_manifests/%s.json" % version.long_version
293298
)
294299

300+
if not os.path.isfile(jar_path):
301+
remove_files([profile_path, installer_info_path])
302+
else:
303+
fileSha1 = filehash(jar_path, hashlib.sha1)
304+
try:
305+
rfile = sess.get(version.url() + ".sha1")
306+
rfile.raise_for_status()
307+
if fileSha1 != rfile.text.strip():
308+
remove_files([jar_path, profile_path, installer_info_path])
309+
except Exception as e:
310+
eprint("Failed to check sha1 %s" % version.url())
311+
eprint("Error is %s" % e)
312+
295313
installer_refresh_required = not os.path.isfile(
296314
profile_path
297315
) or not os.path.isfile(installer_info_path)

meta/run/update_neoforge.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717

1818
from pydantic import ValidationError
1919

20-
from meta.common import upstream_path, ensure_upstream_dir, default_session
20+
from meta.common import (
21+
upstream_path,
22+
ensure_upstream_dir,
23+
default_session,
24+
remove_files,
25+
)
2126
from meta.common.neoforge import (
2227
JARS_DIR,
2328
INSTALLER_INFO_DIR,
@@ -243,6 +248,19 @@ def main():
243248
UPSTREAM_DIR + "/neoforge/version_manifests/%s.json" % version.long_version
244249
)
245250

251+
if not os.path.isfile(jar_path):
252+
remove_files([profile_path, installer_info_path])
253+
else:
254+
fileSha1 = filehash(jar_path, hashlib.sha1)
255+
try:
256+
rfile = sess.get(version.url() + ".sha1")
257+
rfile.raise_for_status()
258+
if fileSha1 != rfile.text.strip():
259+
remove_files([jar_path, profile_path, installer_info_path])
260+
except Exception as e:
261+
eprint("Failed to check sha1 %s" % version.url())
262+
eprint("Error is %s" % e)
263+
246264
installer_refresh_required = not os.path.isfile(
247265
profile_path
248266
) or not os.path.isfile(installer_info_path)

0 commit comments

Comments
 (0)