Add support for mode field, with CurseForge metadata lookup

Now always asks the user before proceeding past the point where optional mods could be selected and configured
When updating files, the hash is checked so an update isn't redownloaded if it already exists
Added DevMain file for running in a dev environment
This commit is contained in:
comp500
2022-05-22 21:20:52 +01:00
parent 92d6f68f1d
commit c6e304bc7f
12 changed files with 388 additions and 25 deletions

View File

@@ -23,6 +23,8 @@ interface IUserInterface {
fun showCancellationDialog(): CancellationResult = CancellationResult.QUIT
fun awaitOptionalButton(showCancel: Boolean)
enum class ExceptionListResult {
CONTINUE, CANCEL, IGNORE
}

View File

@@ -59,4 +59,8 @@ class CLIHandler : IUserInterface {
}
return ExceptionListResult.CANCEL
}
override fun awaitOptionalButton(showCancel: Boolean) {
// Do nothing
}
}

View File

@@ -8,6 +8,7 @@ import link.infra.packwiz.installer.ui.data.InstallProgress
import link.infra.packwiz.installer.util.Log
import java.awt.EventQueue
import java.util.concurrent.CompletableFuture
import java.util.concurrent.CountDownLatch
import javax.swing.JDialog
import javax.swing.JOptionPane
import javax.swing.UIManager
@@ -18,8 +19,21 @@ class GUIHandler : IUserInterface {
@Volatile
override var optionsButtonPressed = false
set(value) {
optionalSelectedLatch.countDown()
field = value
}
@Volatile
override var cancelButtonPressed = false
set(value) {
optionalSelectedLatch.countDown()
field = value
}
var okButtonPressed = false
set(value) {
optionalSelectedLatch.countDown()
field = value
}
@Volatile
override var firstInstall = false
@@ -42,8 +56,12 @@ class GUIHandler : IUserInterface {
}
}
private val visibleCountdownLatch = CountDownLatch(1)
private val optionalSelectedLatch = CountDownLatch(1)
override fun show() = EventQueue.invokeLater {
frmPackwizlauncher.isVisible = true
visibleCountdownLatch.countDown()
}
override fun dispose() = EventQueue.invokeAndWait {
@@ -147,4 +165,15 @@ class GUIHandler : IUserInterface {
}
return future.get()
}
override fun awaitOptionalButton(showCancel: Boolean) {
EventQueue.invokeAndWait {
frmPackwizlauncher.showOk(!showCancel)
}
visibleCountdownLatch.await()
optionalSelectedLatch.await()
EventQueue.invokeLater {
frmPackwizlauncher.hideOk()
}
}
}

View File

@@ -12,6 +12,9 @@ class InstallWindow(private val handler: GUIHandler) : JFrame() {
private var lblProgresslabel: JLabel
private var progressBar: JProgressBar
private var btnOptions: JButton
private val btnCancel: JButton
private val btnOk: JButton
private val buttonsPanel: JPanel
init {
setBounds(100, 100, 493, 95)
@@ -35,7 +38,7 @@ class InstallWindow(private val handler: GUIHandler) : JFrame() {
}, BorderLayout.CENTER)
// Buttons
add(JPanel().apply {
buttonsPanel = JPanel().apply {
border = EmptyBorder(0, 5, 0, 5)
layout = GridBagLayout()
@@ -49,20 +52,28 @@ class InstallWindow(private val handler: GUIHandler) : JFrame() {
}
}
add(btnOptions, GridBagConstraints().apply {
gridx = 0
gridx = 1
gridy = 0
})
add(JButton("Cancel").apply {
btnCancel = JButton("Cancel").apply {
addActionListener {
isEnabled = false
handler.cancelButtonPressed = true
}
}, GridBagConstraints().apply {
gridx = 0
}
add(btnCancel, GridBagConstraints().apply {
gridx = 1
gridy = 1
})
}, BorderLayout.EAST)
}
btnOk = JButton("Continue").apply {
addActionListener {
handler.okButtonPressed = true
}
}
add(buttonsPanel, BorderLayout.EAST)
}
fun displayProgress(progress: InstallProgress) {
@@ -83,4 +94,31 @@ class InstallWindow(private val handler: GUIHandler) : JFrame() {
isEnabled = false
}
}
fun showOk(hideCancel: Boolean) {
if (hideCancel) {
buttonsPanel.add(btnOk, GridBagConstraints().apply {
gridx = 1
gridy = 1
})
buttonsPanel.remove(btnCancel)
} else {
buttonsPanel.add(btnOk, GridBagConstraints().apply {
gridx = 0
gridy = 1
})
}
buttonsPanel.revalidate()
}
fun hideOk() {
buttonsPanel.remove(btnOk)
if (!buttonsPanel.components.contains(btnCancel)) {
buttonsPanel.add(btnCancel, GridBagConstraints().apply {
gridx = 1
gridy = 1
})
}
buttonsPanel.revalidate()
}
}