@@ -2,61 +2,48 @@ package cn.kaicity.common.repository
2
2
3
3
import cn.kaicity.common.bean.InputBean
4
4
import cn.kaicity.common.platform.IObfuscator
5
- import kotlinx.coroutines.DelicateCoroutinesApi
6
5
import kotlinx.coroutines.Dispatchers
7
- import kotlinx.coroutines.GlobalScope
8
- import kotlinx.coroutines.Job
9
6
import kotlinx.coroutines.flow.catch
10
7
import kotlinx.coroutines.flow.collect
11
8
import kotlinx.coroutines.flow.flow
12
9
import kotlinx.coroutines.flow.flowOn
13
10
import kotlinx.coroutines.flow.onCompletion
14
- import kotlinx.coroutines.launch
15
11
import java.io.File
16
- import kotlin.math.log
17
12
18
13
object DexObf {
19
14
20
15
private var obfuscatorImpl: IObfuscator ? = null
21
16
22
- private var job: Job ? = null
23
-
24
- @OptIn(DelicateCoroutinesApi ::class )
25
- fun run (inputBean : InputBean , logCallback : (log: String ) -> Unit ) {
26
- job?.cancel()
27
-
28
- job = GlobalScope .launch(Dispatchers .IO ) {
29
- val params = arrayListOf<String >()
30
- params.add(" -i" )
31
- params.add(inputBean.input)
32
-
33
- params.add(" -o" )
34
- params.add(inputBean.output)
35
-
36
- params.add(" -d" )
37
- params.add(inputBean.depth)
38
-
39
- params.add(" -a" )
40
-
41
- val filterFile = File (File (inputBean.output).parentFile, " filter.txt" )
42
- filterFile.writeText(inputBean.rule)
43
- params.add(filterFile.absolutePath)
44
-
45
-
46
- flow<String > { }.flowOn(Dispatchers .IO )
47
- .collect()
48
- flow {
49
- obfuscatorImpl = IObfuscator (this )
50
- obfuscatorImpl?.doObfuscator(params.toTypedArray())
51
- }.catch {
52
- logCallback.invoke(" Error" )
53
- }.onCompletion {
54
- filterFile.delete()
55
- logCallback.invoke(" Finish" )
56
- }.flowOn(Dispatchers .IO )
57
- .collect {
58
- logCallback.invoke(it)
59
- }
60
- }
17
+ suspend fun run (inputBean : InputBean , logCallback : (log: String ) -> Unit ) {
18
+ val params = arrayListOf<String >()
19
+ params.add(" -i" )
20
+ params.add(inputBean.input)
21
+
22
+ params.add(" -o" )
23
+ params.add(inputBean.output)
24
+
25
+ params.add(" -d" )
26
+ params.add(inputBean.depth)
27
+
28
+ params.add(" -a" )
29
+
30
+ val filterFile = File (File (inputBean.output).parentFile, " filter.txt" )
31
+ filterFile.writeText(inputBean.rule)
32
+ params.add(filterFile.absolutePath)
33
+
34
+
35
+ flow {
36
+ obfuscatorImpl = IObfuscator (this )
37
+ obfuscatorImpl?.doObfuscator(params.toTypedArray())
38
+ }.catch {
39
+ logCallback.invoke(" Error" )
40
+ }.onCompletion {
41
+ filterFile.delete()
42
+ logCallback.invoke(" Finish" )
43
+ }.flowOn(Dispatchers .IO )
44
+ .collect {
45
+ logCallback.invoke(it)
46
+ }
61
47
}
48
+
62
49
}
0 commit comments