fix: cannot rename game version sometimes

This commit is contained in:
huanghongxun
2020-04-17 23:45:15 +08:00
parent 99f42db370
commit 5893eae87f
8 changed files with 110 additions and 80 deletions

View File

@@ -59,6 +59,7 @@ import java.util.Locale;
import java.util.Optional;
import java.util.Random;
import java.util.logging.Level;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
@@ -170,9 +171,9 @@ public class DecoratorController {
}
List<Path> candidates;
try {
candidates = Files.list(imageDir)
.filter(Files::isRegularFile)
try (Stream<Path> stream = Files.list(imageDir)) {
candidates = stream
.filter(Files::isRegularFile)
.filter(it -> {
String filename = it.getFileName().toString();
return filename.endsWith(".png") || filename.endsWith(".jpg");

View File

@@ -43,6 +43,7 @@ import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
@@ -69,7 +70,7 @@ public class WorldListPage extends ListPageBase<WorldListItem> {
}
@Override
protected ToolbarListPageSkin createDefaultSkin() {
protected ToolbarListPageSkin<WorldListPage> createDefaultSkin() {
return new WorldListPageSkin();
}
@@ -87,7 +88,11 @@ public class WorldListPage extends ListPageBase<WorldListItem> {
setLoading(true);
return CompletableFuture
.runAsync(() -> gameVersion = GameVersion.minecraftVersion(profile.getRepository().getVersionJar(id)).orElse(null))
.thenApplyAsync(unused -> World.getWorlds(savesDir).parallel().collect(Collectors.toList()))
.thenApplyAsync(unused -> {
try (Stream<World> stream = World.getWorlds(savesDir)) {
return stream.parallel().collect(Collectors.toList());
}
})
.whenCompleteAsync((result, exception) -> {
worlds = result;
setLoading(false);