mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-04-19 21:16:30 +02:00
Add open missing mods button (#66)
* add open missing mods button * hide missing mods button if none are found * add logging to openUrl
This commit is contained in:
parent
6f05ac6bf0
commit
b2421cfea7
@ -147,8 +147,9 @@ fun resolveCfMetadata(mods: List<IndexFile.File>, packFolder: PackwizFilePath, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (indexFile in fileIdMap[fileId]!!) {
|
for (indexFile in fileIdMap[fileId]!!) {
|
||||||
|
var modUrl = "${mod.links?.websiteUrl}/files/${fileId}"
|
||||||
failures.add(ExceptionDetails(indexFile.name, Exception("This mod is excluded from the CurseForge API and must be downloaded manually.\n" +
|
failures.add(ExceptionDetails(indexFile.name, Exception("This mod is excluded from the CurseForge API and must be downloaded manually.\n" +
|
||||||
"Please go to ${mod.links?.websiteUrl}/files/${fileId} and save this file to ${indexFile.destURI.rebase(packFolder).nioPath.absolute()}")))
|
"Please go to ${modUrl} and save this file to ${indexFile.destURI.rebase(packFolder).nioPath.absolute()}"), modUrl))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,6 @@ package link.infra.packwiz.installer.ui.data
|
|||||||
|
|
||||||
data class ExceptionDetails(
|
data class ExceptionDetails(
|
||||||
val name: String,
|
val name: String,
|
||||||
val exception: Exception
|
val exception: Exception,
|
||||||
|
val modUrl: String? = null
|
||||||
)
|
)
|
@ -1,5 +1,6 @@
|
|||||||
package link.infra.packwiz.installer.ui.gui
|
package link.infra.packwiz.installer.ui.gui
|
||||||
|
|
||||||
|
import link.infra.packwiz.installer.util.Log
|
||||||
import link.infra.packwiz.installer.ui.IUserInterface
|
import link.infra.packwiz.installer.ui.IUserInterface
|
||||||
import link.infra.packwiz.installer.ui.data.ExceptionDetails
|
import link.infra.packwiz.installer.ui.data.ExceptionDetails
|
||||||
import java.awt.BorderLayout
|
import java.awt.BorderLayout
|
||||||
@ -24,6 +25,24 @@ class ExceptionListWindow(eList: List<ExceptionDetails>, future: CompletableFutu
|
|||||||
fun getExceptionAt(index: Int) = details[index].exception
|
fun getExceptionAt(index: Int) = details[index].exception
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun openUrl(url: String) {
|
||||||
|
try {
|
||||||
|
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
|
||||||
|
Desktop.getDesktop().browse(URI(url))
|
||||||
|
} else {
|
||||||
|
val process = Runtime.getRuntime().exec(arrayOf("xdg-open", url));
|
||||||
|
val exitValue = process.waitFor()
|
||||||
|
if (exitValue > 0) {
|
||||||
|
Log.warn("Failed to open $url: xdg-open exited with code $exitValue")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: IOException) {
|
||||||
|
Log.warn("Failed to open $url", e)
|
||||||
|
} catch (e: URISyntaxException) {
|
||||||
|
Log.warn("Failed to open $url", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the dialog.
|
* Create the dialog.
|
||||||
*/
|
*/
|
||||||
@ -112,6 +131,19 @@ class ExceptionListWindow(eList: List<ExceptionDetails>, future: CompletableFutu
|
|||||||
this@ExceptionListWindow.dispose()
|
this@ExceptionListWindow.dispose()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
val missingMods = eList.filter { it.modUrl != null }.map { it.modUrl!! }.toSet()
|
||||||
|
|
||||||
|
if (!missingMods.isEmpty()) {
|
||||||
|
add(JButton("Open missing mods").apply {
|
||||||
|
toolTipText = "Open missing mods in your browser"
|
||||||
|
addActionListener {
|
||||||
|
missingMods.forEach {
|
||||||
|
openUrl(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}, BorderLayout.EAST)
|
}, BorderLayout.EAST)
|
||||||
|
|
||||||
// Errored label
|
// Errored label
|
||||||
@ -122,16 +154,8 @@ class ExceptionListWindow(eList: List<ExceptionDetails>, future: CompletableFutu
|
|||||||
// Left buttons
|
// Left buttons
|
||||||
add(JPanel().apply {
|
add(JPanel().apply {
|
||||||
add(JButton("Report issue").apply {
|
add(JButton("Report issue").apply {
|
||||||
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
|
|
||||||
addActionListener {
|
addActionListener {
|
||||||
try {
|
openUrl("https://github.com/packwiz/packwiz-installer/issues/new")
|
||||||
Desktop.getDesktop().browse(URI("https://github.com/packwiz/packwiz-installer/issues/new"))
|
|
||||||
} catch (e: IOException) {
|
|
||||||
// lol the button just won't work i guess
|
|
||||||
} catch (e: URISyntaxException) {}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
isEnabled = false
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}, BorderLayout.WEST)
|
}, BorderLayout.WEST)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user