Skip to content

Commit 2d3ebca

Browse files
authored
Merge pull request #4 from utkarshdalal/cd-rev4-utkarsh
Add onChunkCompleted callback
2 parents b072d7f + 5d155d2 commit 2d3ebca

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

javasteam-depotdownloader/src/main/kotlin/in/dragonbra/javasteam/depotdownloader/DepotDownloader.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,17 +1499,36 @@ class DepotDownloader @JvmOverloads constructor(
14991499

15001500
logger?.debug("%.2f%% %s".format(depotPercentage, fileFinalPath))
15011501
} else {
1502-
// Just update counters without notifying
1502+
// Update counters and notify on chunk completion
1503+
val sizeDownloaded: Long
1504+
val depotPercentage: Float
1505+
val compressedBytes: Long
1506+
val uncompressedBytes: Long
1507+
15031508
synchronized(depotDownloadCounter) {
15041509
depotDownloadCounter.sizeDownloaded += written.toLong()
15051510
depotDownloadCounter.depotBytesCompressed += chunk.compressedLength
15061511
depotDownloadCounter.depotBytesUncompressed += chunk.uncompressedLength
1512+
1513+
sizeDownloaded = depotDownloadCounter.sizeDownloaded
1514+
compressedBytes = depotDownloadCounter.depotBytesCompressed
1515+
uncompressedBytes = depotDownloadCounter.depotBytesUncompressed
1516+
depotPercentage = (sizeDownloaded.toFloat() / depotDownloadCounter.completeDownloadSize)
15071517
}
15081518

15091519
synchronized(downloadCounter) {
15101520
downloadCounter.totalBytesCompressed += chunk.compressedLength
15111521
downloadCounter.totalBytesUncompressed += chunk.uncompressedLength
15121522
}
1523+
1524+
notifyListeners { listener ->
1525+
listener.onChunkCompleted(
1526+
depotId = depot.depotId,
1527+
depotPercentComplete = depotPercentage,
1528+
compressedBytes = compressedBytes,
1529+
uncompressedBytes = uncompressedBytes
1530+
)
1531+
}
15131532
}
15141533
}
15151534

javasteam-depotdownloader/src/main/kotlin/in/dragonbra/javasteam/depotdownloader/IDownloadListener.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ interface IDownloadListener {
4848
*/
4949
fun onFileCompleted(depotId: Int, fileName: String, depotPercentComplete: Float) {}
5050

51+
/**
52+
* Called when a chunk completes downloading.
53+
* Provides more frequent progress updates than onFileCompleted.
54+
*
55+
* @param depotId The depot being downloaded
56+
* @param depotPercentComplete Overall depot completion percentage (0f to 1f)
57+
* @param compressedBytes Total compressed bytes downloaded so far for this depot
58+
* @param uncompressedBytes Total uncompressed bytes downloaded so far for this depot
59+
*/
60+
fun onChunkCompleted(depotId: Int, depotPercentComplete: Float, compressedBytes: Long, uncompressedBytes: Long) {}
61+
5162
/**
5263
* Called when a depot finishes downloading.
5364
* Use this for printing summary like "Depot 228990 - Downloaded X bytes (Y bytes uncompressed)"

0 commit comments

Comments
 (0)