File tree 2 files changed +25
-15
lines changed
library/src/main/kotlin/dev/jahir/kuper
2 files changed +25
-15
lines changed Original file line number Diff line number Diff line change 3
3
package dev.jahir.kuper.data.viewmodels
4
4
5
5
import android.app.Application
6
+ import android.os.Build
6
7
import android.util.Log
7
8
import androidx.lifecycle.AndroidViewModel
8
9
import androidx.lifecycle.LifecycleOwner
9
10
import androidx.lifecycle.MutableLiveData
10
11
import androidx.lifecycle.viewModelScope
12
+ import dalvik.system.ZipPathValidator
11
13
import dev.jahir.frames.extensions.resources.createIfDidNotExist
12
14
import dev.jahir.frames.extensions.resources.deleteEverything
13
15
import dev.jahir.frames.extensions.resources.hasContent
@@ -130,12 +132,13 @@ class ComponentsViewModel(application: Application) : AndroidViewModel(applicati
130
132
ins.close()
131
133
132
134
if (file.exists() && file.length() > 0 ) {
133
- val zipFile = try {
134
- ZipFile (file)
135
+ try {
136
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) {
137
+ ZipPathValidator .clearCallback()
138
+ }
135
139
} catch (_: Exception ) {
136
- null
137
140
}
138
- if (zipFile != = null ) {
141
+ ZipFile (file). let { zipFile ->
139
142
val entries = zipFile.entries()
140
143
while (entries.hasMoreElements()) {
141
144
val entry = entries.nextElement()
Original file line number Diff line number Diff line change @@ -9,13 +9,17 @@ import java.util.zip.ZipFile
9
9
10
10
private fun InputStream.copyFilesTo (os : OutputStream ) {
11
11
try {
12
- val buffer = ByteArray (2048 )
13
- var readInt = 0
14
- while ({ readInt = read(buffer);readInt }() != - 1 ) os.write(buffer, 0 , readInt)
15
- } catch (e: Exception ) {
12
+ val buffer = ByteArray (4096 )
13
+ var bytes = 0
14
+ while (read(buffer).also { bytes = it } != - 1 )
15
+ os.write(buffer, 0 , bytes)
16
+ } catch (_: Exception ) {
16
17
} finally {
17
- os.flush()
18
- os.close()
18
+ try {
19
+ os.flush()
20
+ os.close()
21
+ } catch (_: Exception ) {
22
+ }
19
23
}
20
24
}
21
25
@@ -27,10 +31,13 @@ fun ZipFile.copyFromTo(from: ZipEntry, to: File?) {
27
31
zipOut = FileOutputStream (to)
28
32
zipIn = getInputStream(from)
29
33
zipIn.copyFilesTo(zipOut)
30
- } catch (e : Exception ) {
34
+ } catch (_ : Exception ) {
31
35
} finally {
32
- zipIn?.close()
33
- zipOut?.flush()
34
- zipOut?.close()
36
+ try {
37
+ zipIn?.close()
38
+ zipOut?.flush()
39
+ zipOut?.close()
40
+ } catch (_: Exception ) {
41
+ }
35
42
}
36
- }
43
+ }
You can’t perform that action at this time.
0 commit comments