Repository navigation
Expand file tree
/
Copy pathenumerateForge.py
More file actions
executable file
·121 lines (95 loc) · 3.66 KB
/
Copy pathenumerateForge.py
File metadata and controls
executable file
·121 lines (95 loc) · 3.66 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
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/python3
from __future__ import print_function
import sys
import os
import re
from metautil import *
from forgeutil import *
from jsonobject import *
from distutils.version import LooseVersion
from enum import Enum
import requests
#with open('multimc/index.json', 'r', encoding='utf-8') as index:
#packages = MultiMCPackageIndex(json.load(index))
#for entry in packages.packages:
#print (entry)
class DownloadType(Enum):
NORMAL = 1
FORGE_XZ = 2
class DownloadEntry:
def __init__(self, url : str, kind : DownloadType, name : GradleSpecifier):
self.name = name
self.url = url
self.kind = kind
def __lt__(self, other):
return self.name < other.name
def __eq__(self, other):
return self.name == other.name
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return self.name.__hash__()
def toString(self):
return "%s %s" % (self.name.toString(), self.url)
def __repr__(self):
return "DownloadEntry('" + self.toString() + "')"
class MojangLibrary (JsonObject):
extract = ObjectProperty(MojangLibraryExtractRules, exclude_if_none=True, default=None)
name = GradleSpecifierProperty(required = True)
downloads = ObjectProperty(MojangLibraryDownloads, exclude_if_none=True, default=None)
natives = DictProperty(StringProperty, exclude_if_none=True, default=None)
rules = ListProperty(MojangRule, exclude_if_none=True, default=None)
class MultiMCLibrary (MojangLibrary):
url = StringProperty(exclude_if_none=True, default=None)
mmcHint = StringProperty(name="MMC-hint", exclude_if_none=True, default=None)
def GetLibraryDownload (library : MultiMCLibrary):
if library.natives:
raise Exception('Natives are not handled yet')
name = library.name
if library.mmcHint == 'forge-pack-xz':
kind = DownloadType.FORGE_XZ
name.extension = 'jar.pack.xz'
else:
kind = DownloadType.NORMAL
if library.downloads:
url = library.downloads.artifact.url
if url.endswith('.zip'):
name.extension = 'zip'
if library.downloads:
url = library.downloads.artifact.url
else:
if library.url:
url = library.url + name.getPath()
else:
url = 'https://libraries.minecraft.net/' + name.getPath()
return DownloadEntry(url, kind, name)
with open('multimc/net.minecraftforge/index.json', 'r', encoding='utf-8') as forgeIndex:
forgeVersions = MultiMCVersionIndex(json.load(forgeIndex))
urlSet = set()
for entry in forgeVersions.versions:
versionString = entry.version
versionPath = "multimc/net.minecraftforge/%s.json" % versionString
with open(versionPath, 'r') as infile:
forgeVersion = MultiMCVersionFile(json.load(infile))
if forgeVersion.libraries:
for entry in forgeVersion.libraries:
urlSet.add(GetLibraryDownload(entry))
if forgeVersion.jarMods:
for entry in forgeVersion.jarMods:
urlSet.add(GetLibraryDownload(entry))
if forgeVersion.mavenFiles:
for entry in forgeVersion.mavenFiles:
urlSet.add(GetLibraryDownload(entry))
for entry in urlSet:
libraryName = entry.name
folderPath = "forgemaven/%s" % libraryName.getBase()
filePath = "forgemaven/%s" % libraryName.getPath()
if not os.path.isfile(filePath):
os.makedirs(folderPath, exist_ok=True)
try:
downloadFile(entry.url, filePath)
except requests.exceptions.HTTPError as exc:
print('Missing: %s %s' % (entry.name, entry.url))
continue
print('Downloading %s' % entry.name)
print('To %s' % filePath)