Skip to content

Commit

Permalink
Fix HMCL-dev#3223: 正确解析包含 hash 的版本号 (HMCL-dev#3224)
Browse files Browse the repository at this point in the history
* Fix HMCL-dev#3223

* 使用正则表达式删除内容

* 添加日志

添加日志

* Update GameVersion.java

* Update GameVersion.java

* update

* update

* update

---------

Co-authored-by: Glavo <[email protected]>
  • Loading branch information
zkitefly and Glavo authored Aug 19, 2024
1 parent 47cc9eb commit 95a1496
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import static org.jackhuang.hmcl.util.Lang.tryCast;
import static org.jackhuang.hmcl.util.logging.Logger.LOG;

/**
Expand All @@ -48,8 +47,11 @@ private GameVersion() {
private static Optional<String> getVersionFromJson(InputStream versionJson) {
try {
Map<?, ?> version = JsonUtils.fromNonNullJsonFully(versionJson, Map.class);
return tryCast(version.get("id"), String.class);
} catch (IOException | JsonParseException e) {
String id = (String) version.get("id");
if (id != null && id.contains(" / "))
id = id.substring(0, id.indexOf(" / "));
return Optional.ofNullable(id);
} catch (IOException | JsonParseException | ClassCastException e) {
LOG.warning("Failed to parse version.json", e);
return Optional.empty();
}
Expand Down

0 comments on commit 95a1496

Please sign in to comment.