better download progress
This commit is contained in:
@@ -14,8 +14,9 @@ import org.kodein.di.conf.global
|
|||||||
import org.kodein.di.instance
|
import org.kodein.di.instance
|
||||||
import suwayomi.tachidesk.server.ApplicationDirs
|
import suwayomi.tachidesk.server.ApplicationDirs
|
||||||
import suwayomi.tachidesk.server.BuildConfig
|
import suwayomi.tachidesk.server.BuildConfig
|
||||||
import java.io.BufferedInputStream
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.net.HttpURLConnection
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
@@ -58,9 +59,12 @@ fun setupWebUI() {
|
|||||||
val webUIZipFile = File(webUIZipPath)
|
val webUIZipFile = File(webUIZipPath)
|
||||||
|
|
||||||
// try with resources first
|
// try with resources first
|
||||||
val resourceWebUI = try {
|
val resourceWebUI: InputStream? = try {
|
||||||
BuildConfig::class.java.getResourceAsStream("/WebUI.zip")
|
BuildConfig::class.java.getResourceAsStream("/WebUI.zip")
|
||||||
} catch (e: NullPointerException) { null }
|
} catch (e: NullPointerException) {
|
||||||
|
logger.info { "No bundled WebUI.zip found!" }
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
if (resourceWebUI == null) { // is not bundled
|
if (resourceWebUI == null) { // is not bundled
|
||||||
// download webUI zip
|
// download webUI zip
|
||||||
@@ -71,18 +75,25 @@ fun setupWebUI() {
|
|||||||
val data = ByteArray(1024)
|
val data = ByteArray(1024)
|
||||||
|
|
||||||
webUIZipFile.outputStream().use { webUIZipFileOut ->
|
webUIZipFile.outputStream().use { webUIZipFileOut ->
|
||||||
BufferedInputStream(URL(webUIZipURL).openStream()).use { inp ->
|
|
||||||
|
val connection = URL(webUIZipURL).openConnection() as HttpURLConnection
|
||||||
|
connection.connect()
|
||||||
|
val contentLength = connection.contentLength
|
||||||
|
|
||||||
|
connection.inputStream.buffered().use { inp ->
|
||||||
var totalCount = 0
|
var totalCount = 0
|
||||||
var tresh = 0
|
|
||||||
|
print("Download progress: % 00")
|
||||||
while (true) {
|
while (true) {
|
||||||
val count = inp.read(data, 0, 1024)
|
val count = inp.read(data, 0, 1024)
|
||||||
totalCount += count
|
|
||||||
if (totalCount > tresh + 10 * 1024) {
|
|
||||||
tresh = totalCount
|
|
||||||
print(" *")
|
|
||||||
}
|
|
||||||
if (count == -1)
|
if (count == -1)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
totalCount += count
|
||||||
|
val percentage = (totalCount.toFloat() / contentLength * 100).toInt().toString().padStart(2, '0')
|
||||||
|
print("\b\b$percentage")
|
||||||
|
|
||||||
webUIZipFileOut.write(data, 0, count)
|
webUIZipFileOut.write(data, 0, count)
|
||||||
}
|
}
|
||||||
println()
|
println()
|
||||||
|
|||||||
Reference in New Issue
Block a user