mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-03-07 17:36:52 +08:00
Fasten versions loading
This commit is contained in:
parent
2ae00db94b
commit
20244fe5cc
@ -43,18 +43,16 @@ import org.jackhuang.hmcl.task.Schedulers;
|
|||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
import org.jackhuang.hmcl.task.TaskExecutor;
|
import org.jackhuang.hmcl.task.TaskExecutor;
|
||||||
import org.jackhuang.hmcl.ui.construct.MessageBox;
|
import org.jackhuang.hmcl.ui.construct.MessageBox;
|
||||||
import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane;
|
|
||||||
import org.jackhuang.hmcl.ui.download.DownloadWizardProvider;
|
import org.jackhuang.hmcl.ui.download.DownloadWizardProvider;
|
||||||
import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
|
import org.jackhuang.hmcl.ui.wizard.DecoratorPage;
|
||||||
import org.jackhuang.hmcl.util.Lang;
|
import org.jackhuang.hmcl.util.Lang;
|
||||||
import org.jackhuang.hmcl.util.OperatingSystem;
|
import org.jackhuang.hmcl.util.OperatingSystem;
|
||||||
import org.jackhuang.hmcl.util.StringUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import static org.jackhuang.hmcl.util.StringUtils.removePrefix;
|
import static org.jackhuang.hmcl.util.StringUtils.removePrefix;
|
||||||
@ -106,28 +104,31 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
return removeSuffix(removePrefix(removeSuffix(removePrefix(version.replace(gameVersion, "").trim(), "-"), "-"), "_"), "_");
|
return removeSuffix(removePrefix(removeSuffix(removePrefix(version.replace(gameVersion, "").trim(), "-"), "-"), "_"), "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node buildNode(HMCLGameRepository repository, Version version, String game) {
|
private Node buildNode(HMCLGameRepository repository, Version version, Callable<String> gameCallable) {
|
||||||
Profile profile = repository.getProfile();
|
Profile profile = repository.getProfile();
|
||||||
String id = version.getId();
|
String id = version.getId();
|
||||||
VersionItem item = new VersionItem();
|
VersionItem item = new VersionItem();
|
||||||
item.setUpdate(repository.isModpack(id));
|
item.setUpdate(repository.isModpack(id));
|
||||||
item.setGameVersion(game);
|
Task.ofResult("game", gameCallable).subscribe(Schedulers.javafx(), vars -> {
|
||||||
|
String game = vars.get("game");
|
||||||
|
item.setGameVersion(game);
|
||||||
|
|
||||||
|
StringBuilder libraries = new StringBuilder();
|
||||||
|
for (Library library : version.getLibraries()) {
|
||||||
|
if (library.getGroupId().equalsIgnoreCase("net.minecraftforge") && library.getArtifactId().equalsIgnoreCase("forge")) {
|
||||||
|
libraries.append(Launcher.i18n("install.installer.forge")).append(": ").append(modifyVersion(game, library.getVersion().replaceAll("(?i)forge", ""))).append("\n");
|
||||||
|
}
|
||||||
|
if (library.getGroupId().equalsIgnoreCase("com.mumfrey") && library.getArtifactId().equalsIgnoreCase("liteloader")) {
|
||||||
|
libraries.append(Launcher.i18n("install.installer.liteloader")).append(": ").append(modifyVersion(game, library.getVersion().replaceAll("(?i)liteloader", ""))).append("\n");
|
||||||
|
}
|
||||||
|
if (library.getGroupId().equalsIgnoreCase("net.optifine") && library.getArtifactId().equalsIgnoreCase("optifine")) {
|
||||||
|
libraries.append(Launcher.i18n("install.installer.optifine")).append(": ").append(modifyVersion(game, library.getVersion().replaceAll("(?i)optifine", ""))).append("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
item.setLibraries(libraries.toString());
|
||||||
|
});
|
||||||
item.setVersionName(id);
|
item.setVersionName(id);
|
||||||
|
|
||||||
StringBuilder libraries = new StringBuilder();
|
|
||||||
for (Library library : version.getLibraries()) {
|
|
||||||
if (library.getGroupId().equalsIgnoreCase("net.minecraftforge") && library.getArtifactId().equalsIgnoreCase("forge")) {
|
|
||||||
libraries.append(Launcher.i18n("install.installer.forge")).append(": ").append(modifyVersion(game, library.getVersion().replaceAll("(?i)forge", ""))).append("\n");
|
|
||||||
}
|
|
||||||
if (library.getGroupId().equalsIgnoreCase("com.mumfrey") && library.getArtifactId().equalsIgnoreCase("liteloader")) {
|
|
||||||
libraries.append(Launcher.i18n("install.installer.liteloader")).append(": ").append(modifyVersion(game, library.getVersion().replaceAll("(?i)liteloader", ""))).append("\n");
|
|
||||||
}
|
|
||||||
if (library.getGroupId().equalsIgnoreCase("net.optifine") && library.getArtifactId().equalsIgnoreCase("optifine")) {
|
|
||||||
libraries.append(Launcher.i18n("install.installer.optifine")).append(": ").append(modifyVersion(game, library.getVersion().replaceAll("(?i)optifine", ""))).append("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
item.setLibraries(libraries.toString());
|
|
||||||
item.setOnLaunchButtonClicked(e -> {
|
item.setOnLaunchButtonClicked(e -> {
|
||||||
if (Settings.INSTANCE.getSelectedAccount() == null)
|
if (Settings.INSTANCE.getSelectedAccount() == null)
|
||||||
Controllers.getLeftPaneController().checkAccount();
|
Controllers.getLeftPaneController().checkAccount();
|
||||||
@ -230,7 +231,7 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
|||||||
private void loadVersions(HMCLGameRepository repository) {
|
private void loadVersions(HMCLGameRepository repository) {
|
||||||
List<Node> children = new LinkedList<>();
|
List<Node> children = new LinkedList<>();
|
||||||
for (Version version : repository.getVersions()) {
|
for (Version version : repository.getVersions()) {
|
||||||
children.add(buildNode(repository, version, GameVersion.minecraftVersion(repository.getVersionJar(version.getId())).orElse("Unknown")));
|
children.add(buildNode(repository, version, () -> GameVersion.minecraftVersion(repository.getVersionJar(version.getId())).orElse("Unknown")));
|
||||||
}
|
}
|
||||||
JFXUtilities.runInFX(() -> {
|
JFXUtilities.runInFX(() -> {
|
||||||
if (profile == repository.getProfile()) {
|
if (profile == repository.getProfile()) {
|
||||||
|
@ -89,10 +89,8 @@ public final class TaskExecutor {
|
|||||||
|
|
||||||
while (!workerQueue.isEmpty()) {
|
while (!workerQueue.isEmpty()) {
|
||||||
Future<?> future = workerQueue.poll();
|
Future<?> future = workerQueue.poll();
|
||||||
if (future != null) {
|
if (future != null)
|
||||||
future.cancel(true);
|
future.cancel(true);
|
||||||
System.out.println("Canceled " + future);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user