comment pruning

This commit is contained in:
downthecrop 2025-11-21 17:55:13 -08:00
parent 0c1e445a95
commit f61852660a
15 changed files with 32 additions and 278 deletions

View file

@ -1,11 +1,7 @@
package KondoKit.pluginmanager
import KondoKit.pluginmanager.GitLabPlugin
import KondoKit.util.HttpFetcher
import KondoKit.pluginmanager.GitLabConfig
import KondoKit.views.ReflectiveEditorView
import plugin.PluginRepository
import java.awt.EventQueue
import java.io.*
import java.net.HttpURLConnection
import java.net.URL
@ -21,19 +17,15 @@ object PluginDownloadManager {
private const val TAG = "PluginDownloadManager"
private const val MAX_CONCURRENT_DOWNLOADS = 3
// Thread pool for concurrent downloads
private val downloadExecutor = Executors.newFixedThreadPool(MAX_CONCURRENT_DOWNLOADS)
// Callback for download progress updates
interface DownloadProgressCallback {
fun onProgress(pluginName: String, progress: Int)
fun onComplete(pluginName: String, success: Boolean, errorMessage: String? = null)
}
// Debug logging function
private fun debugLog(message: String) = PluginLogger.debug(TAG, message)
// Get download URL for debugging/logging purposes
fun getDownloadUrlForLogging(plugin: GitLabPlugin): String {
return GitLabConfig.getArchiveUrl(plugin.path)
}
@ -47,7 +39,6 @@ object PluginDownloadManager {
debugLog("Starting download for plugin: ${plugin.path}")
callback.onProgress(plugin.path, 0)
// Download the plugin as a ZIP archive
val success = downloadAndExtractPlugin(plugin, callback)
if (success) {
@ -77,11 +68,9 @@ object PluginDownloadManager {
fun downloadPlugins(plugins: List<GitLabPlugin>, callback: (String, Boolean, String?) -> Unit) {
debugLog("Starting concurrent download of ${plugins.size} plugins")
// Submit all downloads to the executor
for (plugin in plugins) {
downloadPlugin(plugin, object : DownloadProgressCallback {
override fun onProgress(pluginName: String, progress: Int) {
// We don't need to do anything here for the simple callback
}
override fun onComplete(pluginName: String, success: Boolean, errorMessage: String?) {
@ -96,7 +85,6 @@ object PluginDownloadManager {
*/
private fun downloadAndExtractPlugin(plugin: GitLabPlugin, callback: DownloadProgressCallback): Boolean {
try {
// Validate plugin path
if (plugin.path.isBlank()) {
debugLog("Plugin path is blank for plugin: ${plugin.path}")
return false
@ -117,7 +105,6 @@ object PluginDownloadManager {
for (downloadUrl in downloadUrls) {
debugLog("Trying download URL: $downloadUrl")
// Validate URL
val url = try {
URL(downloadUrl)
} catch (e: Exception) {
@ -125,7 +112,6 @@ object PluginDownloadManager {
continue
}
// Create URL connection
val connection = try {
HttpFetcher.openGetConnection(url.toString())
} catch (e: Exception) {
@ -137,20 +123,16 @@ object PluginDownloadManager {
debugLog("Request headers - User-Agent: ${connection.getRequestProperty("User-Agent")}")
debugLog("Request headers - Accept: ${connection.getRequestProperty("Accept")}")
// Get content length for progress tracking
val contentLength = connection.contentLength
debugLog("Content length: $contentLength bytes for plugin: ${plugin.path}")
// Read response
val responseCode = connection.responseCode
debugLog("Response code: $responseCode for plugin: ${plugin.path}")
// Log response message
val responseMessage = connection.responseMessage
debugLog("Response message: $responseMessage for plugin: ${plugin.path}")
if (responseCode == HttpURLConnection.HTTP_OK) {
// Check if input stream is available
val inputStream = connection.inputStream
if (inputStream == null) {
debugLog("Input stream is null for plugin: ${plugin.path}")
@ -159,11 +141,9 @@ object PluginDownloadManager {
debugLog("Input stream available for plugin: ${plugin.path}")
// Create output directory
val pluginsDir = File(rt4.GlobalJsonConfig.instance.pluginsFolder)
debugLog("Plugins directory: ${pluginsDir.absolutePath}")
// Validate plugins directory
if (!pluginsDir.exists()) {
debugLog("Plugins directory does not exist: ${pluginsDir.absolutePath}")
if (!pluginsDir.mkdirs()) {
@ -181,13 +161,11 @@ object PluginDownloadManager {
val pluginDir = File(pluginsDir, plugin.path)
debugLog("Plugin directory: ${pluginDir.absolutePath}")
// Create directory if it doesn't exist
if (!pluginDir.exists()) {
pluginDir.mkdirs()
debugLog("Created plugin directory: ${pluginDir.absolutePath}")
}
// Download the ZIP file
val tempZipFile = File.createTempFile("plugin_", ".zip")
tempZipFile.deleteOnExit()
debugLog("Created temp file: ${tempZipFile.absolutePath}")
@ -222,10 +200,8 @@ object PluginDownloadManager {
debugLog("Downloaded ${totalBytesRead} bytes to ${tempZipFile.absolutePath}")
// Extract the ZIP file
if (extractZipFile(tempZipFile, pluginDir, plugin.path)) {
debugLog("Successfully extracted plugin to ${pluginDir.absolutePath}")
// Clean up temp file
tempZipFile.delete()
return true
} else {
@ -270,7 +246,6 @@ object PluginDownloadManager {
try {
debugLog("Extracting ZIP file: ${zipFile.absolutePath} to ${targetDir.absolutePath}")
// Validate inputs
if (!zipFile.exists()) {
debugLog("ZIP file does not exist: ${zipFile.absolutePath}")
return false
@ -291,8 +266,7 @@ object PluginDownloadManager {
debugLog("Processing ZIP entry $entryCount: $entryName")
// Skip the top-level directory in the ZIP (GitLab adds a project-branch-hash directory)
// We want to extract the contents of the plugin directory directly
// Strip the top-level GitLab archive directory so we extract only the plugin contents
val relativePath = if (entryName.contains("/")) {
entryName.substring(entryName.indexOf("/") + 1)
} else {
@ -301,7 +275,6 @@ object PluginDownloadManager {
debugLog("Relative path for entry: $relativePath")
// Only extract files that are part of this specific plugin
if (relativePath.startsWith(pluginPath) && relativePath != pluginPath) {
val fileName = relativePath.substring(pluginPath.length + 1) // +1 for the trailing slash
@ -312,7 +285,6 @@ object PluginDownloadManager {
debugLog("Target file path: ${file.absolutePath}")
// Create parent directories if needed
val parent = file.parentFile
if (parent != null && !parent.exists()) {
if (parent.mkdirs()) {
@ -324,7 +296,6 @@ object PluginDownloadManager {
}
}
// Extract file or directory
if (entry!!.isDirectory) {
if (!file.exists()) {
if (file.mkdirs()) {
@ -336,7 +307,6 @@ object PluginDownloadManager {
debugLog("Directory already exists: ${file.absolutePath}")
}
} else {
// Create file
try {
FileOutputStream(file).use { fos ->
zis.copyTo(fos)