-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathforge_install.py
More file actions
111 lines (92 loc) · 3.96 KB
/
forge_install.py
File metadata and controls
111 lines (92 loc) · 3.96 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env python3
import os
import re
import subprocess
import sys
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 get_forge_url(mcver, mlver):
index_url = 'https://files.minecraftforge.net/net/minecraftforge/forge/index_%s.html' \
% mcver
outpath = '/tmp/forge-%s-index.html' % mcver
if not os.path.exists(outpath):
resp = download(index_url, outpath, False)
if resp != 200:
print("Got %d error trying to download Forge download index" % resp)
return ""
with open(outpath, 'r') as f:
match = re.search(r"href=\".*(https://maven\.minecraftforge\.net/.*-%s-.*\.jar)\"" % mlver, f.read())
if match:
url = match.group(1)
else:
print("Could not find Forge download URL for version %s (Minecraft version %s)" % (mlver, mcver))
return ""
return url
def guess_forge_url(mcver, mlver):
forge_fullver = mcver + '-' + mlver
return 'https://maven.minecraftforge.net/net/minecraftforge/forge/%s/forge-%s-installer.jar' % (forge_fullver, forge_fullver)
def main(manifest, mcver, mlver, packname, mc_dir, manual):
url_providers = [guess_forge_url, get_forge_url]
outpath = '/tmp/forge-%s-installer.jar' % (mcver + '-' + mlver)
for provider in url_providers:
if os.path.exists(outpath):
break
url = provider(mcver, mlver)
resp = download(url, outpath, True)
if resp != 200:
print("Got %d error trying to download Forge" % resp)
if not os.path.exists(outpath):
print("Failed to download the Forge installer.")
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)