Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ public final class Controllers {
GameListPage gameListPage = new GameListPage();
gameListPage.selectedProfileProperty().bindBidirectional(Profiles.selectedProfileProperty());
gameListPage.profilesProperty().bindContent(Profiles.profilesProperty());
FXUtils.applyDragListener(gameListPage, ModpackHelper::isFileModpackByExtension, modpacks -> {
Path modpack = modpacks.get(0);
Controllers.getDecorator().startWizard(new ModpackInstallWizardProvider(Profiles.getSelectedProfile(), modpack), i18n("install.modpack"));
FXUtils.applyDragListener(gameListPage, file -> ModpackHelper.isFileModpackByExtension(file) || "json".equalsIgnoreCase(FileUtils.getNameWithoutExtension(file)), files -> {
Path file = files.get(0);

if (ModpackHelper.isFileModpackByExtension(file)) {
Controllers.getDecorator().startWizard(new ModpackInstallWizardProvider(Profiles.getSelectedProfile(), file), i18n("install.modpack"));
} else if ("json".equalsIgnoreCase(FileUtils.getExtension(file))) {
Versions.installFromJson(Profiles.getSelectedProfile(), file);
}
});
return gameListPage;
});
Expand Down
5 changes: 4 additions & 1 deletion HMCL/src/main/java/org/jackhuang/hmcl/ui/main/RootPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.TaskCancellationAction;
import org.jackhuang.hmcl.util.io.CompressingUtils;
import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.platform.*;
import org.jackhuang.hmcl.util.versioning.VersionNumber;

Expand Down Expand Up @@ -98,7 +99,7 @@ public MainPage getMainPage() {
if (mainPage == null) {
MainPage mainPage = new MainPage();
FXUtils.applyDragListener(mainPage,
file -> ModpackHelper.isFileModpackByExtension(file) || NBTFileType.isNBTFileByExtension(file),
file -> ModpackHelper.isFileModpackByExtension(file) || NBTFileType.isNBTFileByExtension(file) || "json".equalsIgnoreCase(FileUtils.getExtension(file)),
modpacks -> {
Path file = modpacks.get(0);
if (ModpackHelper.isFileModpackByExtension(file)) {
Expand All @@ -113,6 +114,8 @@ public MainPage getMainPage() {
Controllers.dialog(i18n("nbt.open.failed") + "\n\n" + StringUtils.getStackTrace(e),
i18n("message.error"), MessageDialogPane.MessageType.ERROR);
}
} else if ("json".equalsIgnoreCase(FileUtils.getExtension(file))) {
Versions.installFromJson(Profiles.getSelectedProfile(), file);
}
});

Expand Down
37 changes: 37 additions & 0 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jackhuang.hmcl.auth.Account;
import org.jackhuang.hmcl.auth.authlibinjector.AuthlibInjectorAccount;
import org.jackhuang.hmcl.download.game.GameAssetDownloadTask;
import org.jackhuang.hmcl.download.game.GameDownloadTask;
import org.jackhuang.hmcl.game.*;
import org.jackhuang.hmcl.mod.RemoteMod;
import org.jackhuang.hmcl.setting.*;
Expand All @@ -41,6 +42,7 @@
import org.jackhuang.hmcl.ui.export.ExportWizardProvider;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.TaskCancellationAction;
import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.io.FileUtils;
import org.jackhuang.hmcl.util.io.NetworkUtils;
import org.jackhuang.hmcl.util.platform.OperatingSystem;
Expand Down Expand Up @@ -157,6 +159,41 @@ public static void openFolder(Profile profile, String version) {
FXUtils.openFolder(profile.getRepository().getRunDirectory(version));
}

public static void installFromJson(Profile profile, Path file) {
Version version;
try {
version = profile.getRepository().readVersionJson(file);
} catch (Exception e) {
Controllers.dialog(i18n("install.new_game.malformed_json"), i18n("message.error"), MessageDialogPane.MessageType.ERROR);
return;
}

Controllers.prompt(i18n("version.manage.duplicate.prompt"), (result, handler) -> {
var unnamedVersion = version.setId(result).setJar(result);
var gameDownloadTask = new GameDownloadTask(profile.getDependency(), null, unnamedVersion).whenComplete(Schedulers.javafx(), (exception) -> {
if (exception != null) {
handler.reject(StringUtils.getStackTrace(exception));
} else {
profile.getRepository().refreshVersions();
profile.setSelectedVersion(result);
handler.resolve();
Comment on lines +177 to +179
}
});
Task.runAsync(() -> {
var dir = profile.getGameDir().resolve("versions");
var versionDir = Files.createDirectory(dir.resolve(result));
var jsonPath = versionDir.resolve(result + ".json");

JsonUtils.writeToJsonFile(jsonPath, unnamedVersion);
}).thenRunAsync(() -> profile.getRepository().refreshVersions()).whenComplete(Schedulers.javafx(), (exception) -> {
if (exception != null) {
handler.reject(StringUtils.getStackTrace(exception));
} else
Controllers.taskDialog(gameDownloadTask, i18n("install.new_game"), TaskCancellationAction.NORMAL);
}).start();
}, FileUtils.getNameWithoutExtension(file), new Validator(i18n("install.new_game.malformed"), HMCLGameRepository::isValidVersionId), new Validator(i18n("install.new_game.already_exists"), newVersionName -> !profile.getRepository().versionIdConflicts(newVersionName)));
}

public static void duplicateVersion(Profile profile, String version) {
Controllers.prompt(
new PromptDialogPane.Builder(i18n("version.manage.duplicate.prompt"), (res, handler) -> {
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 @@ -753,6 +753,7 @@ install.new_game.already_exists=This instance name already exists. Please use an
install.new_game.current_game_version=Current Instance Version
install.new_game.installation=Instance Installation
install.new_game.malformed=Invalid name.
install.new_game.malformed_json=Invalid Minecraft instance JSON file。
install.select=Choose operation
install.success=Successfully installed.

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 @@ -557,6 +557,7 @@ install.new_game.already_exists=此實例已經存在,請重新命名
install.new_game.current_game_version=目前遊戲實例
install.new_game.installation=安裝新實例
install.new_game.malformed=名稱無效
install.new_game.malformed_json=無效的 Minecraft 實例 JSON 文件。
install.select=請選取安裝方式
install.success=安裝成功

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 @@ -562,6 +562,7 @@ install.new_game.already_exists=此实例已经存在,请换一个名字
install.new_game.current_game_version=当前游戏实例
install.new_game.installation=安装新游戏
install.new_game.malformed=名字不合法
install.new_game.malformed_json=不是有效的 Minecraft 实例 JSON 文件。
install.select=请选择安装方式
install.success=安装成功

Expand Down
Loading