@@ -5,9 +5,12 @@ import app.revanced.cli.utils.Patches
5
5
import app.revanced.cli.utils.Preconditions
6
6
import app.revanced.cli.utils.SignatureParser
7
7
import app.revanced.patcher.Patcher
8
+ import app.revanced.patcher.patch.PatchResult
8
9
import kotlinx.cli.ArgParser
9
10
import kotlinx.cli.ArgType
10
11
import kotlinx.cli.required
12
+ import me.tongfei.progressbar.ProgressBarBuilder
13
+ import me.tongfei.progressbar.ProgressBarStyle
11
14
import java.io.File
12
15
import java.nio.file.Files
13
16
@@ -23,35 +26,71 @@ class Main {
23
26
inIntegrations : String? ,
24
27
inOutput : String ,
25
28
) {
29
+ val bar = ProgressBarBuilder ()
30
+ .setTaskName(" Working.." )
31
+ .setUpdateIntervalMillis(25 )
32
+ .continuousUpdate()
33
+ .setStyle(ProgressBarStyle .ASCII )
34
+ .build()
35
+ .maxHint(1 )
36
+ .setExtraMessage(" Initializing" )
26
37
val apk = Preconditions .isFile(inApk)
27
38
val signatures = Preconditions .isFile(inSignatures)
28
39
val patchesFile = Preconditions .isFile(inPatches)
29
40
val output = Preconditions .isDirectory(inOutput)
41
+ bar.step()
30
42
31
43
val patcher = Patcher (
32
44
apk,
33
- SignatureParser
34
- .parse(signatures.readText())
35
- .toTypedArray()
45
+ SignatureParser .parse(signatures.readText(), bar)
36
46
)
37
47
38
48
inIntegrations?.let {
49
+ bar.reset().maxHint(1 )
50
+ .extraMessage = " Merging integrations"
39
51
val integrations = Preconditions .isFile(it)
40
52
patcher.addFiles(integrations)
53
+ bar.step()
41
54
}
42
55
56
+ bar.reset().maxHint(1 )
57
+ .extraMessage = " Loading patches"
43
58
PatchLoader .injectPatches(patchesFile)
44
- val patches = Patches .loadPatches()
45
- patcher.addPatches(* patches.map { it() }.toTypedArray())
59
+ bar.step()
46
60
47
- val results = patcher.applyPatches()
48
- for ((name, result) in results) {
49
- println (" $name : $result " )
61
+ val patches = Patches .loadPatches().map { it() }
62
+ patcher.addPatches(patches)
63
+
64
+ val amount = patches.size.toLong()
65
+ bar.reset().maxHint(amount)
66
+ .extraMessage = " Applying patches"
67
+ val results = patcher.applyPatches {
68
+ bar.step().extraMessage = " Applying $it "
50
69
}
51
70
71
+ bar.reset().maxHint(- 1 )
72
+ .extraMessage = " Generating dex files"
52
73
val dexFiles = patcher.save()
74
+ bar.reset().maxHint(dexFiles.size.toLong())
75
+ .extraMessage = " Saving dex files"
53
76
dexFiles.forEach { (dexName, dexData) ->
54
77
Files .write(File (output, dexName).toPath(), dexData.buffer)
78
+ bar.step()
79
+ }
80
+ bar.close()
81
+
82
+ println (" All done!" )
83
+ printResults(results)
84
+ }
85
+
86
+ private fun printResults (results : Map <String , Result <PatchResult >>) {
87
+ for ((name, result) in results) {
88
+ if (result.isSuccess) {
89
+ println (" Patch $name was applied successfully!" )
90
+ } else {
91
+ println (" Patch $name failed to apply! Cause:" )
92
+ result.exceptionOrNull()!! .printStackTrace()
93
+ }
55
94
}
56
95
}
57
96
0 commit comments