Skip to content

Commit

Permalink
Forbid user from installing both Forge 1.13 and OptiFine simultaneously
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghongxun committed Mar 4, 2019
1 parent 266c686 commit 5b30617
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jackhuang.hmcl.download.LibraryAnalyzer;
import org.jackhuang.hmcl.download.RemoteVersion;
import org.jackhuang.hmcl.download.game.LibraryDownloadException;
import org.jackhuang.hmcl.download.optifine.OptiFineInstallTask;
import org.jackhuang.hmcl.game.Library;
import org.jackhuang.hmcl.game.Version;
import org.jackhuang.hmcl.setting.Profile;
Expand Down Expand Up @@ -125,6 +126,8 @@ public static void alertFailureMessage(Exception exception, Runnable next) {
Controllers.dialog(i18n("launch.failed.download_library", ((LibraryDownloadException) exception).getLibrary().getName()) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageType.ERROR, next);
} else if (exception instanceof DownloadException) {
Controllers.dialog(i18n("install.failed.downloading.detail", ((DownloadException) exception).getUrl()) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageType.ERROR, next);
} else if (exception instanceof OptiFineInstallTask.UnsupportedOptiFineInstallationException) {
Controllers.dialog(i18n("install.failed.optifine_conflict"), i18n("install.failed"), MessageType.ERROR, next);
} else {
Controllers.dialog(StringUtils.getStackTrace(exception), i18n("install.failed"), MessageType.ERROR, next);
}
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N.properties
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ install=Install New Game
install.failed=Failed to install
install.failed.downloading=Failed to install due to some files not downloaded successfully
install.failed.downloading.detail=Failed to download file: %s
install.failed.optifine_conflict=OptiFine and Forge are both installed simultaneously on Minecraft 1.13
install.installer.choose=Choose a %s version
install.installer.forge=Forge
install.installer.game=Game
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ install=新增遊戲
install.failed=安裝失敗
install.failed.downloading=安裝失敗,部分文件未能完成下載
install.failed.downloading.detail=未能下載檔案:%s
install.failed.optifine_conflict=暫不支持 OptiFine 與 Forge 同時安裝於 Minecraft 1.13
install.installer.choose=選擇 %s 版本
install.installer.forge=Forge
install.installer.game=遊戲
Expand Down
1 change: 1 addition & 0 deletions HMCL/src/main/resources/assets/lang/I18N_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ install=添加游戏
install.failed=安装失败
install.failed.downloading=安装失败,部分文件未能完成下载
install.failed.downloading.detail=未能下载文件:%s
install.failed.optifine_conflict=暂不支持 OptiFine 与 Forge 同时安装于 Minecraft 1.13
install.installer.choose=选择 %s 版本
install.installer.forge=Forge
install.installer.game=游戏
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ public Collection<Task> getDependencies() {
return Collections.singleton(dependency);
}

@Override
public boolean isRelyingOnDependencies() {
return false;
}

@Override
public void execute() {
if (VersionNumber.VERSION_COMPARATOR.compare("1.13", remote.getGameVersion()) <= 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.jackhuang.hmcl.download.DefaultDependencyManager;
import org.jackhuang.hmcl.download.game.GameLibrariesTask;
import org.jackhuang.hmcl.download.optifine.OptiFineInstallTask;
import org.jackhuang.hmcl.game.*;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.task.TaskResult;
Expand Down Expand Up @@ -122,6 +123,9 @@ public void preExecute() throws Exception {

@Override
public void execute() throws Exception {
if ("net.minecraft.launchwrapper.Launch".equals(version.getMainClass()))
throw new OptiFineInstallTask.UnsupportedOptiFineInstallationException();

Path temp = Files.createTempDirectory("forge_installer");
int finished = 0;
try (FileSystem fs = CompressingUtils.createReadOnlyZipFileSystem(installer)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public boolean isRelyingOnDependencies() {

@Override
public void execute() {
if ("cpw.mods.modlauncher.Launcher".equals(version.getMainClass()))
throw new UnsupportedOptiFineInstallationException();

String remoteVersion = remote.getGameVersion() + "_" + remote.getSelfVersion();

Library library = new Library(
Expand All @@ -90,4 +93,6 @@ public void execute() {
dependencies.add(dependencyManager.checkLibraryCompletionAsync(version.setLibraries(libraries)));
}

public static class UnsupportedOptiFineInstallationException extends UnsupportedOperationException {
}
}

0 comments on commit 5b30617

Please sign in to comment.