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)
.thenComposeAsync(javaVersion -> {
javaVersionRef.set(Objects.requireNonNull(javaVersion));
return dependencyManager.checkPatchCompletionAsync(repository.getVersion(selectedVersion), integrityCheck);
})
.thenComposeAsync(Task.allOf(
Task.composeAsync(() -> {
if (setting.isNotCheckGame())
return null;
else
return dependencyManager.checkGameCompletionAsync(version, integrityCheck);
}), Task.composeAsync(() -> {
if (setting.isNotCheckGame()) {
return null;
} else {
if (setting.isNotCheckGame())
return null;
return Task.allOf(
dependencyManager.checkGameCompletionAsync(version, integrityCheck),
Task.composeAsync(() -> {
try {
ModpackConfiguration<?> configuration = ModpackHelper.readModpackConfiguration(repository.getModpackConfiguration(selectedVersion));
ModpackProvider provider = ModpackHelper.getProviderByType(configuration.getType());
@@ -154,8 +148,9 @@ public final class LauncherHelper {
} catch (IOException e) {
return null;
}
}
}))).withStage("launch.state.dependencies")
})
);
}).withStage("launch.state.dependencies")
.thenComposeAsync(() -> {
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.GameLibrariesTask;
import org.jackhuang.hmcl.download.optifine.OptiFineInstallTask;
import org.jackhuang.hmcl.game.Artifact;
import org.jackhuang.hmcl.game.DefaultGameRepository;
import org.jackhuang.hmcl.game.Library;
import org.jackhuang.hmcl.game.Version;
@@ -32,11 +33,8 @@ import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import static org.jackhuang.hmcl.download.LibraryAnalyzer.LibraryType.OPTIFINE;
/**
* Note: This class has no state.
*
@@ -75,8 +73,7 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
}
@Override
public Task<?> checkGameCompletionAsync(Version original, boolean integrityCheck) {
Version version = original.resolve(repository);
public Task<?> checkGameCompletionAsync(Version version, boolean integrityCheck) {
return Task.allOf(
Task.composeAsync(() -> {
File versionJar = repository.getVersionJar(version);
@@ -84,7 +81,7 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
return new GameDownloadTask(this, null, version);
else
return null;
}),
}).thenComposeAsync(checkPatchCompletionAsync(version, integrityCheck)),
new GameAssetDownloadTask(this, version, GameAssetDownloadTask.DOWNLOAD_INDEX_IF_NECESSARY, integrityCheck),
new GameLibrariesTask(this, version, integrityCheck)
);
@@ -98,33 +95,36 @@ public class DefaultDependencyManager extends AbstractDependencyManager {
@Override
public Task<?> checkPatchCompletionAsync(Version version, boolean integrityCheck) {
return Task.composeAsync(() -> {
List<Task<?>> tasks = new ArrayList<>();
List<Task<?>> tasks = new ArrayList<>(0);
Optional<String> gameVersion = repository.getGameVersion(version);
if (!gameVersion.isPresent()) return null;
String gameVersion = repository.getGameVersion(version).orElse(null);
if (gameVersion == null) return null;
LibraryAnalyzer analyzer = LibraryAnalyzer.analyze(version.resolvePreservingPatches(getGameRepository()));
for (LibraryAnalyzer.LibraryType type : LibraryAnalyzer.LibraryType.values()) {
Optional<Library> library = analyzer.getLibrary(type);
if (library.isPresent() && GameLibrariesTask.shouldDownloadLibrary(repository, version, library.get(), integrityCheck)) {
tasks.add(downloadMissingLibraryAsync(gameVersion.get(), version, type, library.get()));
Version original = repository.getVersion(version.getId());
Version resolved = original.resolvePreservingPatches(repository);
// OptiFine
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);
});
}
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
public Task<Version> installLibraryAsync(String gameVersion, Version baseVersion, String libraryId, String libraryVersion) {
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);
/**
* Check if the game is complete.
* Check libraries, assets files and so on.
* Check if libraries of this version in complete.
* If not, download missing libraries if possible.
*
* @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 -> {
File file = dependencyManager.getGameRepository().getLibraryFile(version, library);
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 {
dependencyManager.getCacheRepository().tryCacheLibrary(library, file.toPath());
}