fix: #801
This commit is contained in:
@@ -17,8 +17,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.game;
|
package org.jackhuang.hmcl.game;
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.util.Logging.LOG;
|
|
||||||
|
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import org.jackhuang.hmcl.util.gson.JsonUtils;
|
import org.jackhuang.hmcl.util.gson.JsonUtils;
|
||||||
@@ -35,19 +33,23 @@ import java.nio.file.FileSystem;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
|
import static org.jackhuang.hmcl.util.Lang.tryCast;
|
||||||
|
import static org.jackhuang.hmcl.util.Logging.LOG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author huangyuhui
|
* @author huangyuhui
|
||||||
*/
|
*/
|
||||||
public final class GameVersion {
|
public final class GameVersion {
|
||||||
private static Optional<String> getVersionFromJson(Path versionJson) {
|
private static Optional<String> getVersionFromJson(Path versionJson) {
|
||||||
try {
|
try {
|
||||||
MinecraftVersion version = JsonUtils.fromNonNullJson(FileUtils.readText(versionJson), MinecraftVersion.class);
|
Map<?, ?> version = JsonUtils.fromNonNullJson(FileUtils.readText(versionJson), Map.class);
|
||||||
return Optional.ofNullable(version.name);
|
return tryCast(version.get("name"), String.class);
|
||||||
} catch (IOException | JsonParseException e) {
|
} catch (IOException | JsonParseException e) {
|
||||||
LOG.log(Level.WARNING, "Failed to parse version.json", e);
|
LOG.log(Level.WARNING, "Failed to parse version.json", e);
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|||||||
@@ -278,13 +278,15 @@ public abstract class FetchTask<T> extends Task<T> {
|
|||||||
if (DOWNLOAD_EXECUTOR == null) {
|
if (DOWNLOAD_EXECUTOR == null) {
|
||||||
synchronized (Schedulers.class) {
|
synchronized (Schedulers.class) {
|
||||||
if (DOWNLOAD_EXECUTOR == null) {
|
if (DOWNLOAD_EXECUTOR == null) {
|
||||||
DOWNLOAD_EXECUTOR = new ThreadPoolExecutor(0, downloadExecutorConcurrency, 10, TimeUnit.SECONDS,
|
ThreadPoolExecutor executor = new ThreadPoolExecutor(downloadExecutorConcurrency, downloadExecutorConcurrency, 10, TimeUnit.SECONDS,
|
||||||
new LinkedBlockingQueue<>(),
|
new ArrayBlockingQueue<>(downloadExecutorConcurrency),
|
||||||
runnable -> {
|
runnable -> {
|
||||||
Thread thread = Executors.defaultThreadFactory().newThread(runnable);
|
Thread thread = Executors.defaultThreadFactory().newThread(runnable);
|
||||||
thread.setDaemon(true);
|
thread.setDaemon(true);
|
||||||
return thread;
|
return thread;
|
||||||
});
|
});
|
||||||
|
executor.allowCoreThreadTimeOut(true);
|
||||||
|
DOWNLOAD_EXECUTOR = executor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user