fix: compatibility issue with other launchers using auto-installation

This commit is contained in:
huanghongxun 2020-03-06 12:23:34 +08:00
parent 7260ae9b5e
commit 7b6a96b4b6
4 changed files with 29 additions and 8 deletions

2
.gitignore vendored
View File

@ -34,3 +34,5 @@ NVIDIA
# netbeans
.nb-gradle
*.exe

View File

@ -70,6 +70,13 @@ public class MaintainTask extends Task<Version> {
}
}
public static Version maintainPreservingPatches(GameRepository repository, Version version) {
if (!version.isResolvedPreservingPatches())
throw new IllegalArgumentException("MaintainTask requires independent game version");
Version newVersion = maintain(repository, version.resolve(repository));
return newVersion.setPatches(version.getPatches()).markAsUnresolved();
}
private static Version maintainGameWithLaunchWrapper(Version version) {
LibraryAnalyzer libraryAnalyzer = LibraryAnalyzer.analyze(version);
VersionLibraryBuilder builder = new VersionLibraryBuilder(version);

View File

@ -18,6 +18,7 @@
package org.jackhuang.hmcl.game;
import com.google.gson.JsonParseException;
import org.jackhuang.hmcl.download.MaintainTask;
import org.jackhuang.hmcl.download.game.VersionJsonSaveTask;
import org.jackhuang.hmcl.event.Event;
import org.jackhuang.hmcl.event.EventBus;
@ -393,7 +394,11 @@ public class DefaultGameRepository implements GameRepository {
}
public Task<Version> save(Version version) {
return new VersionJsonSaveTask(this, version);
if (version.isResolvedPreservingPatches()) {
return new VersionJsonSaveTask(this, MaintainTask.maintainPreservingPatches(this, version));
} else {
return new VersionJsonSaveTask(this, version);
}
}
public boolean isLoaded() {

View File

@ -223,7 +223,7 @@ public class Version implements Comparable<Version>, Validation {
*/
public Version resolve(VersionProvider provider) throws VersionNotFoundException {
if (isResolved()) return this;
return resolve(provider, new HashSet<>()).setResolved();
return resolve(provider, new HashSet<>()).markAsResolved();
}
protected Version merge(Version parent, boolean isPatch) {
@ -243,12 +243,12 @@ public class Version implements Comparable<Version>, Validation {
Lang.merge(parent.compatibilityRules, this.compatibilityRules),
downloads == null ? parent.downloads : downloads,
logging == null ? parent.logging : logging,
type,
time,
releaseTime,
type == null ? parent.type : type,
time == null ? parent.time : time,
releaseTime == null ? parent.releaseTime : releaseTime,
Lang.merge(minimumLauncherVersion, parent.minimumLauncherVersion, Math::max),
hidden,
false,
true,
isPatch ? parent.patches : Lang.merge(Lang.merge(parent.patches, Collections.singleton(toPatch())), patches));
}
@ -256,7 +256,10 @@ public class Version implements Comparable<Version>, Validation {
Version thisVersion;
if (inheritsFrom == null) {
thisVersion = this.jar == null ? this.setJar(id) : this;
if (isRoot())
thisVersion = new Version(id).setJar(id);
else
thisVersion = this.jar == null ? this.setJar(id) : this;
} else {
// To maximize the compatibility.
if (!resolvedSoFar.add(id)) {
@ -315,10 +318,14 @@ public class Version implements Comparable<Version>, Validation {
return thisVersion.setId(id);
}
private Version setResolved() {
private Version markAsResolved() {
return new Version(true, id, version, priority, minecraftArguments, arguments, mainClass, inheritsFrom, jar, assetIndex, assets, libraries, compatibilityRules, downloads, logging, type, time, releaseTime, minimumLauncherVersion, hidden, root, patches);
}
public Version markAsUnresolved() {
return new Version(false, id, version, priority, minecraftArguments, arguments, mainClass, inheritsFrom, jar, assetIndex, assets, libraries, compatibilityRules, downloads, logging, type, time, releaseTime, minimumLauncherVersion, hidden, root, patches);
}
private Version setHidden(Boolean hidden) {
return new Version(true, id, version, priority, minecraftArguments, arguments, mainClass, inheritsFrom, jar, assetIndex, assets, libraries, compatibilityRules, downloads, logging, type, time, releaseTime, minimumLauncherVersion, hidden, root, patches);
}