mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-11-07 13:04:32 +01:00
Initial MultiMC Forge and MC version support (#31)
* Initial MultiMC Forge and MC version support * Added support for MultiMC MC and Forge versioning * Added support for Fabric, added MultiMC confirmation prompt * Refactored prompt method for MultiMC update * Initial PR changes * Refactored most MultiMC code to LauncherUtils
This commit is contained in:
@@ -23,6 +23,8 @@ interface IUserInterface {
|
||||
|
||||
fun showCancellationDialog(): CancellationResult = CancellationResult.QUIT
|
||||
|
||||
fun showUpdateConfirmationDialog(oldVersions: List<Pair<String, String?>>, newVersions: List<Pair<String, String?>>): UpdateConfirmationResult = UpdateConfirmationResult.CANCELLED
|
||||
|
||||
fun awaitOptionalButton(showCancel: Boolean)
|
||||
|
||||
enum class ExceptionListResult {
|
||||
@@ -33,6 +35,10 @@ interface IUserInterface {
|
||||
QUIT, CONTINUE
|
||||
}
|
||||
|
||||
enum class UpdateConfirmationResult {
|
||||
CANCELLED, CONTINUE, UPDATE
|
||||
}
|
||||
|
||||
var optionsButtonPressed: Boolean
|
||||
var cancelButtonPressed: Boolean
|
||||
|
||||
|
||||
@@ -166,6 +166,58 @@ class GUIHandler : IUserInterface {
|
||||
return future.get()
|
||||
}
|
||||
|
||||
override fun showUpdateConfirmationDialog(oldVersions: List<Pair<String, String?>>, newVersions: List<Pair<String, String?>>): IUserInterface.UpdateConfirmationResult {
|
||||
assert(newVersions.isNotEmpty())
|
||||
val future = CompletableFuture<IUserInterface.UpdateConfirmationResult>()
|
||||
EventQueue.invokeLater {
|
||||
val oldVersIndex = oldVersions.map { it.first to it.second }.toMap()
|
||||
val newVersIndex = newVersions.map { it.first to it.second }.toMap()
|
||||
val message = StringBuilder()
|
||||
message.append("<html>" +
|
||||
"This modpack uses newer versions of the following:<br>" +
|
||||
"<ul>")
|
||||
|
||||
for (oldVer in oldVersions) {
|
||||
val correspondingNewVer = newVersIndex[oldVer.first]
|
||||
message.append("<li>")
|
||||
message.append(oldVer.first.replaceFirstChar { it.uppercase() })
|
||||
message.append(": <font color=${if (oldVer.second != correspondingNewVer) "#ff0000" else "#000000"}>")
|
||||
message.append(oldVer.second ?: "Not found")
|
||||
message.append("</font></li>")
|
||||
}
|
||||
message.append("</ul>")
|
||||
|
||||
message.append("New versions:" +
|
||||
"<ul>")
|
||||
for (newVer in newVersions) {
|
||||
val correspondingOldVer = oldVersIndex[newVer.first]
|
||||
message.append("<li>")
|
||||
message.append(newVer.first.replaceFirstChar { it.uppercase() })
|
||||
message.append(": <font color=${if (newVer.second != correspondingOldVer) "#00ff00" else "#000000"}>")
|
||||
message.append(newVer.second ?: "Not found")
|
||||
message.append("</font></li>")
|
||||
}
|
||||
message.append("</ul><br>" +
|
||||
"Would you like to update the versions, launch without updating, or cancel the launch?")
|
||||
|
||||
|
||||
val options = arrayOf("Cancel", "Continue anyways", "Update")
|
||||
val result = JOptionPane.showOptionDialog(frmPackwizlauncher,
|
||||
message,
|
||||
"Updating MultiMC versions",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0])
|
||||
future.complete(
|
||||
when (result) {
|
||||
JOptionPane.CLOSED_OPTION, 0 -> IUserInterface.UpdateConfirmationResult.CANCELLED
|
||||
1 -> IUserInterface.UpdateConfirmationResult.CONTINUE
|
||||
2 -> IUserInterface.UpdateConfirmationResult.UPDATE
|
||||
else -> IUserInterface.UpdateConfirmationResult.CANCELLED
|
||||
}
|
||||
)
|
||||
}
|
||||
return future.get()
|
||||
}
|
||||
|
||||
override fun awaitOptionalButton(showCancel: Boolean) {
|
||||
EventQueue.invokeAndWait {
|
||||
frmPackwizlauncher.showOk(!showCancel)
|
||||
|
||||
Reference in New Issue
Block a user