fix #1311: fix auto complete OptiFine

This commit is contained in:
Glavo
2022-01-25 05:00:09 +08:00
committed by Yuhui Huang
parent a237a31d23
commit 7c502ecd01
4 changed files with 38 additions and 42 deletions

View File

@@ -134,18 +134,12 @@ public final class LauncherHelper {
TaskExecutor executor = checkGameState(profile, setting, version) TaskExecutor executor = checkGameState(profile, setting, version)
.thenComposeAsync(javaVersion -> { .thenComposeAsync(javaVersion -> {
javaVersionRef.set(Objects.requireNonNull(javaVersion)); javaVersionRef.set(Objects.requireNonNull(javaVersion));
return dependencyManager.checkPatchCompletionAsync(repository.getVersion(selectedVersion), integrityCheck); if (setting.isNotCheckGame())
}) return null;
.thenComposeAsync(Task.allOf(
Task.composeAsync(() -> { return Task.allOf(
if (setting.isNotCheckGame()) dependencyManager.checkGameCompletionAsync(version, integrityCheck),
return null; Task.composeAsync(() -> {
else
return dependencyManager.checkGameCompletionAsync(version, integrityCheck);
}), Task.composeAsync(() -> {
if (setting.isNotCheckGame()) {
return null;
} else {
try { try {
ModpackConfiguration<?> configuration = ModpackHelper.readModpackConfiguration(repository.getModpackConfiguration(selectedVersion)); ModpackConfiguration<?> configuration = ModpackHelper.readModpackConfiguration(repository.getModpackConfiguration(selectedVersion));
ModpackProvider provider = ModpackHelper.getProviderByType(configuration.getType()); ModpackProvider provider = ModpackHelper.getProviderByType(configuration.getType());
@@ -154,8 +148,9 @@ public final class LauncherHelper {
} catch (IOException e) { } catch (IOException e) {
return null; return null;
} }
} })
}))).withStage("launch.state.dependencies") );
}).withStage("launch.state.dependencies")
.thenComposeAsync(() -> { .thenComposeAsync(() -> {
return gameVersion.map(s -> new GameVerificationFixTask(dependencyManager, s, version)).orElse(null); return gameVersion.map(s -> new GameVerificationFixTask(dependencyManager, s, version)).orElse(null);
}) })

View File

@@ -22,6 +22,7 @@ import org.jackhuang.hmcl.download.game.GameAssetDownloadTask;
import org.jackhuang.hmcl.download.game.GameDownloadTask; import org.jackhuang.hmcl.download.game.GameDownloadTask;
import org.jackhuang.hmcl.download.game.GameLibrariesTask; import org.jackhuang.hmcl.download.game.GameLibrariesTask;
import org.jackhuang.hmcl.download.optifine.OptiFineInstallTask; import org.jackhuang.hmcl.download.optifine.OptiFineInstallTask;
import org.jackhuang.hmcl.game.Artifact;
import org.jackhuang.hmcl.game.DefaultGameRepository; import org.jackhuang.hmcl.game.DefaultGameRepository;
import org.jackhuang.hmcl.game.Library; import org.jackhuang.hmcl.game.Library;
import org.jackhuang.hmcl.game.Version; import org.jackhuang.hmcl.game.Version;
@@ -32,11 +33,8 @@ import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static org.jackhuang.hmcl.download.LibraryAnalyzer.LibraryType.OPTIFINE;
/** /**
* Note: This class has no state. * Note: This class has no state.
* *
@@ -75,8 +73,7 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
} }
@Override @Override
public Task<?> checkGameCompletionAsync(Version original, boolean integrityCheck) { public Task<?> checkGameCompletionAsync(Version version, boolean integrityCheck) {
Version version = original.resolve(repository);
return Task.allOf( return Task.allOf(
Task.composeAsync(() -> { Task.composeAsync(() -> {
File versionJar = repository.getVersionJar(version); File versionJar = repository.getVersionJar(version);
@@ -84,7 +81,7 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
return new GameDownloadTask(this, null, version); return new GameDownloadTask(this, null, version);
else else
return null; return null;
}), }).thenComposeAsync(checkPatchCompletionAsync(version, integrityCheck)),
new GameAssetDownloadTask(this, version, GameAssetDownloadTask.DOWNLOAD_INDEX_IF_NECESSARY, integrityCheck), new GameAssetDownloadTask(this, version, GameAssetDownloadTask.DOWNLOAD_INDEX_IF_NECESSARY, integrityCheck),
new GameLibrariesTask(this, version, integrityCheck) new GameLibrariesTask(this, version, integrityCheck)
); );
@@ -98,33 +95,36 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
@Override @Override
public Task<?> checkPatchCompletionAsync(Version version, boolean integrityCheck) { public Task<?> checkPatchCompletionAsync(Version version, boolean integrityCheck) {
return Task.composeAsync(() -> { return Task.composeAsync(() -> {
List<Task<?>> tasks = new ArrayList<>(); List<Task<?>> tasks = new ArrayList<>(0);
Optional<String> gameVersion = repository.getGameVersion(version); String gameVersion = repository.getGameVersion(version).orElse(null);
if (!gameVersion.isPresent()) return null; if (gameVersion == null) return null;
LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(version.resolvePreservingPatches(getGameRepository())); Version original = repository.getVersion(version.getId());
for (LibraryAnalyzer.LibraryType type : LibraryAnalyzer.LibraryType.values()) { Version resolved = original.resolvePreservingPatches(repository);
Optional<Library> library = analyzer.getLibrary(type);
if (library.isPresent() && GameLibrariesTask.shouldDownloadLibrary(repository, version, library.get(), integrityCheck)) { // OptiFine
tasks.add(downloadMissingLibraryAsync(gameVersion.get(), version, type, library.get())); String optifineVersion = resolved.getPatches().stream()
.filter(patch -> "optifine".equals(patch.getId()))
.findAny()
.filter(optifine -> optifine.getLibraries().stream()
.anyMatch(library -> GameLibrariesTask.shouldDownloadLibrary(repository, version, library, integrityCheck)))
.map(Version::getVersion)
.orElse(null);
if (optifineVersion != null) {
Library installer = new Library(new Artifact("optifine", "OptiFine", gameVersion + "_" + optifineVersion, "installer"));
if (GameLibrariesTask.shouldDownloadLibrary(repository, original, installer, integrityCheck)) {
tasks.add(installLibraryAsync(gameVersion, original, "optifine", optifineVersion));
} else {
tasks.add(OptiFineInstallTask.install(this, original, repository.getLibraryFile(version, installer).toPath()));
} }
} }
return Task.allOf(tasks); return Task.allOf(tasks);
}); });
} }
private Task<?> downloadMissingLibraryAsync(String gameVersion, Version version, LibraryAnalyzer.LibraryType libraryType, Library library) {
switch (libraryType) {
case OPTIFINE:
if (library.hasDownloadURL())
break;
return installLibraryAsync(gameVersion, version, libraryType.getPatchId(), library.getVersion());
}
return Task.completed(null);
}
@Override @Override
public Task<Version> installLibraryAsync(String gameVersion, Version baseVersion, String libraryId, String libraryVersion) { public Task<Version> installLibraryAsync(String gameVersion, Version baseVersion, String libraryId, String libraryVersion) {
if (baseVersion.isResolved()) throw new IllegalArgumentException("Version should not be resolved"); if (baseVersion.isResolved()) throw new IllegalArgumentException("Version should not be resolved");

View File

@@ -49,8 +49,8 @@ public interface DependencyManager {
Task<?> checkGameCompletionAsync(Version version, boolean integrityCheck); Task<?> checkGameCompletionAsync(Version version, boolean integrityCheck);
/** /**
* Check if the game is complete. * Check if libraries of this version in complete.
* Check libraries, assets files and so on. * If not, download missing libraries if possible.
* *
* @return the task to check game completion. * @return the task to check game completion.
*/ */

View File

@@ -109,7 +109,8 @@ public final class GameLibrariesTask extends Task<Void> {
libraries.stream().filter(Library::appliesToCurrentEnvironment).forEach(library -> { libraries.stream().filter(Library::appliesToCurrentEnvironment).forEach(library -> {
File file = dependencyManager.getGameRepository().getLibraryFile(version, library); File file = dependencyManager.getGameRepository().getLibraryFile(version, library);
if (shouldDownloadLibrary(dependencyManager.getGameRepository(), version, library, integrityCheck)) { if (shouldDownloadLibrary(dependencyManager.getGameRepository(), version, library, integrityCheck)) {
dependencies.add(new LibraryDownloadTask(dependencyManager, file, library)); if (library.hasDownloadURL() || !"optifine".equals(library.getGroupId()))
dependencies.add(new LibraryDownloadTask(dependencyManager, file, library));
} else { } else {
dependencyManager.getCacheRepository().tryCacheLibrary(library, file.toPath()); dependencyManager.getCacheRepository().tryCacheLibrary(library, file.toPath());
} }