2012-11-20 09:55:41 +00:00
|
|
|
import os, os.path, sys
|
|
|
|
import shutil, glob, fnmatch
|
|
|
|
import csv, re
|
|
|
|
from pprint import pprint
|
|
|
|
from zipfile import ZipFile
|
2012-12-09 05:40:39 +00:00
|
|
|
from optparse import OptionParser
|
2013-06-28 05:30:40 +00:00
|
|
|
from contextlib import closing
|
2012-11-20 09:55:41 +00:00
|
|
|
|
2013-06-28 05:30:40 +00:00
|
|
|
def get_merged_info(fml_dir, mcp_dir):
|
2012-11-20 09:55:41 +00:00
|
|
|
joined = os.path.join(mcp_dir, 'conf', 'joined.srg')
|
|
|
|
values = {'PK:': {}, 'CL:': {}, 'FD:': {}, 'MD:': {}}
|
|
|
|
|
|
|
|
if not os.path.isfile(joined):
|
2013-06-28 05:30:40 +00:00
|
|
|
sys.path.append(os.path.join(fml_dir, 'install'))
|
2012-11-20 09:55:41 +00:00
|
|
|
from fml import gen_merged_srg
|
2013-06-28 05:30:40 +00:00
|
|
|
values = create_merged_srg(mcp_dir, None)
|
2012-11-20 09:55:41 +00:00
|
|
|
else:
|
|
|
|
with open(joined, 'r') as fh:
|
|
|
|
for line in fh:
|
|
|
|
pts = line.rstrip('\r\n').split(' ')
|
|
|
|
if pts[0] == 'MD:':
|
|
|
|
values[pts[0]][pts[1] + ' ' + pts[2]] = pts[3] + ' ' + pts[4]
|
|
|
|
else:
|
|
|
|
values[pts[0]][pts[1]] = pts[2]
|
|
|
|
return {t:{v.split(' ')[0]:k for k, v in m.items()} for t,m in values.items()}
|
|
|
|
|
|
|
|
def main():
|
2012-12-09 05:40:39 +00:00
|
|
|
parser = OptionParser()
|
2013-06-28 05:30:40 +00:00
|
|
|
parser.add_option('-m', '--mcp-dir', action='store', dest='mcp_dir', help='MCP install folder', default='mcp')
|
|
|
|
parser.add_option('-f', '--fml-dir', action='store', dest='fml_dir', help='FML instlal folder', default='.')
|
2012-12-09 05:40:39 +00:00
|
|
|
options, _ = parser.parse_args()
|
|
|
|
|
2013-06-28 05:30:40 +00:00
|
|
|
sys.path.append(os.path.join(options.fml_dir, 'install'))
|
2012-12-09 05:40:39 +00:00
|
|
|
|
2013-06-28 05:30:40 +00:00
|
|
|
from fml import read_mc_versions, load_srg
|
|
|
|
info = read_mc_versions(options.fml_dir, work_dir=os.path.join(options.mcp_dir, 'jars'))
|
2012-11-20 09:55:41 +00:00
|
|
|
|
2013-06-28 05:30:40 +00:00
|
|
|
types = {'client' : [], 'server' : []}
|
|
|
|
for type in ['client', 'server']:
|
|
|
|
with closing(ZipFile(info['%s_file' % type])) as zip:
|
|
|
|
for i in zip.filelist:
|
|
|
|
if i.filename.endswith('.class') and i.filename.find('/') == -1:
|
|
|
|
types[type].append(i.filename[:-6])
|
2012-11-20 09:55:41 +00:00
|
|
|
|
2013-06-28 05:30:40 +00:00
|
|
|
srg = get_merged_info(options.fml_dir, options.mcp_dir)
|
|
|
|
pkgs = {}
|
2012-11-20 09:55:41 +00:00
|
|
|
pkg_file = os.path.join('conf', 'packages.csv')
|
|
|
|
|
|
|
|
if os.path.isfile(pkg_file):
|
2013-06-28 05:30:40 +00:00
|
|
|
with closing(open(pkg_file)) as fh:
|
2012-11-20 09:55:41 +00:00
|
|
|
reader = csv.DictReader(fh)
|
|
|
|
for line in reader:
|
|
|
|
pkgs[line['class']] = line['package']
|
|
|
|
|
|
|
|
classes = []
|
|
|
|
for cls in srg['CL:'].keys():
|
|
|
|
if cls.startswith('net/minecraft/src/'):
|
|
|
|
obf = srg['CL:'][cls]
|
|
|
|
cls = cls[18:]
|
|
|
|
classes.append(cls)
|
2013-06-28 05:30:40 +00:00
|
|
|
for type in ['server', 'client']:
|
|
|
|
if obf in types[type]:
|
|
|
|
types[type].remove(obf)
|
|
|
|
types[type].append(cls)
|
2012-11-20 09:55:41 +00:00
|
|
|
|
|
|
|
for cls in pkgs.keys():
|
|
|
|
if not cls in classes:
|
2012-12-18 00:55:46 +00:00
|
|
|
print 'Removed Class: %s/%s' % (pkgs[cls], cls)
|
2013-03-02 08:12:31 +00:00
|
|
|
pkgs.pop(cls)
|
2012-11-20 09:55:41 +00:00
|
|
|
|
|
|
|
for cls in classes:
|
|
|
|
if not cls in pkgs.keys():
|
|
|
|
print 'New Class: %s' % cls
|
|
|
|
if cls.find('/') == -1:
|
2013-06-28 05:30:40 +00:00
|
|
|
if cls in types['server'] and cls in types['client']:
|
2012-12-09 01:50:14 +00:00
|
|
|
pkgs[cls] = 'get_me_out_of_here_shared'
|
2013-06-28 05:30:40 +00:00
|
|
|
elif cls in types['server']:
|
2012-12-09 01:50:14 +00:00
|
|
|
pkgs[cls] = 'get_me_out_of_here_server'
|
2013-06-28 05:30:40 +00:00
|
|
|
elif cls in types['client']:
|
2012-12-09 01:50:14 +00:00
|
|
|
pkgs[cls] = 'get_me_out_of_here_client'
|
2012-11-20 09:55:41 +00:00
|
|
|
else:
|
2012-12-09 01:50:14 +00:00
|
|
|
pkgs[cls] = 'get_me_out_of_here_src'
|
2012-11-20 09:55:41 +00:00
|
|
|
|
|
|
|
tmp=[]
|
|
|
|
for cls,pkg in pkgs.items():
|
|
|
|
tmp.append({'class': cls, 'package': pkg})
|
|
|
|
|
2013-06-28 05:30:40 +00:00
|
|
|
with closing(open(pkg_file, 'wb')) as fh:
|
2012-11-20 09:55:41 +00:00
|
|
|
writer = csv.DictWriter(fh, fieldnames=['class', 'package'], lineterminator='\n')
|
|
|
|
writer.writeheader()
|
|
|
|
for row in sorted(tmp, key=lambda x: (x['package'], x['class'])):
|
|
|
|
writer.writerow(row)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|