Support download modpack from direct download url
This commit is contained in:
@@ -122,6 +122,8 @@ public class ModpackInstallWizardProvider implements WizardProvider {
|
|||||||
public Node createPage(WizardController controller, int step, Map<String, Object> settings) {
|
public Node createPage(WizardController controller, int step, Map<String, Object> settings) {
|
||||||
switch (step) {
|
switch (step) {
|
||||||
case 0:
|
case 0:
|
||||||
|
return new ModpackSelectionPage(controller);
|
||||||
|
case 1:
|
||||||
return new ModpackPage(controller);
|
return new ModpackPage(controller);
|
||||||
default:
|
default:
|
||||||
throw new IllegalStateException("error step " + step + ", settings: " + settings + ", pages: " + controller.getPages());
|
throw new IllegalStateException("error step " + step + ", settings: " + settings + ", pages: " + controller.getPages());
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* Hello Minecraft! Launcher
|
||||||
|
* Copyright (C) 2019 huangyuhui <huanghongxun2008@126.com> and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.jackhuang.hmcl.ui.download;
|
||||||
|
|
||||||
|
import com.jfoenix.controls.JFXButton;
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
|
import javafx.stage.FileChooser;
|
||||||
|
import org.jackhuang.hmcl.task.FileDownloadTask;
|
||||||
|
import org.jackhuang.hmcl.task.Schedulers;
|
||||||
|
import org.jackhuang.hmcl.ui.Controllers;
|
||||||
|
import org.jackhuang.hmcl.ui.FXUtils;
|
||||||
|
import org.jackhuang.hmcl.ui.wizard.WizardController;
|
||||||
|
import org.jackhuang.hmcl.ui.wizard.WizardPage;
|
||||||
|
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.jackhuang.hmcl.ui.download.ModpackPage.MODPACK_FILE;
|
||||||
|
import static org.jackhuang.hmcl.util.Lang.tryCast;
|
||||||
|
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
||||||
|
|
||||||
|
public final class ModpackSelectionPage extends StackPane implements WizardPage {
|
||||||
|
private final WizardController controller;
|
||||||
|
|
||||||
|
@FXML private JFXButton btnLocal;
|
||||||
|
@FXML private JFXButton btnRemote;
|
||||||
|
|
||||||
|
public ModpackSelectionPage(WizardController controller) {
|
||||||
|
this.controller = controller;
|
||||||
|
FXUtils.loadFXML(this, "/assets/fxml/download/modpack-source.fxml");
|
||||||
|
|
||||||
|
Optional<File> filePath = tryCast(controller.getSettings().get(MODPACK_FILE), File.class);
|
||||||
|
if (filePath.isPresent()) {
|
||||||
|
controller.getSettings().put(MODPACK_FILE, filePath.get());
|
||||||
|
controller.onNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
FXUtils.applyDragListener(this, it -> "zip".equals(FileUtils.getExtension(it)), modpacks -> {
|
||||||
|
File modpack = modpacks.get(0);
|
||||||
|
controller.getSettings().put(MODPACK_FILE, modpack);
|
||||||
|
controller.onNext();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onChooseLocalFile() {
|
||||||
|
FileChooser chooser = new FileChooser();
|
||||||
|
chooser.setTitle(i18n("modpack.choose"));
|
||||||
|
chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter(i18n("modpack"), "*.zip"));
|
||||||
|
File selectedFile = chooser.showOpenDialog(Controllers.getStage());
|
||||||
|
if (selectedFile == null) {
|
||||||
|
Platform.runLater(controller::onEnd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
controller.getSettings().put(MODPACK_FILE, selectedFile);
|
||||||
|
controller.onNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onChooseRemoteFile() {
|
||||||
|
Controllers.inputDialog(i18n("modpack.choose.remote.tooltip"), (urlString, resolve, reject) -> {
|
||||||
|
try {
|
||||||
|
URL url = new URL(urlString);
|
||||||
|
Path modpack = Files.createTempFile("forge-installer", ".jar");
|
||||||
|
resolve.run();
|
||||||
|
|
||||||
|
Controllers.taskDialog(
|
||||||
|
new FileDownloadTask(url, modpack.toFile(), null)
|
||||||
|
.whenComplete(Schedulers.javafx(), e -> {
|
||||||
|
if (e == null) {
|
||||||
|
resolve.run();
|
||||||
|
controller.getSettings().put(MODPACK_FILE, modpack.toFile());
|
||||||
|
controller.onNext();
|
||||||
|
} else {
|
||||||
|
reject.accept(e.getMessage());
|
||||||
|
}
|
||||||
|
}).executor(true),
|
||||||
|
i18n("message.downloading")
|
||||||
|
);
|
||||||
|
} catch (IOException e) {
|
||||||
|
reject.accept(e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanup(Map<String, Object> settings) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTitle() {
|
||||||
|
return i18n("modpack.task.install");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import com.jfoenix.controls.*?>
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<?import org.jackhuang.hmcl.ui.construct.TwoLineListItem?>
|
||||||
|
<fx:root xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
type="StackPane">
|
||||||
|
<fx:define>
|
||||||
|
<Insets fx:id="insets" topRightBottomLeft="8" />
|
||||||
|
</fx:define>
|
||||||
|
<VBox fx:id="list" styleClass="jfx-list-view" maxHeight="150" maxWidth="400">
|
||||||
|
<Label padding="${insets}" text="%install.modpack" />
|
||||||
|
<JFXButton fx:id="btnLocal" prefWidth="${list.width}" onMouseClicked="#onChooseLocalFile">
|
||||||
|
<graphic>
|
||||||
|
<BorderPane mouseTransparent="true">
|
||||||
|
<left>
|
||||||
|
<TwoLineListItem title="%modpack.choose.local" subtitle="%modpack.choose.local.detail" />
|
||||||
|
</left>
|
||||||
|
<right>
|
||||||
|
<fx:include BorderPane.alignment="CENTER" source="/assets/svg/arrow-right.fxml"/>
|
||||||
|
</right>
|
||||||
|
</BorderPane>
|
||||||
|
</graphic>
|
||||||
|
</JFXButton>
|
||||||
|
<JFXButton fx:id="btnRemote" prefWidth="${list.width}" onMouseClicked="#onChooseRemoteFile">
|
||||||
|
<graphic>
|
||||||
|
<BorderPane mouseTransparent="true">
|
||||||
|
<left>
|
||||||
|
<TwoLineListItem title="%modpack.choose.remote" subtitle="%modpack.choose.remote.detail" />
|
||||||
|
</left>
|
||||||
|
<right>
|
||||||
|
<fx:include BorderPane.alignment="CENTER" source="/assets/svg/arrow-right.fxml"/>
|
||||||
|
</right>
|
||||||
|
</BorderPane>
|
||||||
|
</graphic>
|
||||||
|
</JFXButton>
|
||||||
|
</VBox>
|
||||||
|
</fx:root>
|
||||||
@@ -218,6 +218,11 @@ message.warning=Warning
|
|||||||
|
|
||||||
modpack=Modpack
|
modpack=Modpack
|
||||||
modpack.choose=Choose a modpack zip.
|
modpack.choose=Choose a modpack zip.
|
||||||
|
modpack.choose.local=Import local modpack file
|
||||||
|
modpack.choose.local.detail=You can drag the modpack file into this page to install
|
||||||
|
modpack.choose.remote=Download modpack from Internet
|
||||||
|
modpack.choose.remote.detail=Requires a direct download link to the remote modpack file
|
||||||
|
modpack.choose.remote.tooltip=A direct download link to the remote modpack file
|
||||||
modpack.desc=Describe your modpack, including precautions and changelog. Markdown and online pictures are supported.
|
modpack.desc=Describe your modpack, including precautions and changelog. Markdown and online pictures are supported.
|
||||||
modpack.enter_name=Enter a name for this modpack.
|
modpack.enter_name=Enter a name for this modpack.
|
||||||
modpack.export=Export Modpack
|
modpack.export=Export Modpack
|
||||||
|
|||||||
@@ -215,6 +215,11 @@ message.warning=警告
|
|||||||
|
|
||||||
modpack=整合包
|
modpack=整合包
|
||||||
modpack.choose=選擇要安裝的遊戲整合包檔案
|
modpack.choose=選擇要安裝的遊戲整合包檔案
|
||||||
|
modpack.choose.local=導入本地整合包檔案
|
||||||
|
modpack.choose.local.detail=你可以直接將整合包檔案拖入本頁面以安裝
|
||||||
|
modpack.choose.remote=從網路下載整合包
|
||||||
|
modpack.choose.remote.detail=需要提供整合包的下載連結
|
||||||
|
modpack.choose.remote.tooltip=要下載的整合包的連結
|
||||||
modpack.desc=描述你要製作的整合包,比如整合包注意事項和更新記錄,支援 Markdown(圖片請上傳至網路)。
|
modpack.desc=描述你要製作的整合包,比如整合包注意事項和更新記錄,支援 Markdown(圖片請上傳至網路)。
|
||||||
modpack.enter_name=給遊戲取個你喜歡的名字
|
modpack.enter_name=給遊戲取個你喜歡的名字
|
||||||
modpack.export=匯出整合包
|
modpack.export=匯出整合包
|
||||||
|
|||||||
@@ -216,6 +216,11 @@ message.warning=警告
|
|||||||
|
|
||||||
modpack=整合包
|
modpack=整合包
|
||||||
modpack.choose=选择要安装的游戏整合包文件
|
modpack.choose=选择要安装的游戏整合包文件
|
||||||
|
modpack.choose.local=导入本地整合包文件
|
||||||
|
modpack.choose.local.detail=你可以直接将整合包文件拖入本页面以安装
|
||||||
|
modpack.choose.remote=从互联网下载整合包
|
||||||
|
modpack.choose.remote.detail=需要提供整合包的下载链接
|
||||||
|
modpack.choose.remote.tooltip=要下载的整合包的链接
|
||||||
modpack.desc=描述你要制作的整合包,比如整合包注意事项和更新记录,支持 Markdown(图片请用网络图)。
|
modpack.desc=描述你要制作的整合包,比如整合包注意事项和更新记录,支持 Markdown(图片请用网络图)。
|
||||||
modpack.enter_name=给游戏起个你喜欢的名字
|
modpack.enter_name=给游戏起个你喜欢的名字
|
||||||
modpack.export=导出整合包
|
modpack.export=导出整合包
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ public class FileDownloadTask extends Task<Void> {
|
|||||||
if (temp != null)
|
if (temp != null)
|
||||||
temp.toFile().delete();
|
temp.toFile().delete();
|
||||||
exception = e;
|
exception = e;
|
||||||
Logging.LOG.log(Level.WARNING, "Failed to download " + url + ", repeat times: " + repeat + 1, e);
|
Logging.LOG.log(Level.WARNING, "Failed to download " + url + ", repeat times: " + (repeat + 1), e);
|
||||||
} finally {
|
} finally {
|
||||||
closeFiles();
|
closeFiles();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user