@@ -6,9 +6,7 @@ import app.revanced.patcher.PatcherOptions
6
6
import app.revanced.patcher.extensions.PatchExtensions.patchName
7
7
import app.revanced.patcher.util.patch.implementation.JarPatchBundle
8
8
import app.revanced.utils.adb.Adb
9
- import picocli.CommandLine.Command
10
- import picocli.CommandLine.Option
11
- import picocli.CommandLine.ArgGroup
9
+ import picocli.CommandLine.*
12
10
import java.io.File
13
11
import java.nio.file.Files
14
12
@@ -17,92 +15,96 @@ import java.nio.file.Files
17
15
)
18
16
internal object MainCommand : Runnable {
19
17
20
- @ArgGroup(exclusive = false , multiplicity= " 1" )
21
- lateinit var args: Args
22
-
23
- class Args
24
- {
25
- @Option(names = [" -b" , " --bundles" ], description = [" One or more bundles of patches" ], required = true )
26
- var patchBundles = arrayOf<String >()
27
-
28
- @ArgGroup(exclusive = false )
29
- lateinit var lArgs: ListingArgs
30
-
31
- @ArgGroup(exclusive = false )
32
- lateinit var pArgs: PatchingArgs
33
- }
34
-
35
- class ListingArgs {
36
- @Option(names = [" -l" , " --list" ], description = [" List patches only" ], required = true )
37
- public var listOnly: Boolean = false
38
- }
39
-
40
- class PatchingArgs {
41
- @Option(names = [" -a" , " --apk" ], description = [" Input file to be patched" ], required = true )
42
- lateinit var inputFile: File
43
-
44
- @Option(names = [" -o" , " --out" ], description = [" Output file path" ], required = true )
45
- lateinit var outputPath: String
46
-
47
- @Option(
48
- names = [" -i" , " --include" ],
49
- description = [" Which patches to include. If none is specified, all compatible default patches will be included" ]
50
- )
51
- var includedPatches = arrayOf<String >()
52
-
53
- @Option(names = [" -r" , " --resource-patcher" ], description = [" Disable patching resources" ])
54
- var disableResourcePatching: Boolean = false
55
-
56
- @Option(names = [" --debugging" ], description = [" Disable patch version compatibility" ])
57
- var debugging: Boolean = false
58
-
59
- @Option(names = [" -m" , " --merge" ], description = [" One or more dex file containers to merge" ])
60
- var mergeFiles = listOf<File >()
61
-
62
- @Option(names = [" --install" ], description = [" If specified, instead of mounting, install" ])
63
- var install: Boolean = false
64
-
65
- @Option(names = [" --cn" ], description = [" Overwrite the default CN for the signed file" ])
66
- var cn = " ReVanced"
67
-
68
- @Option(names = [" -p" , " --password" ], description = [" Overwrite the default password for the signed file" ])
69
- var password = " ReVanced"
70
-
71
- @Option(names = [" -d" , " --deploy-on" ], description = [" If specified, deploy to adb device with given name" ])
72
- var deploy: String? = null
73
-
74
- @Option(names = [" -t" , " --temp-dir" ], description = [" Temporal resource cache directory" ])
75
- var cacheDirectory = " revanced-cache"
76
-
77
- @Option(
78
- names = [" -c" , " --clean" ],
79
- description = [" Clean the temporal resource cache directory. This will be done anyways when running the patcher" ]
80
- )
81
- var clean: Boolean = false
82
- }
83
-
84
- override fun run () {
85
- try
86
- {
87
- if (args.lArgs.listOnly) {
88
- for (patchBundlePath in args.patchBundles) for (patch in JarPatchBundle (patchBundlePath).loadPatches()) {
89
- println (" [available] ${patch.patchName} " )
90
- }
91
- return
92
- }
93
- } catch (e: UninitializedPropertyAccessException ) {}
94
-
95
- val args = args.pArgs;
96
-
97
- val patcher = app.revanced.patcher.Patcher (PatcherOptions (args.inputFile, args.cacheDirectory, ! args.disableResourcePatching))
18
+ @ArgGroup(exclusive = false , multiplicity = " 1" )
19
+ lateinit var args: Args
20
+
21
+ class Args {
22
+ @Option(names = [" -b" , " --bundles" ], description = [" One or more bundles of patches" ], required = true )
23
+ var patchBundles = arrayOf<String >()
24
+
25
+ @ArgGroup(exclusive = false )
26
+ lateinit var lArgs: ListingArgs
27
+
28
+ @ArgGroup(exclusive = false )
29
+ lateinit var pArgs: PatchingArgs
30
+ }
31
+
32
+ class ListingArgs {
33
+ @Option(names = [" -l" , " --list" ], description = [" List patches only" ], required = true )
34
+ var listOnly: Boolean = false
35
+ }
36
+
37
+ class PatchingArgs {
38
+ @Option(names = [" -a" , " --apk" ], description = [" Input file to be patched" ], required = true )
39
+ lateinit var inputFile: File
40
+
41
+ @Option(names = [" -o" , " --out" ], description = [" Output file path" ], required = true )
42
+ lateinit var outputPath: String
43
+
44
+ @Option(
45
+ names = [" -i" , " --include" ],
46
+ description = [" Which patches to include. If none is specified, all compatible default patches will be included" ]
47
+ )
48
+ var includedPatches = arrayOf<String >()
49
+
50
+ @Option(names = [" -r" , " --resource-patcher" ], description = [" Disable patching resources" ])
51
+ var disableResourcePatching: Boolean = false
52
+
53
+ @Option(names = [" --debugging" ], description = [" Disable patch version compatibility" ])
54
+ var debugging: Boolean = false
55
+
56
+ @Option(names = [" -m" , " --merge" ], description = [" One or more dex file containers to merge" ])
57
+ var mergeFiles = listOf<File >()
58
+
59
+ @Option(names = [" --install" ], description = [" If specified, instead of mounting, install" ])
60
+ var install: Boolean = false
61
+
62
+ @Option(names = [" --cn" ], description = [" Overwrite the default CN for the signed file" ])
63
+ var cn = " ReVanced"
64
+
65
+ @Option(names = [" -p" , " --password" ], description = [" Overwrite the default password for the signed file" ])
66
+ var password = " ReVanced"
67
+
68
+ @Option(names = [" -d" , " --deploy-on" ], description = [" If specified, deploy to adb device with given name" ])
69
+ var deploy: String? = null
70
+
71
+ @Option(names = [" -t" , " --temp-dir" ], description = [" Temporal resource cache directory" ])
72
+ var cacheDirectory = " revanced-cache"
73
+
74
+ @Option(
75
+ names = [" -c" , " --clean" ],
76
+ description = [" Clean the temporal resource cache directory. This will be done anyways when running the patcher" ]
77
+ )
78
+ var clean: Boolean = false
79
+ }
80
+
81
+ override fun run () {
82
+ try {
83
+ if (args.lArgs.listOnly) {
84
+ for (patchBundlePath in args.patchBundles) for (patch in JarPatchBundle (patchBundlePath).loadPatches()) {
85
+ println (" [available] ${patch.patchName} " )
86
+ }
87
+ return
88
+ }
89
+ } catch (_: UninitializedPropertyAccessException ) {
90
+ }
91
+
92
+ val args = args.pArgs
93
+
94
+ val patcher = app.revanced.patcher.Patcher (
95
+ PatcherOptions (
96
+ args.inputFile, args.cacheDirectory, ! args.disableResourcePatching
97
+ )
98
+ )
98
99
99
100
val outputFile = File (args.outputPath)
100
101
101
102
val adb: Adb ? = args.deploy?.let {
102
103
Adb (outputFile, patcher.data.packageMetadata.packageName, args.deploy!! , args.install)
103
104
}
104
105
105
- val patchedFile = if (args.install) File (args.cacheDirectory).resolve(" ${outputFile.nameWithoutExtension} _raw.apk" ) else outputFile
106
+ val patchedFile =
107
+ if (args.install) File (args.cacheDirectory).resolve(" ${outputFile.nameWithoutExtension} _raw.apk" ) else outputFile
106
108
107
109
Patcher .start(patcher, patchedFile)
108
110
0 commit comments