mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-10-17 16:34:31 +02:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b2421cfea7 | ||
|
6f05ac6bf0 | ||
|
7b6daaf7e5 |
@@ -49,14 +49,15 @@ private val APIKey = "JDJhJDEwJHNBWVhqblU1N0EzSmpzcmJYM3JVdk92UWk2NHBLS3BnQ2VpbG
|
|||||||
@Throws(JsonSyntaxException::class, JsonIOException::class)
|
@Throws(JsonSyntaxException::class, JsonIOException::class)
|
||||||
fun resolveCfMetadata(mods: List<IndexFile.File>, packFolder: PackwizFilePath, clientHolder: ClientHolder): List<ExceptionDetails> {
|
fun resolveCfMetadata(mods: List<IndexFile.File>, packFolder: PackwizFilePath, clientHolder: ClientHolder): List<ExceptionDetails> {
|
||||||
val failures = mutableListOf<ExceptionDetails>()
|
val failures = mutableListOf<ExceptionDetails>()
|
||||||
val fileIdMap = mutableMapOf<Int, IndexFile.File>()
|
val fileIdMap = mutableMapOf<Int, List<IndexFile.File>>()
|
||||||
|
|
||||||
for (mod in mods) {
|
for (mod in mods) {
|
||||||
if (!mod.linkedFile!!.update.contains("curseforge")) {
|
if (!mod.linkedFile!!.update.contains("curseforge")) {
|
||||||
failures.add(ExceptionDetails(mod.linkedFile!!.name, Exception("Failed to resolve CurseForge metadata: no CurseForge update section")))
|
failures.add(ExceptionDetails(mod.linkedFile!!.name, Exception("Failed to resolve CurseForge metadata: no CurseForge update section")))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fileIdMap[(mod.linkedFile!!.update["curseforge"] as CurseForgeUpdateData).fileId] = mod
|
val fileId = (mod.linkedFile!!.update["curseforge"] as CurseForgeUpdateData).fileId
|
||||||
|
fileIdMap[fileId] = (fileIdMap[fileId] ?: listOf()) + mod
|
||||||
}
|
}
|
||||||
|
|
||||||
val reqData = GetFilesRequest(fileIdMap.keys.toList())
|
val reqData = GetFilesRequest(fileIdMap.keys.toList())
|
||||||
@@ -77,7 +78,7 @@ fun resolveCfMetadata(mods: List<IndexFile.File>, packFolder: PackwizFilePath, c
|
|||||||
val resData = Gson().fromJson(res.body!!.charStream(), GetFilesResponse::class.java)
|
val resData = Gson().fromJson(res.body!!.charStream(), GetFilesResponse::class.java)
|
||||||
res.closeQuietly()
|
res.closeQuietly()
|
||||||
|
|
||||||
val manualDownloadMods = mutableMapOf<Int, Pair<IndexFile.File, Int>>()
|
val manualDownloadMods = mutableMapOf<Int, List<Int>>()
|
||||||
for (file in resData.data) {
|
for (file in resData.data) {
|
||||||
if (!fileIdMap.contains(file.id)) {
|
if (!fileIdMap.contains(file.id)) {
|
||||||
failures.add(ExceptionDetails(file.id.toString(),
|
failures.add(ExceptionDetails(file.id.toString(),
|
||||||
@@ -85,12 +86,14 @@ fun resolveCfMetadata(mods: List<IndexFile.File>, packFolder: PackwizFilePath, c
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (file.downloadUrl == null) {
|
if (file.downloadUrl == null) {
|
||||||
manualDownloadMods[file.modId] = Pair(fileIdMap[file.id]!!, file.id)
|
manualDownloadMods[file.modId] = (manualDownloadMods[file.modId] ?: listOf()) + file.id
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
fileIdMap[file.id]!!.linkedFile!!.resolvedUpdateData["curseforge"] =
|
for (indexFile in fileIdMap[file.id]!!) {
|
||||||
|
indexFile.linkedFile!!.resolvedUpdateData["curseforge"] =
|
||||||
HttpUrlPath(file.downloadUrl!!.toHttpUrl())
|
HttpUrlPath(file.downloadUrl!!.toHttpUrl())
|
||||||
|
}
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
failures.add(ExceptionDetails(file.id.toString(),
|
failures.add(ExceptionDetails(file.id.toString(),
|
||||||
Exception("Failed to parse URL: ${file.downloadUrl} for ID ${file.id}, Project ID ${file.modId}", e)))
|
Exception("Failed to parse URL: ${file.downloadUrl} for ID ${file.id}, Project ID ${file.modId}", e)))
|
||||||
@@ -99,10 +102,13 @@ fun resolveCfMetadata(mods: List<IndexFile.File>, packFolder: PackwizFilePath, c
|
|||||||
|
|
||||||
// Some file types don't show up in the API at all! (e.g. shaderpacks)
|
// Some file types don't show up in the API at all! (e.g. shaderpacks)
|
||||||
// Add unresolved files to manualDownloadMods
|
// Add unresolved files to manualDownloadMods
|
||||||
for ((fileId, file) in fileIdMap) {
|
for ((fileId, indexFiles) in fileIdMap) {
|
||||||
|
for (file in indexFiles) {
|
||||||
if (file.linkedFile != null) {
|
if (file.linkedFile != null) {
|
||||||
if (file.linkedFile!!.resolvedUpdateData["curseforge"] == null) {
|
if (file.linkedFile!!.resolvedUpdateData["curseforge"] == null) {
|
||||||
manualDownloadMods[(file.linkedFile!!.update["curseforge"] as CurseForgeUpdateData).projectId] = Pair(file, fileId)
|
val projectId = (file.linkedFile!!.update["curseforge"] as CurseForgeUpdateData).projectId
|
||||||
|
manualDownloadMods[projectId] = (manualDownloadMods[projectId] ?: listOf()) + fileId
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -133,9 +139,19 @@ fun resolveCfMetadata(mods: List<IndexFile.File>, packFolder: PackwizFilePath, c
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
val modFile = manualDownloadMods[mod.id]!!
|
for (fileId in manualDownloadMods[mod.id]!!) {
|
||||||
failures.add(ExceptionDetails(mod.name, Exception("This mod is excluded from the CurseForge API and must be downloaded manually.\n" +
|
if (!fileIdMap.contains(fileId)) {
|
||||||
"Please go to ${mod.links?.websiteUrl}/files/${modFile.second} and save this file to ${modFile.first.destURI.rebase(packFolder).nioPath.absolute()}")))
|
failures.add(ExceptionDetails(mod.name,
|
||||||
|
Exception("Failed to find file from result: file ID $fileId")))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
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" +
|
||||||
|
"Please go to ${modUrl} and save this file to ${indexFile.destURI.rebase(packFolder).nioPath.absolute()}"), modUrl))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,7 +23,10 @@ interface IUserInterface {
|
|||||||
|
|
||||||
fun showCancellationDialog(): CancellationResult = CancellationResult.QUIT
|
fun showCancellationDialog(): CancellationResult = CancellationResult.QUIT
|
||||||
|
|
||||||
fun showUpdateConfirmationDialog(oldVersions: List<Pair<String, String?>>, newVersions: List<Pair<String, String?>>): UpdateConfirmationResult = UpdateConfirmationResult.CANCELLED
|
fun showUpdateConfirmationDialog(oldVersions: List<Pair<String, String?>>, newVersions: List<Pair<String, String?>>): UpdateConfirmationResult {
|
||||||
|
// Always update metadata when using the CLI
|
||||||
|
return UpdateConfirmationResult.UPDATE
|
||||||
|
}
|
||||||
|
|
||||||
fun awaitOptionalButton(showCancel: Boolean, timeout: Long)
|
fun awaitOptionalButton(showCancel: Boolean, timeout: Long)
|
||||||
|
|
||||||
|
@@ -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)
|
||||||
|
Reference in New Issue
Block a user