Fixed not downloading when a library and an native library have the same name

This commit is contained in:
huangyuhui
2017-07-01 23:38:07 +08:00
parent 29f53d574c
commit 7d8a66b71a
7 changed files with 13 additions and 18 deletions

View File

@@ -37,8 +37,8 @@ public interface IMinecraftLibrary extends Cloneable {
File getFilePath(File gameDir); File getFilePath(File gameDir);
String getName(); String getName();
boolean isRequiredToUnzip(); boolean isNative();
String getDownloadURL(String downloadSource); String getDownloadURL(String downloadSource);

View File

@@ -46,7 +46,7 @@ public class MinecraftLoader extends AbstractMinecraftLoader {
StringBuilder library = new StringBuilder(""); StringBuilder library = new StringBuilder("");
ArrayList<MinecraftLibrary> opt = new ArrayList<>(); ArrayList<MinecraftLibrary> opt = new ArrayList<>();
for (MinecraftLibrary l : version.libraries) for (MinecraftLibrary l : version.libraries)
if (l.allow() && !l.isRequiredToUnzip()) { if (l.allow() && !l.isNative()) {
if (l.getName().toLowerCase(Locale.US).contains("optifine")) { if (l.getName().toLowerCase(Locale.US).contains("optifine")) {
opt.add(l); opt.add(l);
continue; continue;

View File

@@ -26,7 +26,7 @@ import org.jackhuang.hmcl.api.game.IMinecraftLibrary;
*/ */
public abstract class AbstractMinecraftLibrary implements IMinecraftLibrary { public abstract class AbstractMinecraftLibrary implements IMinecraftLibrary {
private String name; private final String name;
public AbstractMinecraftLibrary(String name) { public AbstractMinecraftLibrary(String name) {
this.name = name; this.name = name;

View File

@@ -84,7 +84,7 @@ public class MinecraftLibrary extends AbstractMinecraftLibrary {
} }
@Override @Override
public boolean isRequiredToUnzip() { public boolean isNative() {
return natives != null && allow(); return natives != null && allow();
} }
@@ -125,11 +125,7 @@ public class MinecraftLibrary extends AbstractMinecraftLibrary {
downloads.classifiers = new HashMap<>(); downloads.classifiers = new HashMap<>();
if (!downloads.classifiers.containsKey(getNative())) if (!downloads.classifiers.containsKey(getNative()))
downloads.classifiers.put(getNative(), info = new LibraryDownloadInfo()); downloads.classifiers.put(getNative(), info = new LibraryDownloadInfo());
else { else info = downloads.classifiers.get(getNative());
info = downloads.classifiers.get(getNative());
if (info == null)
info = new LibraryDownloadInfo();
}
} else { } else {
if (downloads.artifact == null) if (downloads.artifact == null)
downloads.artifact = new LibraryDownloadInfo(); downloads.artifact = new LibraryDownloadInfo();

View File

@@ -30,7 +30,7 @@ public class MinecraftOldLibrary extends MinecraftLibrary {
} }
@Override @Override
public boolean isRequiredToUnzip() { public boolean isNative() {
return false; return false;
} }

View File

@@ -21,8 +21,10 @@ import org.jackhuang.hmcl.api.game.IMinecraftLibrary;
import com.google.gson.annotations.SerializedName; import com.google.gson.annotations.SerializedName;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@@ -164,8 +166,7 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
} }
public File getNatives(File gameDir) { public File getNatives(File gameDir) {
return new File(gameDir, "versions/" + id + "/" + id return new File(gameDir, "versions/" + id + "/" + id + "-natives");
+ "-natives");
} }
public boolean isAllowedToUnpackNatives() { public boolean isAllowedToUnpackNatives() {
@@ -193,8 +194,6 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
return Objects.equals(this.id, ((MinecraftVersion) obj).id); return Objects.equals(this.id, ((MinecraftVersion) obj).id);
} }
public AssetIndexDownloadInfo getAssetsIndex() { public AssetIndexDownloadInfo getAssetsIndex() {
if (assetIndex == null) if (assetIndex == null)
assetIndex = new AssetIndexDownloadInfo(assets == null ? AssetsIndex.DEFAULT_ASSET_NAME : assets); assetIndex = new AssetIndexDownloadInfo(assets == null ? AssetsIndex.DEFAULT_ASSET_NAME : assets);
@@ -212,7 +211,7 @@ public class MinecraftVersion implements Cloneable, Comparable<MinecraftVersion>
return i; return i;
} }
public Set<IMinecraftLibrary> getLibraries() { public List<IMinecraftLibrary> getLibraries() {
return libraries == null ? new HashSet<>() : new HashSet<>(libraries); return libraries == null ? new LinkedList<>() : Collections.unmodifiableList(libraries);
} }
} }

View File

@@ -248,7 +248,7 @@ public class MinecraftVersionManager<T extends IMinecraftService> extends IMinec
ArrayList<File> unzippings = new ArrayList<>(); ArrayList<File> unzippings = new ArrayList<>();
ArrayList<Extract> extractRules = new ArrayList<>(); ArrayList<Extract> extractRules = new ArrayList<>();
for (IMinecraftLibrary l : v.libraries) for (IMinecraftLibrary l : v.libraries)
if (l.isRequiredToUnzip() && v.isAllowedToUnpackNatives()) { if (l.isNative() && v.isAllowedToUnpackNatives()) {
unzippings.add(getLibraryFile(v, l)); unzippings.add(getLibraryFile(v, l));
extractRules.add(l.getDecompressExtractRules()); extractRules.add(l.getDecompressExtractRules());
} }