diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/game/HMCLModpack.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/game/HMCLModpack.kt index b8fb96737..6ec9d82ad 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/game/HMCLModpack.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/game/HMCLModpack.kt @@ -76,7 +76,7 @@ class HMCLModpackInstallTask(profile: Profile, private val zipFile: File, privat version = version.copy(jar = null) dependents += dependency.gameBuilder().name(name).gameVersion(modpack.gameVersion!!).buildAsync() dependencies += dependency.checkGameCompletionAsync(version) - dependencies += VersionJSONSaveTask(dependency, version) + dependencies += VersionJSONSaveTask(repository, version) } private val run = repository.getRunDirectory(name) diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/InstallerController.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/InstallerController.kt new file mode 100644 index 000000000..d2ff528b9 --- /dev/null +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/InstallerController.kt @@ -0,0 +1,86 @@ +/* + * Hello Minecraft! Launcher. + * Copyright (C) 2017 huangyuhui + * + * 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 {http://www.gnu.org/licenses/}. + */ +package org.jackhuang.hmcl.ui + +import javafx.fxml.FXML +import javafx.scene.control.ScrollPane +import javafx.scene.layout.VBox +import org.jackhuang.hmcl.download.game.VersionJSONSaveTask +import org.jackhuang.hmcl.game.Version +import org.jackhuang.hmcl.game.minecraftVersion +import org.jackhuang.hmcl.setting.Profile +import org.jackhuang.hmcl.task.Scheduler +import org.jackhuang.hmcl.task.task +import org.jackhuang.hmcl.ui.download.InstallWizardProvider +import java.util.* + +class InstallerController { + private lateinit var profile: Profile + private lateinit var versionId: String + private lateinit var version: Version + + @FXML lateinit var scrollPane: ScrollPane + @FXML lateinit var contentPane: VBox + + private var forge: String? = null + private var liteloader: String? = null + private var optifine: String? = null + + fun initialize() { + scrollPane.smoothScrolling() + } + + fun loadVersion(profile: Profile, versionId: String) { + this.profile = profile + this.versionId = versionId + this.version = profile.repository.getVersion(versionId).resolve(profile.repository) + + contentPane.children.clear() + forge = null + liteloader = null + optifine = null + + for (library in version.libraries) { + val removeAction = { _: InstallerItem -> + val newList = LinkedList(version.libraries) + newList.remove(library) + VersionJSONSaveTask(profile.repository, version.copy(libraries = newList)) + .with(task { profile.repository.refreshVersions() }) + .with(task(Scheduler.JAVAFX) { loadVersion(this.profile, this.versionId) }) + .start() + } + if (library.groupId.equals("net.minecraftforge", ignoreCase = true) && library.artifactId.equals("forge", ignoreCase = true)) { + contentPane.children += InstallerItem("Forge", library.version, removeAction) + forge = library.version + } else if (library.groupId.equals("com.mumfrey", ignoreCase = true) && library.artifactId.equals("liteloader", ignoreCase = true)) { + contentPane.children += InstallerItem("LiteLoader", library.version, removeAction) + liteloader = library.version + } else if ((library.groupId.equals("net.optifine", ignoreCase = true) || library.groupId.equals("optifine", ignoreCase = true)) && library.artifactId.equals("optifine", ignoreCase = true)) { + contentPane.children += InstallerItem("OptiFine", library.version, removeAction) + optifine = library.version + } + } + } + + fun onAdd() { + // TODO: if minecraftVersion returns null. + val gameVersion = minecraftVersion(profile.repository.getVersionJar(version)) ?: return + + Controllers.decorator.startWizard(InstallWizardProvider(profile, gameVersion, version, forge, liteloader, optifine)) + } +} \ No newline at end of file diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/InstallerItem.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/InstallerItem.kt new file mode 100644 index 000000000..0e3849deb --- /dev/null +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/InstallerItem.kt @@ -0,0 +1,24 @@ +package org.jackhuang.hmcl.ui + +import com.jfoenix.effects.JFXDepthManager +import javafx.fxml.FXML +import javafx.scene.control.Label +import javafx.scene.layout.BorderPane + +class InstallerItem(artifact: String, version: String, private val deleteCallback: (InstallerItem) -> Unit) : BorderPane() { + @FXML lateinit var lblInstallerArtifact: Label + @FXML lateinit var lblInstallerVersion: Label + + init { + loadFXML("/assets/fxml/version/installer-item.fxml") + + style = "-fx-background-radius: 2; -fx-background-color: white; -fx-padding: 8;" + JFXDepthManager.setDepth(this, 1) + lblInstallerArtifact.text = artifact + lblInstallerVersion.text = version + } + + fun onDelete() { + deleteCallback(this) + } +} \ No newline at end of file diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModController.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModController.kt index bbd6cc48d..b6a13aa2b 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModController.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModController.kt @@ -69,9 +69,6 @@ class ModController { modManager.removeMods(versionId, modInfo) loadMods(modManager, versionId) }.apply { - JFXDepthManager.setDepth(this, 1) - style += "-fx-background-radius: 2; -fx-background-color: white; -fx-padding: 8;" - modInfo.activeProperty.onChange { if (it) styleClass -= "disabled" diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModItem.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModItem.kt index a5d0e2be1..f1fe947d4 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModItem.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/ModItem.kt @@ -18,6 +18,7 @@ package org.jackhuang.hmcl.ui import com.jfoenix.controls.JFXCheckBox +import com.jfoenix.effects.JFXDepthManager import javafx.fxml.FXML import javafx.scene.control.Label import javafx.scene.layout.BorderPane @@ -30,8 +31,10 @@ class ModItem(info: ModInfo, private val deleteCallback: (ModItem) -> Unit) : Bo @FXML lateinit var chkEnabled: JFXCheckBox init { - loadFXML("/assets/fxml/mod-item.fxml") + loadFXML("/assets/fxml/version/mod-item.fxml") + style = "-fx-background-radius: 2; -fx-background-color: white; -fx-padding: 8;" + JFXDepthManager.setDepth(this, 1) lblModFileName.text = info.fileName lblModAuthor.text = "${info.name}, Version: ${info.version}, Game Version: ${info.mcversion}, Authors: ${info.authors}" chkEnabled.isSelected = info.isActive diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionPage.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionPage.kt index b1ca75eba..7fe094cb0 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionPage.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/VersionPage.kt @@ -37,6 +37,8 @@ class VersionPage : StackPane(), DecoratorPage { @FXML lateinit var versionSettingsController: VersionSettingsController @FXML lateinit var modController: ModController + @FXML lateinit var installerController: InstallerController + @FXML lateinit var browseList: JFXListView<*> @FXML lateinit var managementList: JFXListView<*> @FXML lateinit var btnBrowseMenu: JFXButton @@ -48,7 +50,7 @@ class VersionPage : StackPane(), DecoratorPage { lateinit var version: String init { - loadFXML("/assets/fxml/version.fxml") + loadFXML("/assets/fxml/version/version.fxml") children -= browseList children -= managementList @@ -68,6 +70,7 @@ class VersionPage : StackPane(), DecoratorPage { versionSettingsController.loadVersionSetting(profile.getVersionSetting(id)) modController.loadMods(profile.modManager, id) + installerController.loadVersion(profile, id) } fun onBrowseMenu() { diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.kt new file mode 100644 index 000000000..4876f0e82 --- /dev/null +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.kt @@ -0,0 +1,103 @@ +/* + * Hello Minecraft! Launcher. + * Copyright (C) 2017 huangyuhui + * + * 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 {http://www.gnu.org/licenses/}. + */ +package org.jackhuang.hmcl.ui.download + +import com.jfoenix.controls.JFXButton +import com.jfoenix.controls.JFXListView +import javafx.fxml.FXML +import javafx.scene.control.Label +import javafx.scene.layout.StackPane +import javafx.scene.layout.VBox +import org.jackhuang.hmcl.download.DownloadProvider +import org.jackhuang.hmcl.game.GameRepository +import org.jackhuang.hmcl.ui.loadFXML +import org.jackhuang.hmcl.ui.wizard.WizardController +import org.jackhuang.hmcl.ui.wizard.WizardPage + +class AdditionalInstallersPage(private val provider: InstallWizardProvider, private val controller: WizardController, private val repository: GameRepository, private val downloadProvider: DownloadProvider): StackPane(), WizardPage { + + @FXML lateinit var list: VBox + @FXML lateinit var btnForge: JFXButton + @FXML lateinit var btnLiteLoader: JFXButton + @FXML lateinit var btnOptiFine: JFXButton + @FXML lateinit var lblGameVersion: Label + @FXML lateinit var lblVersionName: Label + @FXML lateinit var lblForge: Label + @FXML lateinit var lblLiteLoader: Label + @FXML lateinit var lblOptiFine: Label + @FXML lateinit var btnInstall: JFXButton + + init { + loadFXML("/assets/fxml/download/additional-installers.fxml") + + lblGameVersion.text = provider.gameVersion + lblVersionName.text = provider.version.id + + btnForge.setOnMouseClicked { + controller.settings[INSTALLER_TYPE] = 0 + controller.onNext(VersionsPage(controller, provider.gameVersion, downloadProvider, "forge") { controller.onPrev(false) }) + } + + btnLiteLoader.setOnMouseClicked { + controller.settings[INSTALLER_TYPE] = 1 + controller.onNext(VersionsPage(controller, provider.gameVersion, downloadProvider, "liteloader") { controller.onPrev(false) }) + } + + btnOptiFine.setOnMouseClicked { + controller.settings[INSTALLER_TYPE] = 2 + controller.onNext(VersionsPage(controller, provider.gameVersion, downloadProvider, "optifine") { controller.onPrev(false) }) + } + } + + override val title: String + get() = "Choose a game version" + + override fun onNavigate(settings: MutableMap) { + lblGameVersion.text = "Current Game Version: ${provider.gameVersion}" + btnForge.isDisable = provider.forge != null + if (provider.forge != null || controller.settings.containsKey("forge")) + lblForge.text = "Forge Versoin: ${provider.forge ?: controller.settings["forge"]}" + else + lblForge.text = "Forge not installed" + + btnLiteLoader.isDisable = provider.liteloader != null + if (provider.liteloader != null || controller.settings.containsKey("liteloader")) + lblLiteLoader.text = "LiteLoader Versoin: ${provider.liteloader ?: controller.settings["liteloader"]}" + else + lblLiteLoader.text = "LiteLoader not installed" + + btnOptiFine.isDisable = provider.optifine != null + if (provider.optifine != null || controller.settings.containsKey("optifine")) + lblOptiFine.text = "OptiFine Versoin: ${provider.optifine ?: controller.settings["optifine"]}" + else + lblOptiFine.text = "OptiFine not installed" + + } + + override fun cleanup(settings: MutableMap) { + settings.remove(INSTALLER_TYPE) + } + + fun onInstall() { + controller.onFinish() + } + + companion object { + val INSTALLER_TYPE = "INSTALLER_TYPE" + } +} \ No newline at end of file diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/DownloadWizardProvider.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/DownloadWizardProvider.kt index 413be4797..f9091a213 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/DownloadWizardProvider.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/DownloadWizardProvider.kt @@ -95,10 +95,11 @@ class DownloadWizardProvider(): WizardProvider() { } override fun createPage(controller: WizardController, step: Int, settings: MutableMap): Node { + val provider = profile.dependency.downloadProvider return when (step) { 0 -> InstallTypePage(controller) 1 -> when (settings[InstallTypePage.INSTALL_TYPE]) { - 0 -> VersionsPage(controller, "", BMCLAPIDownloadProvider, "game") { controller.onNext(InstallersPage(controller, profile.repository, BMCLAPIDownloadProvider)) } + 0 -> VersionsPage(controller, "", provider, "game") { controller.onNext(InstallersPage(controller, profile.repository, provider)) } 1 -> ModpackPage(controller) else -> throw Error() } diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/InstallWizardProvider.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/InstallWizardProvider.kt new file mode 100644 index 000000000..127bf7b30 --- /dev/null +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/InstallWizardProvider.kt @@ -0,0 +1,52 @@ +package org.jackhuang.hmcl.ui.download + +import javafx.scene.Node +import org.jackhuang.hmcl.download.BMCLAPIDownloadProvider +import org.jackhuang.hmcl.game.HMCLModpackInstallTask +import org.jackhuang.hmcl.game.HMCLModpackManifest +import org.jackhuang.hmcl.game.Version +import org.jackhuang.hmcl.mod.CurseForgeModpackInstallTask +import org.jackhuang.hmcl.mod.CurseForgeModpackManifest +import org.jackhuang.hmcl.mod.Modpack +import org.jackhuang.hmcl.setting.EnumGameDirectory +import org.jackhuang.hmcl.setting.Profile +import org.jackhuang.hmcl.setting.Settings +import org.jackhuang.hmcl.task.Scheduler +import org.jackhuang.hmcl.task.Task +import org.jackhuang.hmcl.task.task +import org.jackhuang.hmcl.ui.wizard.WizardController +import org.jackhuang.hmcl.ui.wizard.WizardProvider +import java.io.File + +class InstallWizardProvider(val profile: Profile, val gameVersion: String, val version: Version, val forge: String? = null, val liteloader: String? = null, val optifine: String? = null): WizardProvider() { + + override fun start(settings: MutableMap) { + } + + override fun finish(settings: MutableMap): Any? { + var ret = task {} + + if (settings.containsKey("forge")) + ret = ret with profile.dependency.installLibraryAsync(gameVersion, version, "forge", settings["forge"] as String) + + if (settings.containsKey("liteloader")) + ret = ret with profile.dependency.installLibraryAsync(gameVersion, version, "liteloader", settings["liteloader"] as String) + + if (settings.containsKey("optifine")) + ret = ret with profile.dependency.installLibraryAsync(gameVersion, version, "optifine", settings["optifine"] as String) + + return ret with task(Scheduler.JAVAFX) { profile.repository.refreshVersions() } + } + + override fun createPage(controller: WizardController, step: Int, settings: MutableMap): Node { + return when (step) { + 0 -> AdditionalInstallersPage(this, controller, profile.repository, BMCLAPIDownloadProvider) + else -> throw IllegalStateException() + } + } + + override fun cancel(): Boolean { + return true + } + +} \ No newline at end of file diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/InstallersPage.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/InstallersPage.kt index 122a7acdb..75f592833 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/InstallersPage.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/download/InstallersPage.kt @@ -23,6 +23,7 @@ import com.jfoenix.controls.JFXTextField import javafx.fxml.FXML import javafx.scene.control.Label import javafx.scene.layout.StackPane +import javafx.scene.layout.VBox import org.jackhuang.hmcl.download.DownloadProvider import org.jackhuang.hmcl.game.GameRepository import org.jackhuang.hmcl.i18n @@ -30,11 +31,13 @@ import org.jackhuang.hmcl.ui.construct.Validator import org.jackhuang.hmcl.ui.loadFXML import org.jackhuang.hmcl.ui.wizard.WizardController import org.jackhuang.hmcl.ui.wizard.WizardPage -import org.jackhuang.hmcl.util.onChange class InstallersPage(private val controller: WizardController, private val repository: GameRepository, private val downloadProvider: DownloadProvider): StackPane(), WizardPage { - @FXML lateinit var list: JFXListView + @FXML lateinit var list: VBox + @FXML lateinit var btnForge: JFXButton + @FXML lateinit var btnLiteLoader: JFXButton + @FXML lateinit var btnOptiFine: JFXButton @FXML lateinit var lblGameVersion: Label @FXML lateinit var lblForge: Label @FXML lateinit var lblLiteLoader: Label @@ -52,14 +55,19 @@ class InstallersPage(private val controller: WizardController, private val repos } txtName.text = gameVersion - list.selectionModel.selectedIndexProperty().onChange { - controller.settings[INSTALLER_TYPE] = it - controller.onNext(when (it){ - 0 -> VersionsPage(controller, gameVersion, downloadProvider, "forge") { controller.onPrev(false) } - 1 -> VersionsPage(controller, gameVersion, downloadProvider, "liteloader") { controller.onPrev(false) } - 2 -> VersionsPage(controller, gameVersion, downloadProvider, "optifine") { controller.onPrev(false) } - else -> throw IllegalStateException() - }) + btnForge.setOnMouseClicked { + controller.settings[INSTALLER_TYPE] = 0 + controller.onNext(VersionsPage(controller, gameVersion, downloadProvider, "forge") { controller.onPrev(false) }) + } + + btnLiteLoader.setOnMouseClicked { + controller.settings[INSTALLER_TYPE] = 1 + controller.onNext(VersionsPage(controller, gameVersion, downloadProvider, "liteloader") { controller.onPrev(false) }) + } + + btnOptiFine.setOnMouseClicked { + controller.settings[INSTALLER_TYPE] = 2 + controller.onNext(VersionsPage(controller, gameVersion, downloadProvider, "optifine") { controller.onPrev(false) }) } } diff --git a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/wizard/WizardController.kt b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/wizard/WizardController.kt index 2a257ab62..a127b7cea 100644 --- a/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/wizard/WizardController.kt +++ b/HMCL/src/main/kotlin/org/jackhuang/hmcl/ui/wizard/WizardController.kt @@ -28,10 +28,15 @@ class WizardController(protected val displayer: WizardDisplayer) : Navigation { override fun onStart() { settings.clear() + provider.start(settings) + pages.clear() val page = navigatingTo(0) pages.push(page) - provider.start(settings) + + if (page is WizardPage) + page.onNavigate(settings) + displayer.onStart() displayer.navigateTo(page, Navigation.NavigationDirection.START) } diff --git a/HMCL/src/main/resources/assets/fxml/download/additional-installers.fxml b/HMCL/src/main/resources/assets/fxml/download/additional-installers.fxml new file mode 100644 index 000000000..f0b7f9e62 --- /dev/null +++ b/HMCL/src/main/resources/assets/fxml/download/additional-installers.fxml @@ -0,0 +1,63 @@ + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+
diff --git a/HMCL/src/main/resources/assets/fxml/download/installers.fxml b/HMCL/src/main/resources/assets/fxml/download/installers.fxml index e4bd743c3..57f07cbb2 100644 --- a/HMCL/src/main/resources/assets/fxml/download/installers.fxml +++ b/HMCL/src/main/resources/assets/fxml/download/installers.fxml @@ -1,54 +1,62 @@ - - - + - - - - + + type="StackPane" style="-fx-padding: 16;"> -
- - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- +
diff --git a/HMCL/src/main/resources/assets/fxml/version/installer-item.fxml b/HMCL/src/main/resources/assets/fxml/version/installer-item.fxml new file mode 100644 index 000000000..00753a0fc --- /dev/null +++ b/HMCL/src/main/resources/assets/fxml/version/installer-item.fxml @@ -0,0 +1,23 @@ + + + + + + + +
+ + +
+ + + + + + + +
diff --git a/HMCL/src/main/resources/assets/fxml/version/installer.fxml b/HMCL/src/main/resources/assets/fxml/version/installer.fxml new file mode 100644 index 000000000..af3c3e605 --- /dev/null +++ b/HMCL/src/main/resources/assets/fxml/version/installer.fxml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/HMCL/src/main/resources/assets/fxml/mod-item.fxml b/HMCL/src/main/resources/assets/fxml/version/mod-item.fxml similarity index 100% rename from HMCL/src/main/resources/assets/fxml/mod-item.fxml rename to HMCL/src/main/resources/assets/fxml/version/mod-item.fxml diff --git a/HMCL/src/main/resources/assets/fxml/mod.fxml b/HMCL/src/main/resources/assets/fxml/version/mod.fxml similarity index 100% rename from HMCL/src/main/resources/assets/fxml/mod.fxml rename to HMCL/src/main/resources/assets/fxml/version/mod.fxml diff --git a/HMCL/src/main/resources/assets/fxml/version-settings.fxml b/HMCL/src/main/resources/assets/fxml/version/version-settings.fxml similarity index 100% rename from HMCL/src/main/resources/assets/fxml/version-settings.fxml rename to HMCL/src/main/resources/assets/fxml/version/version-settings.fxml diff --git a/HMCL/src/main/resources/assets/fxml/version.fxml b/HMCL/src/main/resources/assets/fxml/version/version.fxml similarity index 94% rename from HMCL/src/main/resources/assets/fxml/version.fxml rename to HMCL/src/main/resources/assets/fxml/version/version.fxml index f4d308881..765aa3a91 100644 --- a/HMCL/src/main/resources/assets/fxml/version.fxml +++ b/HMCL/src/main/resources/assets/fxml/version/version.fxml @@ -13,6 +13,9 @@ + + + diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DefaultDependencyManager.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DefaultDependencyManager.kt index 93e945b0f..668e9a9bc 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DefaultDependencyManager.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DefaultDependencyManager.kt @@ -51,13 +51,13 @@ class DefaultDependencyManager(override val repository: DefaultGameRepository, o override fun installLibraryAsync(gameVersion: String, version: Version, libraryId: String, libraryVersion: String): Task { if (libraryId == "forge") return ForgeInstallTask(this, gameVersion, version, libraryVersion) - .then { VersionJSONSaveTask(this, it["version"]) } + .then { VersionJSONSaveTask(repository, it["version"]) } else if (libraryId == "liteloader") return LiteLoaderInstallTask(this, gameVersion, version, libraryVersion) - .then { VersionJSONSaveTask(this, it["version"]) } + .then { VersionJSONSaveTask(repository, it["version"]) } else if (libraryId == "optifine") return OptiFineInstallTask(this, gameVersion, version, libraryVersion) - .then { VersionJSONSaveTask(this, it["version"]) } + .then { VersionJSONSaveTask(repository, it["version"]) } else throw IllegalArgumentException("Library id $libraryId is unrecognized.") } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DefaultGameBuilder.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DefaultGameBuilder.kt index 7ea7a6b82..722272e8b 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DefaultGameBuilder.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DefaultGameBuilder.kt @@ -45,7 +45,7 @@ class DefaultGameBuilder(val dependencyManager: DefaultDependencyManager): GameB GameLoggingDownloadTask(dependencyManager, version), GameDownloadTask(version), GameLibrariesTask(dependencyManager, version) // Game libraries will be downloaded for multiple times partly, this time is for vanilla libraries. - ) then VersionJSONSaveTask(dependencyManager, version) + ) then VersionJSONSaveTask(dependencyManager.repository, version) if (toolVersions.containsKey("forge")) result = result then libraryTaskHelper(gameVersion, "forge") diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/game/GameDownloadTasks.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/game/GameDownloadTasks.kt index adf3c5b80..fbf4d76db 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/game/GameDownloadTasks.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/game/GameDownloadTasks.kt @@ -20,10 +20,7 @@ package org.jackhuang.hmcl.download.game import org.jackhuang.hmcl.download.AbstractDependencyManager import org.jackhuang.hmcl.download.DefaultDependencyManager import org.jackhuang.hmcl.download.DependencyManager -import org.jackhuang.hmcl.game.AssetIndex -import org.jackhuang.hmcl.game.AssetObject -import org.jackhuang.hmcl.game.DownloadType -import org.jackhuang.hmcl.game.Version +import org.jackhuang.hmcl.game.* import org.jackhuang.hmcl.task.FileDownloadTask import org.jackhuang.hmcl.task.Task import org.jackhuang.hmcl.task.TaskResult @@ -164,12 +161,12 @@ class GameAssetDownloadTask(private val dependencyManager: DefaultDependencyMana /** * This task is to save the version json. - * @param dependencyManager the dependency manager that can provides proxy settings and [GameRepository] + * @param repository the game repository * @param version the **resolved** version */ -class VersionJSONSaveTask(private val dependencyManager: DefaultDependencyManager, private val version: Version): Task() { +class VersionJSONSaveTask(private val repository: DefaultGameRepository, private val version: Version): Task() { override fun execute() { - val json = dependencyManager.repository.getVersionJson(version.id).absoluteFile + val json = repository.getVersionJson(version.id).absoluteFile if (!json.makeFile()) throw IOException("Cannot create file $json") json.writeText(GSON.toJson(version)) diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Library.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Library.kt index 5a4cf2aa8..0b42adcfd 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Library.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Library.kt @@ -74,12 +74,13 @@ open class Library( companion object LibrarySerializer : JsonDeserializer, JsonSerializer { fun fromName(name: String, url: String? = null, downloads: LibrariesDownloadInfo? = null, extract: ExtractRules? = null, natives: Map? = null, rules: List? = null): Library { val arr = name.split(":".toRegex(), 3) - if (arr.size != 3) + if (arr.size != 3 && arr.size != 4) throw IllegalArgumentException("Library name is malformed. Correct example: group:artifact:version.") return Library( groupId = arr[0].replace("\\", "/"), artifactId = arr[1], version = arr[2], + classifier_ = arr.getOrNull(3), url = url, downloads = downloads, extract = extract, diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/GetTask.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/GetTask.kt index 2e6ce7058..48bd7bc89 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/GetTask.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/GetTask.kt @@ -65,6 +65,10 @@ class GetTask @JvmOverloads constructor(val url: URL, val encoding: Charset = Ch return } + if (size > 0 && size != read) { + throw IllegalStateException("Not completed! Readed: $read, Size: $size") + } + result = baos.toString(encoding.name()) return } catch (e: IOException) { diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/Task.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/Task.kt index b41c07445..a0faeb228 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/Task.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/Task.kt @@ -50,7 +50,7 @@ abstract class Task { */ open val reliant: Boolean = true - var title: String = this.javaClass.toString() + open var title: String = this.javaClass.toString() var variables: AutoTypingMap? = null