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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
#include "Library.h"
#include "MinecraftInstance.h"
#include <net/Download.h>
#include <net/ChecksumValidator.h>
#include <minecraft/forge/ForgeXzDownload.h>
#include <Env.h>
#include <FileSystem.h>
void Library::getApplicableFiles(OpSys system, QStringList& jar, QStringList& native, QStringList& native32,
QStringList& native64, const QString &overridePath) const
{
bool local = isLocal();
auto actualPath = [&](QString relPath)
{
QFileInfo out(FS::PathCombine(storagePrefix(), relPath));
if(local && !overridePath.isEmpty())
{
QString fileName = out.fileName();
auto fullPath = FS::PathCombine(overridePath, fileName);
qDebug() << fullPath;
QFileInfo fileinfo(fullPath);
if(fileinfo.exists())
{
return fileinfo.absoluteFilePath();
}
}
return out.absoluteFilePath();
};
QString raw_storage = storageSuffix(system);
if(isNative())
{
if (raw_storage.contains("${arch}"))
{
auto nat32Storage = raw_storage;
nat32Storage.replace("${arch}", "32");
auto nat64Storage = raw_storage;
nat64Storage.replace("${arch}", "64");
native32 += actualPath(nat32Storage);
native64 += actualPath(nat64Storage);
}
else
{
native += actualPath(raw_storage);
}
}
else
{
jar += actualPath(raw_storage);
}
}
QList< std::shared_ptr< NetAction > > Library::getDownloads(OpSys system, class HttpMetaCache* cache,
QStringList& failedFiles, const QString & overridePath) const
{
QList<NetActionPtr> out;
bool isAlwaysStale = (hint() == "always-stale");
bool local = isLocal();
bool isForge = (hint() == "forge-pack-xz");
auto add_download = [&](QString storage, QString url, QString sha1)
{
auto entry = cache->resolveEntry("libraries", storage);
if(isAlwaysStale)
{
entry->setStale(true);
}
if (!entry->isStale())
return true;
if(local)
{
if(!overridePath.isEmpty())
{
QString fileName;
int position = storage.lastIndexOf('/');
if(position == -1)
{
fileName = storage;
}
else
{
fileName = storage.mid(position);
}
auto fullPath = FS::PathCombine(overridePath, fileName);
QFileInfo fileinfo(fullPath);
if(fileinfo.exists())
{
return true;
}
}
QFileInfo fileinfo(entry->getFullPath());
if(!fileinfo.exists())
{
failedFiles.append(entry->getFullPath());
return false;
}
return true;
}
Net::Download::Options options;
if(isAlwaysStale)
{
options |= Net::Download::Option::AcceptLocalFiles;
}
if (isForge)
{
qDebug() << "XzDownload for:" << rawName() << "storage:" << storage << "url:" << url;
out.append(ForgeXzDownload::make(url, storage, entry));
}
else
{
if(sha1.size())
{
auto rawSha1 = QByteArray::fromHex(sha1.toLatin1());
auto dl = Net::Download::makeCached(url, entry, options);
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1));
qDebug() << "Checksummed Download for:" << rawName() << "storage:" << storage << "url:" << url;
out.append(dl);
}
else
{
out.append(Net::Download::makeCached(url, entry, options));
qDebug() << "Download for:" << rawName() << "storage:" << storage << "url:" << url;
}
}
return true;
};
QString raw_storage = storageSuffix(system);
if(m_mojangDownloads)
{
if(isNative())
{
if(m_nativeClassifiers.contains(system))
{
auto nativeClassifier = m_nativeClassifiers[system];
if(nativeClassifier.contains("${arch}"))
{
auto nat32Classifier = nativeClassifier;
nat32Classifier.replace("${arch}", "32");
auto nat64Classifier = nativeClassifier;
nat64Classifier.replace("${arch}", "64");
auto nat32info = m_mojangDownloads->getDownloadInfo(nat32Classifier);
if(nat32info)
{
auto cooked_storage = raw_storage;
cooked_storage.replace("${arch}", "32");
add_download(cooked_storage, nat32info->url, nat32info->sha1);
}
auto nat64info = m_mojangDownloads->getDownloadInfo(nat64Classifier);
if(nat64info)
{
auto cooked_storage = raw_storage;
cooked_storage.replace("${arch}", "64");
add_download(cooked_storage, nat64info->url, nat64info->sha1);
}
}
else
{
auto info = m_mojangDownloads->getDownloadInfo(nativeClassifier);
if(info)
{
add_download(raw_storage, info->url, info->sha1);
}
}
}
else
{
qDebug() << "Ignoring native library" << m_name << "because it has no classifier for current OS";
}
}
else
{
if(m_mojangDownloads->artifact)
{
auto artifact = m_mojangDownloads->artifact;
add_download(raw_storage, artifact->url, artifact->sha1);
}
else
{
qDebug() << "Ignoring java library" << m_name << "because it has no artifact";
}
}
}
else
{
auto raw_dl = [&](){
if (!m_absoluteURL.isEmpty())
{
return m_absoluteURL;
}
if (m_repositoryURL.isEmpty())
{
return URLConstants::LIBRARY_BASE + raw_storage;
}
if(m_repositoryURL.endsWith('/'))
{
return m_repositoryURL + raw_storage;
}
else
{
return m_repositoryURL + QChar('/') + raw_storage;
}
}();
if (raw_storage.contains("${arch}"))
{
QString cooked_storage = raw_storage;
QString cooked_dl = raw_dl;
add_download(cooked_storage.replace("${arch}", "32"), cooked_dl.replace("${arch}", "32"), QString());
cooked_storage = raw_storage;
cooked_dl = raw_dl;
add_download(cooked_storage.replace("${arch}", "64"), cooked_dl.replace("${arch}", "64"), QString());
}
else
{
add_download(raw_storage, raw_dl, QString());
}
}
return out;
}
bool Library::isActive() const
{
bool result = true;
if (m_rules.empty())
{
result = true;
}
else
{
RuleAction ruleResult = Disallow;
for (auto rule : m_rules)
{
RuleAction temp = rule->apply(this);
if (temp != Defer)
ruleResult = temp;
}
result = result && (ruleResult == Allow);
}
if (isNative())
{
result = result && m_nativeClassifiers.contains(currentSystem);
}
return result;
}
bool Library::isLocal() const
{
return m_hint == "local";
}
void Library::setStoragePrefix(QString prefix)
{
m_storagePrefix = prefix;
}
QString Library::defaultStoragePrefix()
{
return "libraries/";
}
QString Library::storagePrefix() const
{
if(m_storagePrefix.isEmpty())
{
return defaultStoragePrefix();
}
return m_storagePrefix;
}
QString Library::filename(OpSys system) const
{
if(!m_filename.isEmpty())
{
return m_filename;
}
// non-native? use only the gradle specifier
if (!isNative())
{
return m_name.getFileName();
}
// otherwise native, override classifiers. Mojang HACK!
GradleSpecifier nativeSpec = m_name;
if (m_nativeClassifiers.contains(system))
{
nativeSpec.setClassifier(m_nativeClassifiers[system]);
}
else
{
nativeSpec.setClassifier("INVALID");
}
return nativeSpec.getFileName();
}
QString Library::displayName(OpSys system) const
{
if(!m_displayname.isEmpty())
return m_displayname;
return filename(system);
}
QString Library::storageSuffix(OpSys system) const
{
// non-native? use only the gradle specifier
if (!isNative())
{
return m_name.toPath(m_filename);
}
// otherwise native, override classifiers. Mojang HACK!
GradleSpecifier nativeSpec = m_name;
if (m_nativeClassifiers.contains(system))
{
nativeSpec.setClassifier(m_nativeClassifiers[system]);
}
else
{
nativeSpec.setClassifier("INVALID");
}
return nativeSpec.toPath(m_filename);
}
|