feat: added basic UI, started on backend

chore: added coroutines

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-03-12 02:48:17 +01:00
parent 56f797f7a3
commit 74d09702a8
8 changed files with 338 additions and 2 deletions

View file

@ -51,6 +51,7 @@ repositories {
dependencies {
implementation("com.formdev:flatlaf:2.4")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
}
val targetJavaVersion = 17
@ -91,6 +92,7 @@ tasks {
withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
dependencies {
include(dependency("com.formdev:flatlaf:2.4"))
include(dependency("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4"))
}
dependsOn("generateTemplates", "processResources")
}

View file

@ -1,8 +1,32 @@
/*
* Copyright (C) 2023 limited_dev
*
* 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 de.limited_dev.modpackinstaller
import com.formdev.flatlaf.FlatDarculaLaf
import de.limited_dev.modpackinstaller.build.BuildConstants
import de.limited_dev.modpackinstaller.gui.GUI
fun main() {
println("Hello World")
println("${BuildConstants.version} ${BuildConstants.fabricDownloadLocation} ${BuildConstants.modpackDownloadLocation}")
println("Launching installer...")
println("${BuildConstants.version}")
println("Download Location Fabric: ${BuildConstants.fabricDownloadLocation}")
println("Download Modpacka Fabric: ${BuildConstants.modpackDownloadLocation}")
FlatDarculaLaf.setup()
GUI()
}

View file

@ -0,0 +1,41 @@
/*
* Copyright (C) 2023 limited_dev
*
* 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 de.limited_dev.modpackinstaller.backend
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
object Manager {
fun startDownloadAndInstall(dotMcLocation: String) {
val modloaderCoroutine = GlobalScope.launch {
println("Downloading Modloader")
}
val modpackCoroutine = GlobalScope.launch {
println("Downloading Modpack")
}
runBlocking {
modloaderCoroutine.join()
}
}
}

View file

@ -0,0 +1,38 @@
/*
* Copyright (C) 2023 limited_dev
*
* 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 de.limited_dev.modpackinstaller.gui
import java.awt.GridLayout
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JSeparator
import javax.swing.border.EmptyBorder
class BottomBar : JPanel() {
init {
this.layout = GridLayout(2, 4)
this.border = EmptyBorder(0, 10, 10, 10)
val label = JLabel("(c) 2023 limited_dev, Licensed under GPL-3.0")
this.add(JSeparator())
this.add(label)
}
}

View file

@ -0,0 +1,43 @@
/*
* Copyright (C) 2023 limited_dev
*
* 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 de.limited_dev.modpackinstaller.gui
import de.limited_dev.modpackinstaller.build.BuildConstants
import java.awt.BorderLayout
import javax.swing.JFrame
import javax.swing.WindowConstants
class GUI : JFrame("Modpack installer " + BuildConstants.version) {
init {
this.isResizable = false
this.defaultCloseOperation = WindowConstants.EXIT_ON_CLOSE
val contentPane = this.contentPane
contentPane.layout = BorderLayout()
contentPane.add(MainPanel(), BorderLayout.CENTER)
contentPane.add(BottomBar(), BorderLayout.SOUTH)
this.pack()
this.setLocationRelativeTo(null)
this.isVisible = true
}
}

View file

@ -0,0 +1,103 @@
/*
* Copyright (C) 2023 limited_dev
*
* 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 de.limited_dev.modpackinstaller.gui
import de.limited_dev.modpackinstaller.backend.Manager
import de.limited_dev.modpackinstaller.util.OSHelper
import de.limited_dev.modpackinstaller.util.PopupFactory
import java.awt.*
import java.io.File
import javax.swing.*
import javax.swing.border.EmptyBorder
class MainPanel : JPanel() {
private val generatorButton = JButton("Download & Install")
private var fabricLabel: JLabel
private var modpackLabel: JLabel
private var dotMcLocationBar: JTextField
private var dotMcLocation: String = OSHelper.os.oSType
init {
val layout = GridLayout(6, 1)
this.layout = layout
border = EmptyBorder(10, 10, 10, 10)
val info = JLabel("Modpack Installer")
info.horizontalAlignment = SwingConstants.CENTER
info.font = Font(font.name, font.style, font.size + 6)
this.add(info, BorderLayout.NORTH)
val flayout = FlowLayout()
flayout.hgap = 10
flayout.alignment = SwingConstants.VERTICAL
fabricLabel = JLabel("Fabric mod loader")
modpackLabel = JLabel("Modpack")
this.add(fabricLabel)
this.add(modpackLabel)
dotMcLocationBar = JTextField(dotMcLocation)
dotMcLocationBar.isEditable = false
this.add(dotMcLocationBar)
val openFileChooser = JButton("Select .minecraft Folder")
openFileChooser.addActionListener {
dotMcLocation = promptForFolder(openFileChooser)
dotMcLocationBar.text = dotMcLocation
}
this.add(openFileChooser)
generatorButton.addActionListener {
Manager.startDownloadAndInstall(dotMcLocation)
val dotMcMods = File(dotMcLocation + File.separator + "mods")
if (dotMcMods.exists()) {
val bool = PopupFactory.getYesOrNoError(
"Warning! .minecraft/mods folder found",
"This installer will clear your mods folder in order to install the right Modpack."
)
if (bool) {
generatorButton.isEnabled = false
Manager.startDownloadAndInstall(dotMcLocation)
}
} else {
generatorButton.isEnabled = false
Manager.startDownloadAndInstall(dotMcLocation)
}
}
this.add(generatorButton)
}
private fun promptForFolder(parent: Component?): String {
val fc = JFileChooser()
fc.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY
return if (fc.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
fc.selectedFile.absolutePath
} else "Error"
}
fun updateFabricModloader(tx: String) {
fabricLabel.text = "Fabric mod loader $tx"
}
fun updateModpack(tx: String) {
modpackLabel.text = "Modpack $tx"
}
}

View file

@ -0,0 +1,43 @@
/*
* Copyright (C) 2023 limited_dev
*
* 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 de.limited_dev.modpackinstaller.util
import java.io.File
import java.util.*
enum class OSHelper(val oSType: String) {
WINDOWS(System.getenv("APPDATA") + File.separator + ".minecraft"),
MAC("Please select your .minecraft folder"),
LINUX(System.getProperty("user.home") + File.separator + ".minecraft");
companion object {
val os: OSHelper
get() {
val currentOS = System.getProperty("os.name").lowercase(Locale.getDefault())
if (currentOS.startsWith("windows")) {
return WINDOWS
} else if (currentOS.startsWith("mac")) {
return MAC
}
return LINUX
}
val dotMinecraftLocation: String
get() = System.getProperty("os.name")
}
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (C) 2023 limited_dev
*
* 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 de.limited_dev.modpackinstaller.util
import javax.swing.JOptionPane
object PopupFactory {
fun getYesOrNoError(title: String, msg: String): Boolean {
println("Popup created")
val res = JOptionPane.showConfirmDialog(
null,
msg,
title,
JOptionPane.OK_CANCEL_OPTION
)
if (res == 0) {
println("Pressed OK")
return true
} else {
println("Pressed CANCEL")
return false
}
}
}