Skip to content

Commit

Permalink
Fix HMCL-dev#3540: MultiMC json-patch native data.
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtnt committed Jan 27, 2025
1 parent f655bba commit 303bdb8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
39 changes: 31 additions & 8 deletions HMCLCore/src/main/java/org/jackhuang/hmcl/game/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
*/
package org.jackhuang.hmcl.game;

import com.google.gson.*;
import com.google.gson.JsonParseException;
import com.google.gson.annotations.SerializedName;
import org.jackhuang.hmcl.util.Constants;
import org.jackhuang.hmcl.util.Immutable;
import org.jackhuang.hmcl.util.ToStringBuilder;
import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.gson.TolerableValidationException;
import org.jackhuang.hmcl.util.gson.Validation;
import org.jackhuang.hmcl.util.platform.Architecture;
Expand All @@ -46,7 +47,7 @@ public class Library implements Comparable<Library>, Validation {
private final String url;
private final LibrariesDownloadInfo downloads;
private final ExtractRules extract;
private final Map<OperatingSystem, String> natives;
private final Map<String, String> natives;
private final List<CompatibilityRule> rules;
private final List<String> checksums;

Expand All @@ -64,7 +65,7 @@ public Library(Artifact artifact, String url, LibrariesDownloadInfo downloads) {
this(artifact, url, downloads, null, null, null, null, null, null);
}

public Library(Artifact artifact, String url, LibrariesDownloadInfo downloads, List<String> checksums, ExtractRules extract, Map<OperatingSystem, String> natives, List<CompatibilityRule> rules, String hint, String filename) {
public Library(Artifact artifact, String url, LibrariesDownloadInfo downloads, List<String> checksums, ExtractRules extract, Map<String, String> natives, List<CompatibilityRule> rules, String hint, String filename) {
this.artifact = artifact;
this.url = url;
this.downloads = downloads;
Expand Down Expand Up @@ -93,13 +94,33 @@ public String getVersion() {
}

public String getClassifier() {
if (artifact.getClassifier() == null)
if (natives != null && natives.containsKey(OperatingSystem.CURRENT_OS))
return natives.get(OperatingSystem.CURRENT_OS).replace("${arch}", Architecture.SYSTEM_ARCH.getBits().getBit());
else
if (artifact.getClassifier() == null) {
if (natives == null) {
return null;
else
}

String current = natives.get(OperatingSystem.CURRENT_OS.getCheckedName());
if (current == null) {
for (String value : natives.values()) {
int i = value.indexOf('-');
if (i == -1) {
continue;
}

Architecture architecture = JsonUtils.GSON.fromJson(value.substring(i + 1), Architecture.class);
if (architecture == Architecture.SYSTEM_ARCH) {
current = natives.get(value);
break;
}
}
}
if (current == null) {
return null;
}
return current.replace("${arch}", Architecture.SYSTEM_ARCH.getBits().getBit());
} else {
return artifact.getClassifier();
}
}

public ExtractRules getExtract() {
Expand Down Expand Up @@ -159,6 +180,7 @@ public List<CompatibilityRule> getRules() {

/**
* Hint for how to locate the library file.
*
* @return null for default, "local" for location in version/&lt;version&gt;/libraries/filename
*/
@Nullable
Expand All @@ -168,6 +190,7 @@ public String getHint() {

/**
* Available when hint is "local"
*
* @return the filename of the local library in version/&lt;version&gt;/libraries/$filename
*/
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Immutable
public class TLauncherLibrary {
Expand Down Expand Up @@ -58,7 +59,9 @@ public Library toLibrary() {
new LibrariesDownloadInfo(artifact, classifiers),
checksums,
extract,
natives,
natives.entrySet().stream().collect(Collectors.toMap(
entry -> entry.getKey().getCheckedName(), Map.Entry::getValue
)),
rules,
null,
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void execute() throws Exception {
try {
multiMCPatch = JsonUtils.GSON.fromJson(FileUtils.readText(patchJson), MultiMCInstancePatch.class);
} catch (JsonParseException e) {
throw new IllegalArgumentException("Cannot parse MultiMC patch json: " + patchJson);
throw new IllegalArgumentException("Cannot parse MultiMC patch json: " + patchJson, e);
}

List<String> arguments = new ArrayList<>();
Expand Down

0 comments on commit 303bdb8

Please sign in to comment.