Fix #3223: 正确解析包含 hash 的版本号 (#3224)

* Fix #3223

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

* 添加日志

添加日志

* Update GameVersion.java

* Update GameVersion.java

* update

* update

* update

---------

Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
Zkitefly 2024-08-20 01:08:49 +08:00 committed by GitHub
parent 47cc9ebe2b
commit 95a1496389
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -35,7 +35,6 @@ import java.util.stream.StreamSupport;
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;
/**
@ -48,8 +47,11 @@ final class 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();
}