forked from MinecraftForge/MinecraftForge
/
setup.py
120 lines (89 loc) · 4.05 KB
/
setup.py
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
112
113
114
115
116
117
118
119
120
import os, os.path, sys
import urllib, zipfile
import shutil, glob, fnmatch
import subprocess, logging
import argparse
forge_dir = os.path.dirname(os.path.abspath(__file__))
forge_mcp_conf = os.path.join(forge_dir, 'conf')
mcp_dir = os.path.abspath('..')
mcp_included_conf = os.path.join(mcp_dir, 'conf')
src_dir = os.path.join(mcp_dir, 'src')
sys.path.append(mcp_dir)
from runtime.decompile import decompile
from runtime.updatenames import updatenames
from runtime.updatemd5 import updatemd5
from forge import apply_patches, copytree, reset_logger, download_ff, cleanup_source, pre_decompile, post_decompile
def main():
print '=================================== Setup Start ================================='
parser = argparse.ArgumentParser(description='Sets up Forge with MCP.')
parser.add_argument('--skipdecompile', action='store_true', help='prevents decompilation during setup')
parser.add_argument('--preventconfigclobber', action='store_true', help='prevents overwriting mcp.cfg during setup')
args = parser.parse_args()
skipDecompile = args.skipdecompile
preventConfigClobber = args.preventconfigclobber
# print "test args {} {}".format(args.skipdecompile, args.preventconfigclobber)
if not preventConfigClobber:
if os.path.isdir(mcp_included_conf):
shutil.rmtree(mcp_included_conf)
shutil.copytree(forge_mcp_conf, mcp_included_conf)
print 'Successfully overwrote MCP config folder with the Forge config folder (including patches)! (If you want this to not happen, please use the --preventconfigclobber option!)'
if not skipDecompile:
if not download_ff(mcp_dir):
sys.exit(1)
if os.path.isdir(src_dir):
shutil.rmtree(src_dir)
try:
pre_decompile()
os.chdir(mcp_dir)
# Conf JAD CSV -r -d -a -n -p -o -l -g
decompile(None, False, False, True, True, False, True, False, False, False, False)
reset_logger()
os.chdir(forge_dir)
post_decompile()
except SystemExit, e:
print 'Decompile Exception: %d ' % e.code
raise e
if not os.path.isdir(src_dir):
print 'Something went wrong, src folder not found at: %s' % src_dir
sys.exit(1)
cleanup_source(src_dir)
setup_fml()
os.chdir(mcp_dir)
updatenames(None, True)
reset_logger()
updatemd5(None, True)
reset_logger()
os.chdir(forge_dir)
base_dir = os.path.join(mcp_dir, 'src_base')
work_dir = os.path.join(mcp_dir, 'src_work')
if os.path.isdir(base_dir):
shutil.rmtree(base_dir)
if os.path.isdir(work_dir):
shutil.rmtree(work_dir)
print 'Setting up source directories'
shutil.copytree(src_dir, base_dir)
shutil.copytree(src_dir, work_dir)
print 'Applying forge patches'
apply_patches(os.path.join(forge_dir, 'patches'), work_dir)
print '=================================== Setup Finished ================================='
def setup_fml():
print 'Setting up Forge ModLoader'
fml = glob.glob(os.path.join(forge_dir, 'fml-src-*.zip'))
if not len(fml) == 1:
if len(fml) == 0:
print 'Missing FML source zip, should be named fml-src-*.zip inside your forge folder, obtain it from the repo'
else:
print 'To many FML source zips found, we should only have one. Check the Forge Git for the latest FML version supported'
sys.exit(1)
fml_dir = os.path.join(forge_dir, 'fml')
if os.path.isdir(fml_dir):
shutil.rmtree(fml_dir)
print 'Extracting: %s' % os.path.basename(fml[0])
zf = zipfile.ZipFile(fml[0])
zf.extractall(forge_dir)
zf.close()
print 'Applying Forge ModLoader patches'
apply_patches(os.path.join(fml_dir, 'patches'), src_dir)
copytree(os.path.join(fml_dir, 'src'), src_dir)
if __name__ == '__main__':
main()