mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-11-07 13:04:32 +01:00
Complete Kotlin port
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package link.infra.packwiz.installer.ui
|
||||
|
||||
import link.infra.packwiz.installer.ui.IExceptionDetails.ExceptionListResult
|
||||
import link.infra.packwiz.installer.ui.IUserInterface.ExceptionListResult
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.Future
|
||||
|
||||
@@ -39,7 +39,7 @@ class CLIHandler : IUserInterface {
|
||||
}
|
||||
}
|
||||
|
||||
override fun showExceptions(exceptions: List<IExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): Future<ExceptionListResult> {
|
||||
override fun showExceptions(exceptions: List<ExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): Future<ExceptionListResult> {
|
||||
val future = CompletableFuture<ExceptionListResult>()
|
||||
future.complete(ExceptionListResult.CANCEL)
|
||||
return future
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package link.infra.packwiz.installer.ui
|
||||
|
||||
data class ExceptionDetails(
|
||||
val name: String,
|
||||
val exception: Exception
|
||||
)
|
||||
@@ -1,6 +1,5 @@
|
||||
package link.infra.packwiz.installer.ui
|
||||
|
||||
import link.infra.packwiz.installer.ui.IExceptionDetails.ExceptionListResult
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Desktop
|
||||
import java.awt.event.WindowAdapter
|
||||
@@ -14,10 +13,10 @@ import java.util.concurrent.CompletableFuture
|
||||
import javax.swing.*
|
||||
import javax.swing.border.EmptyBorder
|
||||
|
||||
internal class ExceptionListWindow(eList: List<IExceptionDetails>, future: CompletableFuture<ExceptionListResult>, numTotal: Int, allowsIgnore: Boolean, parentWindow: JFrame?) : JDialog(parentWindow, "Failed file downloads", true) {
|
||||
class ExceptionListWindow(eList: List<ExceptionDetails>, future: CompletableFuture<IUserInterface.ExceptionListResult>, numTotal: Int, allowsIgnore: Boolean, parentWindow: JFrame?) : JDialog(parentWindow, "Failed file downloads", true) {
|
||||
private val lblExceptionStacktrace: JTextArea
|
||||
|
||||
private class ExceptionListModel internal constructor(private val details: List<IExceptionDetails>) : AbstractListModel<String>() {
|
||||
private class ExceptionListModel internal constructor(private val details: List<ExceptionDetails>) : AbstractListModel<String>() {
|
||||
override fun getSize() = details.size
|
||||
override fun getElementAt(index: Int) = details[index].name
|
||||
fun getExceptionAt(index: Int) = details[index].exception
|
||||
@@ -90,7 +89,7 @@ internal class ExceptionListWindow(eList: List<IExceptionDetails>, future: Compl
|
||||
add(JButton("Continue").apply {
|
||||
toolTipText = "Attempt to continue installing, excluding the failed downloads"
|
||||
addActionListener {
|
||||
future.complete(ExceptionListResult.CONTINUE)
|
||||
future.complete(IUserInterface.ExceptionListResult.CONTINUE)
|
||||
this@ExceptionListWindow.dispose()
|
||||
}
|
||||
})
|
||||
@@ -98,7 +97,7 @@ internal class ExceptionListWindow(eList: List<IExceptionDetails>, future: Compl
|
||||
add(JButton("Cancel launch").apply {
|
||||
toolTipText = "Stop launching the game"
|
||||
addActionListener {
|
||||
future.complete(ExceptionListResult.CANCEL)
|
||||
future.complete(IUserInterface.ExceptionListResult.CANCEL)
|
||||
this@ExceptionListWindow.dispose()
|
||||
}
|
||||
})
|
||||
@@ -107,7 +106,7 @@ internal class ExceptionListWindow(eList: List<IExceptionDetails>, future: Compl
|
||||
toolTipText = "Start the game without attempting to update"
|
||||
isEnabled = allowsIgnore
|
||||
addActionListener {
|
||||
future.complete(ExceptionListResult.IGNORE)
|
||||
future.complete(IUserInterface.ExceptionListResult.IGNORE)
|
||||
this@ExceptionListWindow.dispose()
|
||||
}
|
||||
})
|
||||
@@ -139,13 +138,13 @@ internal class ExceptionListWindow(eList: List<IExceptionDetails>, future: Compl
|
||||
|
||||
addWindowListener(object : WindowAdapter() {
|
||||
override fun windowClosing(e: WindowEvent) {
|
||||
future.complete(ExceptionListResult.CANCEL)
|
||||
future.complete(IUserInterface.ExceptionListResult.CANCEL)
|
||||
}
|
||||
|
||||
override fun windowClosed(e: WindowEvent) {
|
||||
// Just in case closing didn't get triggered - if something else called dispose() the
|
||||
// future will have already completed
|
||||
future.complete(ExceptionListResult.CANCEL)
|
||||
future.complete(IUserInterface.ExceptionListResult.CANCEL)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package link.infra.packwiz.installer.ui
|
||||
|
||||
interface IExceptionDetails {
|
||||
val exception: Exception
|
||||
val name: String
|
||||
|
||||
enum class ExceptionListResult {
|
||||
CONTINUE, CANCEL, IGNORE
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package link.infra.packwiz.installer.ui
|
||||
|
||||
import link.infra.packwiz.installer.ui.IExceptionDetails.ExceptionListResult
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.Future
|
||||
import kotlin.system.exitProcess
|
||||
@@ -21,14 +20,22 @@ interface IUserInterface {
|
||||
// Return true if the installation was cancelled!
|
||||
fun showOptions(options: List<IOptionDetails>): Future<Boolean>
|
||||
|
||||
fun showExceptions(exceptions: List<IExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): Future<ExceptionListResult>
|
||||
fun showExceptions(exceptions: List<ExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): Future<ExceptionListResult>
|
||||
@JvmDefault
|
||||
fun disableOptionsButton() {}
|
||||
// Should not return CONTINUE
|
||||
|
||||
@JvmDefault
|
||||
fun showCancellationDialog(): Future<ExceptionListResult> {
|
||||
return CompletableFuture<ExceptionListResult>().apply {
|
||||
complete(ExceptionListResult.CANCEL)
|
||||
fun showCancellationDialog(): Future<CancellationResult> {
|
||||
return CompletableFuture<CancellationResult>().apply {
|
||||
complete(CancellationResult.QUIT)
|
||||
}
|
||||
}
|
||||
|
||||
enum class ExceptionListResult {
|
||||
CONTINUE, CANCEL, IGNORE
|
||||
}
|
||||
|
||||
enum class CancellationResult {
|
||||
QUIT, CONTINUE
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package link.infra.packwiz.installer.ui
|
||||
|
||||
import link.infra.packwiz.installer.ui.IExceptionDetails.ExceptionListResult
|
||||
import link.infra.packwiz.installer.ui.IUserInterface.ExceptionListResult
|
||||
import java.awt.*
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import java.util.concurrent.Future
|
||||
@@ -186,7 +186,7 @@ class InstallWindow : IUserInterface {
|
||||
return future
|
||||
}
|
||||
|
||||
override fun showExceptions(exceptions: List<IExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): Future<ExceptionListResult> {
|
||||
override fun showExceptions(exceptions: List<ExceptionDetails>, numTotal: Int, allowsIgnore: Boolean): Future<ExceptionListResult> {
|
||||
val future = CompletableFuture<ExceptionListResult>()
|
||||
EventQueue.invokeLater {
|
||||
ExceptionListWindow(exceptions, future, numTotal, allowsIgnore, frmPackwizlauncher).apply {
|
||||
@@ -204,15 +204,15 @@ class InstallWindow : IUserInterface {
|
||||
}
|
||||
}
|
||||
|
||||
override fun showCancellationDialog(): Future<ExceptionListResult> {
|
||||
val future = CompletableFuture<ExceptionListResult>()
|
||||
override fun showCancellationDialog(): Future<IUserInterface.CancellationResult> {
|
||||
val future = CompletableFuture<IUserInterface.CancellationResult>()
|
||||
EventQueue.invokeLater {
|
||||
val buttons = arrayOf("Quit", "Ignore")
|
||||
val result = JOptionPane.showOptionDialog(frmPackwizlauncher,
|
||||
"The installation was cancelled. Would you like to quit the game, or ignore the update and start the game?",
|
||||
"Cancelled installation",
|
||||
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, buttons, buttons[0])
|
||||
future.complete(if (result == 0) ExceptionListResult.CANCEL else ExceptionListResult.IGNORE)
|
||||
future.complete(if (result == 0) IUserInterface.CancellationResult.QUIT else IUserInterface.CancellationResult.CONTINUE)
|
||||
}
|
||||
return future
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user