-
Notifications
You must be signed in to change notification settings - Fork 4
/
clientCopy.py
154 lines (126 loc) · 4.88 KB
/
clientCopy.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python2
'''
Created on Jun 30, 2013
@author: kickban
'''
import os, sys
import shutil
import zipfile
from commands import Commands
import MinecraftDiscovery
def copyAssets(src, dst):
if os.path.exists(dst):
shutil.rmtree(dst)
try:
shutil.copytree(src, dst)
except:
print ("Error copying assets.")
sys.exit()
def copyLibrary(src, dst, library):
try:
dstPath = os.path.split(os.path.join(dst, library['filename']))[0]
if os.path.exists(dstPath):
shutil.rmtree(dstPath)
os.makedirs(dstPath)
shutil.copy2(os.path.join(src, library['filename']), dstPath)
except:
print ("Error copying library %s"%library['name'])
sys.exit()
#def extractLibrary(src, dst, library, version):
# try:
# srcPath = os.path.join(src, library['filename'])
# dstPath = os.path.join(dst, "versions", version, "%s-natives"%version)
#
# if not os.path.exists(dstPath):
# os.makedirs(dstPath)
#
# jarFile = zipfile.ZipFile(srcPath)
# fileList = jarFile.namelist()
#
# for _file in fileList:
# if not os.path.exists(os.path.join(dstPath, _file)):
# exclude = False;
# for entry in library['exclude']:
# if entry in _file:
# exclude = True
# if not exclude:
# print("Extracting file %s from library %s"%(_file, library['name'].split(":")[1]))
# jarFile.extract(_file, dstPath)
#
# except:
# print ("Error extracting library %s"%library['name'])
# sys.exit()
def extractNative(root, name, jarname, version):
try:
srcPath = os.path.join(root, jarname)
dstPath = os.path.join(root, "versions", version, "%s-natives"%version)
if not os.path.exists(dstPath):
os.makedirs(dstPath)
jarFile = zipfile.ZipFile(srcPath)
jarFile.extract(name, dstPath)
except:
print ("Error extracting native %s from %s"%(name, jarname))
sys.exit()
def copyMinecraft(src, dst, version):
try:
jarSrcPath = os.path.join(src, "versions", version, "%s.jar"%version)
jsonSrcPath = os.path.join(src, "versions", version, "%s.json"%version)
dstPath = os.path.join(dst, "versions", version)
if os.path.exists(dstPath):
shutil.rmtree(dstPath)
os.makedirs(dstPath)
shutil.copy2(jarSrcPath, dstPath)
shutil.copy2(jsonSrcPath, dstPath)
except Exception as e:
print ("\nError while copying Minecraft : %s"%e)
sys.exit()
#########################################################################################################
def copyClientAssets(commands, workDir = None):
currentVersion = commands.versionClient
osKeyword = MinecraftDiscovery.getNativesKeyword()
if workDir == None:
if MinecraftDiscovery.checkCacheIntegrity(commands.dirjars, commands.jsonFile, osKeyword, currentVersion):
return
else:
mcDir = MinecraftDiscovery.getMinecraftPath()
else:
mcDir = workDir
#if not workDir:
# mcDir = MinecraftDiscovery.getMinecraftPath()
#else:
# mcDir = workDir
dstDir = commands.dirjars
#versionDir = os.path.join(mcDir, "versions")
#librariesDir = os.path.join(mcDir, "libraries")
print("Looking in %s for mc installs..."%os.path.join(mcDir, "versions")),
MinecraftDiscovery.checkMCDir(mcDir, currentVersion)
print("OK")
print("Copying assets..."),
copyAssets(os.path.join(mcDir, "assets"), os.path.join(dstDir, "assets"))
print("OK")
print("Parsing JSON file..."),
mcLibraries = MinecraftDiscovery.getLibraries(mcDir, MinecraftDiscovery.getJSONFilename(mcDir, currentVersion), osKeyword)
print("OK")
print ("Looking for minecraft main jar..."),
if (MinecraftDiscovery.checkMinecraftExists(dstDir, currentVersion)):
print ("OK")
else:
print ("Not found")
print ("Copying minecraft main jar..."),
copyMinecraft(mcDir, dstDir, currentVersion)
print("OK")
print ("> Checking libraries...")
for library in mcLibraries.values():
if not MinecraftDiscovery.checkLibraryExists(dstDir, library):
print ("\tCopying library %s..."%library['name'].split(':')[1]),
copyLibrary(mcDir, dstDir, library)
print ("OK")
print ("> Checking Natives...")
for native, jarname in MinecraftDiscovery.getNatives(dstDir, mcLibraries).items():
if not MinecraftDiscovery.checkNativeExists(dstDir, native, currentVersion):
print ("\tExtracting native %s..."%native),
extractNative(dstDir, native, jarname, currentVersion)
print ("OK")
if __name__ == '__main__':
commands = Commands()
copyClientAssets(commands)