Fix Library resolve bug
This commit is contained in:
@@ -118,7 +118,7 @@ public class DynamicDownloadProvider extends MojangDownloadProvider {
|
|||||||
if (StrUtils.isNotBlank(launcherMetaAddr)) {
|
if (StrUtils.isNotBlank(launcherMetaAddr)) {
|
||||||
str = str.replace("https://launchermeta.mojang.com", launcherMetaAddr);
|
str = str.replace("https://launchermeta.mojang.com", launcherMetaAddr);
|
||||||
}
|
}
|
||||||
if (StrUtils.isNotBlank(launcherMetaAddr)) {
|
if (StrUtils.isNotBlank(launcherAddr)) {
|
||||||
str = str.replace("https://launcher.mojang.com", launcherAddr);
|
str = str.replace("https://launcher.mojang.com", launcherAddr);
|
||||||
}
|
}
|
||||||
return super.getParsedDownloadURL(str);
|
return super.getParsedDownloadURL(str);
|
||||||
|
|||||||
@@ -31,122 +31,122 @@ import org.jackhuang.hellominecraft.util.StrUtils;
|
|||||||
*/
|
*/
|
||||||
public class MinecraftLibrary extends IMinecraftLibrary {
|
public class MinecraftLibrary extends IMinecraftLibrary {
|
||||||
|
|
||||||
@SerializedName("rules")
|
@SerializedName("rules")
|
||||||
public ArrayList<Rules> rules;
|
public ArrayList<Rules> rules;
|
||||||
@SerializedName("url")
|
@SerializedName("url")
|
||||||
public String url;
|
public String url;
|
||||||
@SerializedName("natives")
|
@SerializedName("natives")
|
||||||
public Natives natives;
|
public Natives natives;
|
||||||
@SerializedName("extract")
|
@SerializedName("extract")
|
||||||
public Extract extract;
|
public Extract extract;
|
||||||
@SerializedName("downloads")
|
@SerializedName("downloads")
|
||||||
public LibrariesDownloadInfo downloads;
|
public LibrariesDownloadInfo downloads;
|
||||||
|
|
||||||
public MinecraftLibrary(String name) {
|
public MinecraftLibrary(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MinecraftLibrary(ArrayList<Rules> rules, String url, Natives natives, String name, Extract extract, LibraryDownloadInfo downloads) {
|
public MinecraftLibrary(ArrayList<Rules> rules, String url, Natives natives, String name, Extract extract, LibraryDownloadInfo downloads) {
|
||||||
super(name);
|
super(name);
|
||||||
this.rules = (rules == null) ? null : (ArrayList<Rules>) rules.clone();
|
this.rules = (rules == null) ? null : (ArrayList<Rules>) rules.clone();
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.natives = (natives == null) ? null : (Natives) natives.clone();
|
this.natives = (natives == null) ? null : (Natives) natives.clone();
|
||||||
this.extract = (extract == null) ? null : (Extract) extract.clone();
|
this.extract = (extract == null) ? null : (Extract) extract.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean allow() {
|
public boolean allow() {
|
||||||
if (rules != null) {
|
if (rules != null) {
|
||||||
boolean flag = false;
|
boolean flag = false;
|
||||||
for (Rules r : rules) {
|
for (Rules r : rules) {
|
||||||
if ("disallow".equals(r.action()))
|
if ("disallow".equals(r.action())) {
|
||||||
return false;
|
return false;
|
||||||
else if ("allow".equals(r.action()))
|
} else if ("allow".equals(r.action())) {
|
||||||
flag = true;
|
flag = true;
|
||||||
}
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String formatArch(String nati) {
|
|
||||||
return nati == null ? "" : nati.replace("${arch}", Platform.getPlatform().getBit());
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getNative() {
|
|
||||||
switch (OS.os()) {
|
|
||||||
case WINDOWS:
|
|
||||||
return formatArch(natives.windows);
|
|
||||||
case OSX:
|
|
||||||
return formatArch(natives.osx);
|
|
||||||
default:
|
|
||||||
return formatArch(natives.linux);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isRequiredToUnzip() {
|
|
||||||
return natives != null && allow();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String formatName() {
|
|
||||||
String[] s = name.split(":");
|
|
||||||
if (s.length < 3) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder(s[0].replace('.', '/')).append('/').append(s[1]).append('/').append(s[2]).append('/').append(s[1]).append('-').append(s[2]);
|
|
||||||
if (natives != null) {
|
|
||||||
sb.append('-').append(getNative());
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.append(".jar").toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public File getFilePath(File gameDir) {
|
|
||||||
LibraryDownloadInfo info = getDownloadInfo();
|
|
||||||
if (info == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new File(gameDir, "libraries/" + info.path);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Extract getDecompressExtractRules() {
|
|
||||||
return extract == null ? new Extract() : extract;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LibraryDownloadInfo getDownloadInfo() {
|
|
||||||
if (downloads == null) {
|
|
||||||
downloads = new LibrariesDownloadInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
LibraryDownloadInfo info = null;
|
|
||||||
if (natives != null) {
|
|
||||||
if (downloads.classifiers == null) {
|
|
||||||
downloads.classifiers = new HashMap<>();
|
|
||||||
} else {
|
|
||||||
if (!downloads.classifiers.containsKey(getNative())) {
|
|
||||||
downloads.classifiers.put(getNative(), info = new LibraryDownloadInfo());
|
|
||||||
} else {
|
|
||||||
info = downloads.classifiers.get(getNative());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (downloads.artifact == null) {
|
return flag;
|
||||||
downloads.artifact = info = new LibraryDownloadInfo();
|
|
||||||
} else {
|
|
||||||
info = downloads.artifact;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
if (StrUtils.isBlank(info.path)) {
|
}
|
||||||
info.path = formatName();
|
|
||||||
if (info.path == null) {
|
private String formatArch(String nati) {
|
||||||
return null;
|
return nati == null ? "" : nati.replace("${arch}", Platform.getPlatform().getBit());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getNative() {
|
||||||
|
switch (OS.os()) {
|
||||||
|
case WINDOWS:
|
||||||
|
return formatArch(natives.windows);
|
||||||
|
case OSX:
|
||||||
|
return formatArch(natives.osx);
|
||||||
|
default:
|
||||||
|
return formatArch(natives.linux);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isRequiredToUnzip() {
|
||||||
|
return natives != null && allow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String formatName() {
|
||||||
|
String[] s = name.split(":");
|
||||||
|
if (s.length < 3) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder(s[0].replace('.', '/')).append('/').append(s[1]).append('/').append(s[2]).append('/').append(s[1]).append('-').append(s[2]);
|
||||||
|
if (natives != null) {
|
||||||
|
sb.append('-').append(getNative());
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.append(".jar").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File getFilePath(File gameDir) {
|
||||||
|
LibraryDownloadInfo info = getDownloadInfo();
|
||||||
|
if (info == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new File(gameDir, "libraries/" + info.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Extract getDecompressExtractRules() {
|
||||||
|
return extract == null ? new Extract() : extract;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LibraryDownloadInfo getDownloadInfo() {
|
||||||
|
if (downloads == null) {
|
||||||
|
downloads = new LibrariesDownloadInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
LibraryDownloadInfo info = null;
|
||||||
|
if (natives != null) {
|
||||||
|
if (downloads.classifiers == null) {
|
||||||
|
downloads.classifiers = new HashMap<>();
|
||||||
}
|
}
|
||||||
}
|
if (!downloads.classifiers.containsKey(getNative())) {
|
||||||
|
downloads.classifiers.put(getNative(), info = new LibraryDownloadInfo());
|
||||||
info.forgeURL = this.url;
|
} else {
|
||||||
return info;
|
info = downloads.classifiers.get(getNative());
|
||||||
}
|
}
|
||||||
|
} else if (downloads.artifact == null) {
|
||||||
|
downloads.artifact = info = new LibraryDownloadInfo();
|
||||||
|
} else {
|
||||||
|
info = downloads.artifact;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StrUtils.isBlank(info.path)) {
|
||||||
|
info.path = formatName();
|
||||||
|
if (info.path == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
info.forgeURL = this.url;
|
||||||
|
return info;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user