Skip to content

Commit fe88dba

Browse files
committed
Fix download progress being stuck at 0
1 parent c96896c commit fe88dba

3 files changed

Lines changed: 13 additions & 8 deletions

File tree

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ the [Discord](https://dediamondpro.dev/discord).
77
- Resourcify now contributes to Modrinth's analytics,
88
see [their article](https://modrinth.com/news/article/analytics-overhaul/) for more info.
99
- Ported to 1.21.11 and 26.1.2 NeoForge
10-
- Fixed issues with trying to open links with special characters.
10+
- Fixed download progress being stuck at 0% sometimes.
1111
- Added a search debounce to prevent sending a lot of requests when typing fast
12+
- Fixed issues with trying to open links with special characters.
1213
- Updated a lot of dependencies
1314

1415
----------------------------------------------------------------------------------------------------

src/main/kotlin/dev/dediamondpro/resourcify/Constants.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ import org.slf4j.LoggerFactory
2323
object Constants {
2424
const val NAME = /*$ mod_name*/ "Resourcify"
2525
const val ID = /*$ mod_id*/ "resourcify"
26-
const val VERSION = /*$ mod_version*/ "1.8.2"
26+
const val VERSION = /*$ mod_version*/ "1.8.3"
2727
val LOGGER: Logger = LoggerFactory.getLogger(NAME)
2828
}

src/main/kotlin/dev/dediamondpro/resourcify/util/DownloadManager.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,15 @@ object DownloadManager {
7272
val queuedDownload = queuedDownloads.remove(url) ?: return
7373
tempFolder.mkdirs()
7474
var tempFile = File(tempFolder, queuedDownload.file.name + ".tmp")
75-
val i = 0
75+
var i = 0
7676
while (tempFile.exists()) {
77-
tempFile = File(tempFolder, queuedDownload.file.name + "-$i.tmp")
77+
tempFile = File(tempFolder, queuedDownload.file.name + "-${i++}.tmp")
7878
}
79-
downloadsInProgress[url] = DownloadData(runAsync {
79+
80+
// Create data first, so we don't have race conditions trying to set the length
81+
val downloadData = DownloadData(null, tempFile)
82+
downloadsInProgress[url] = downloadData
83+
downloadData.future = runAsync {
8084
// Modrinth analytics
8185
val headers = mutableMapOf<String, String>()
8286
if (url.host == "cdn.modrinth.com") {
@@ -88,7 +92,7 @@ object DownloadManager {
8892
}
8993

9094
val con = url.toURL().setupConnection(headers)
91-
downloadsInProgress[url]?.length = con.contentLength
95+
downloadData.length = con.contentLength
9296
con.getEncodedInputStream().use {
9397
Files.copy(it!!, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING)
9498
}
@@ -118,7 +122,7 @@ object DownloadManager {
118122
}
119123
downloadsInProgress.remove(url)
120124
downloadNext()
121-
}, tempFile)
125+
}
122126
}
123127

124128
fun extractWorldZip(zipFile: File, dest: File) {
@@ -193,4 +197,4 @@ private data class QueuedDownload(
193197
val downloadReason: ModrinthAnalytics.DownloadReason?
194198
)
195199

196-
private data class DownloadData(val future: CompletableFuture<Void>, val file: File, var length: Int? = null)
200+
private data class DownloadData(var future: CompletableFuture<Void>?, val file: File, var length: Int? = null)

0 commit comments

Comments
 (0)