This repository was archived by the owner on Mar 26, 2023. It is now read-only.
forked from cdbbnnyCode/modpack-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforge_install.py
More file actions
80 lines (68 loc) · 2.95 KB
/
forge_install.py
File metadata and controls
80 lines (68 loc) · 2.95 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
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
#!/usr/bin/env python3
import sys
import os
import subprocess
import time
from util import *
# https://files.minecraftforge.net/maven/net/minecraftforge/forge/1.12.2-14.23.5.2847/forge-1.12.2-14.23.5.2847-universal.jar
def main(manifest, mcver, mlver, packname, mc_dir, manual):
forge_fullver = mcver + '-' + mlver
url = 'https://files.minecraftforge.net/maven/net/minecraftforge/forge/%s/forge-%s-installer.jar' \
% (forge_fullver, forge_fullver)
outpath = '/tmp/forge-%s-installer.jar' % forge_fullver
if not os.path.exists(outpath):
resp = download(url, outpath, True)
if resp != 200:
print("Got %d error trying to download Forge" % resp)
sys.exit(2)
# Run the Forge auto-install hack
if manual:
print("Using the manual installer!")
print("***** NEW: INSTALL TO THE MAIN .MINECRAFT DIRECTORY *****")
print("***** (Just hit 'OK' with the default settings) *****")
for i in range(20):
print("^ ", end="", flush=True)
time.sleep(0.05)
subprocess.run(['java', '-jar', outpath])
else:
compile_hack = False
if not os.path.exists('ForgeHack.class'):
compile_hack = True
else:
src_modtime = os.stat('ForgeHack.java').st_mtime
cls_modtime = os.stat('ForgeHack.class').st_mtime
if src_modtime > cls_modtime:
print("hack source file updated, recompiling")
compile_hack = True
if compile_hack:
subprocess.run(['javac', 'ForgeHack.java'])
exit_code = subprocess.run(['java', 'ForgeHack', outpath, mc_dir]).returncode
if exit_code != 0:
print("Error running the auto-installer, try using --manual.")
sys.exit(3)
ver_id = get_version_id(mcver, mlver)
if not os.path.exists(mc_dir + '/versions/' + ver_id):
print("Forge installation not found.")
if manual:
print("Make sure you browsed to the correct minecraft directory.")
print("Expected to find a directory named %s in %s" % (ver_id, mc_dir + '/versions'))
print("If a similarly named directory was created in the expected folder, please submit a")
print("bug report.")
sys.exit(3)
def get_version_id(mcver, mlver):
mcv_split = mcver.split('.')
mcv = int(mcv_split[0]) * 1000 + int(mcv_split[1])
mlv_split = mlver.split('.')
mlv = int(mlv_split[-1]) # modloader patch version
if mcv < 1008:
# 1.7 (and possibly lower, haven't checked)
return '%s-Forge%s-%s' % (mcver, mlver, mcver)
elif mcv < 1010:
# 1.8, 1.9
return '%s-forge%s-%s-%s' % (mcver, mcver, mlver, mcver)
elif mcv < 1012 or (mcv == 1012 and mlv < 2851):
# 1.10, 1.11, 1.12 (up to 1.12.2-14.23.5.2847)
return '%s-forge%s-%s' % (mcver, mcver, mlver)
else:
# 1.12.2-14.23.5.2851 and above
return '%s-forge-%s' % (mcver, mlver)