@@ -11,41 +11,19 @@ import dev.zwander.installwithoptions.data.DataModel
11
11
import net.lingala.zip4j.ZipFile
12
12
import net.lingala.zip4j.exception.ZipException
13
13
import java.io.File
14
- import java.io.FileNotFoundException
15
14
16
15
fun Context.handleIncomingUris (uris : List <Uri >) {
17
16
DataModel .isImporting.value = true
18
17
val currentSelection = DataModel .selectedFiles.value.toMutableMap()
19
18
20
- fun addApkFile (file : DocumentFile ) {
21
- try {
22
- val realFile = if (file.uri.scheme == " file" ) file else run {
23
- contentResolver.openInputStream(file.uri).use { input ->
24
- val dest = File (cacheDir, " ${file.name ? : file.uri} " )
25
- dest.outputStream().use { output ->
26
- input.copyTo(output)
27
- }
28
- DocumentFile .fromFile(dest)
29
- }
30
- }
31
- val apkFile = PackageParser .parseApkLite(File (realFile.uri.path), 0 )
32
- val packageList = currentSelection[apkFile.packageName] ? : listOf ()
33
-
34
- currentSelection[apkFile.packageName] = (packageList + file).distinctBy { " ${apkFile.packageName} :${it.name} " }
35
- } catch (_: PackageParser .PackageParserException ) {
36
- } catch (_: IllegalStateException ) {
37
- } catch (_: FileNotFoundException ) {
38
- }
39
- }
40
-
41
19
uris.forEach { uri ->
42
20
val file = DocumentFile .fromSingleUri(this , uri) ? : return @forEach
43
21
44
22
if (file.isApk) {
45
- addApkFile(file)
23
+ addApkFile(file, currentSelection )
46
24
} else if (file.isSplitBundle) {
47
25
copyZipToCacheAndExtract(file).forEach { innerFile ->
48
- addApkFile(innerFile)
26
+ addApkFile(innerFile, currentSelection )
49
27
}
50
28
}
51
29
}
@@ -54,6 +32,24 @@ fun Context.handleIncomingUris(uris: List<Uri>) {
54
32
DataModel .isImporting.value = false
55
33
}
56
34
35
+ private fun Context.addApkFile (file : DocumentFile , currentSelection : MutableMap <String , List <DocumentFile >>) {
36
+ try {
37
+ val realFile = if (file.uri.scheme == " file" ) file else run {
38
+ contentResolver.openInputStream(file.uri).use { input ->
39
+ val dest = File (cacheDir, " ${file.name ? : file.uri} " )
40
+ dest.outputStream().use { output ->
41
+ input.copyTo(output)
42
+ }
43
+ DocumentFile .fromFile(dest)
44
+ }
45
+ }
46
+ val apkFile = PackageParser .parseApkLite(File (realFile.uri.path), 0 )
47
+ val packageList = currentSelection[apkFile.packageName] ? : listOf ()
48
+
49
+ currentSelection[apkFile.packageName] = (packageList + file).distinctBy { " ${apkFile.packageName} :${it.name} " }
50
+ } catch (_: Throwable ) {}
51
+ }
52
+
57
53
private fun Context.copyZipToCacheAndExtract (zip : DocumentFile ): List <DocumentFile > {
58
54
val destFile = File (cacheDir, zip.name ? : zip.uri.toString())
59
55
val destDir = File (cacheDir, " ${destFile.name} _extracted" ).apply {
0 commit comments