diff --git a/library/src/main/kotlin/dev/jahir/kuper/data/viewmodels/ComponentsViewModel.kt b/library/src/main/kotlin/dev/jahir/kuper/data/viewmodels/ComponentsViewModel.kt index 26b41df6..ed0cb389 100644 --- a/library/src/main/kotlin/dev/jahir/kuper/data/viewmodels/ComponentsViewModel.kt +++ b/library/src/main/kotlin/dev/jahir/kuper/data/viewmodels/ComponentsViewModel.kt @@ -3,11 +3,13 @@ package dev.jahir.kuper.data.viewmodels import android.app.Application +import android.os.Build import android.util.Log import androidx.lifecycle.AndroidViewModel import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope +import dalvik.system.ZipPathValidator import dev.jahir.frames.extensions.resources.createIfDidNotExist import dev.jahir.frames.extensions.resources.deleteEverything import dev.jahir.frames.extensions.resources.hasContent @@ -130,12 +132,13 @@ class ComponentsViewModel(application: Application) : AndroidViewModel(applicati ins.close() if (file.exists() && file.length() > 0) { - val zipFile = try { - ZipFile(file) + try { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + ZipPathValidator.clearCallback() + } } catch (_: Exception) { - null } - if (zipFile !== null) { + ZipFile(file).let { zipFile -> val entries = zipFile.entries() while (entries.hasMoreElements()) { val entry = entries.nextElement() diff --git a/library/src/main/kotlin/dev/jahir/kuper/extensions/File.kt b/library/src/main/kotlin/dev/jahir/kuper/extensions/File.kt index 89c27d1a..07413422 100644 --- a/library/src/main/kotlin/dev/jahir/kuper/extensions/File.kt +++ b/library/src/main/kotlin/dev/jahir/kuper/extensions/File.kt @@ -9,13 +9,17 @@ import java.util.zip.ZipFile private fun InputStream.copyFilesTo(os: OutputStream) { try { - val buffer = ByteArray(2048) - var readInt = 0 - while ({ readInt = read(buffer);readInt }() != -1) os.write(buffer, 0, readInt) - } catch (e: Exception) { + val buffer = ByteArray(4096) + var bytes = 0 + while (read(buffer).also { bytes = it } != -1) + os.write(buffer, 0, bytes) + } catch (_: Exception) { } finally { - os.flush() - os.close() + try { + os.flush() + os.close() + } catch (_: Exception) { + } } } @@ -27,10 +31,13 @@ fun ZipFile.copyFromTo(from: ZipEntry, to: File?) { zipOut = FileOutputStream(to) zipIn = getInputStream(from) zipIn.copyFilesTo(zipOut) - } catch (e: Exception) { + } catch (_: Exception) { } finally { - zipIn?.close() - zipOut?.flush() - zipOut?.close() + try { + zipIn?.close() + zipOut?.flush() + zipOut?.close() + } catch (_: Exception) { + } } -} \ No newline at end of file +}