@@ -4,11 +4,19 @@ pub mod android_root;
4
4
pub mod cmd;
5
5
pub mod repo;
6
6
pub mod utils;
7
- use crate :: cmd:: { download:: download, info:: info, install:: install, search:: search, upself:: upself} ;
7
+ use crate :: cmd:: {
8
+ download:: download, info:: info, install:: install, search:: search, upself:: upself,
9
+ } ;
10
+ use crate :: repo:: Module ;
8
11
9
12
use clap:: { Parser , Subcommand } ;
10
13
use repo:: Repo ;
11
- use std:: process:: exit;
14
+ use std:: io:: { Read , Write } ;
15
+ use std:: {
16
+ fs:: { self , File } ,
17
+ path:: Path ,
18
+ process:: exit,
19
+ } ;
12
20
13
21
#[ derive( Debug , Subcommand ) ]
14
22
enum SearchCommands {
@@ -84,30 +92,61 @@ enum Commands {
84
92
#[ derive( Parser , Debug ) ]
85
93
#[ command( author, version, about, long_about = None ) ]
86
94
struct Args {
87
- /// Were the modules comes from
88
- #[ arg( short, long, default_value_t = String :: from( "https://raw.githubusercontent.com/ya0211/magisk-modules-alt-repo/main/json/modules.json" ) ) ]
89
- repo : String ,
90
-
91
95
#[ clap( subcommand) ]
92
96
commands : Commands ,
93
97
}
94
98
99
+ fn setup ( ) {
100
+ let file_path = Path :: new ( "/data/adb/mmrl/repos.list" ) ; // Replace with the desired file path
101
+
102
+ if !file_path. exists ( ) {
103
+ // Create all directories in the path if they don't exist
104
+ if let Some ( parent_dir) = file_path. parent ( ) {
105
+ if !parent_dir. exists ( ) {
106
+ if let Err ( err) = fs:: create_dir_all ( parent_dir) {
107
+ eprintln ! ( "Error creating directories: {}" , err) ;
108
+ return ;
109
+ }
110
+ }
111
+ }
112
+
113
+ // Create the file
114
+ let mut file = match File :: create ( & file_path) {
115
+ Ok ( file) => file,
116
+ Err ( err) => {
117
+ eprintln ! ( "Error creating file: {}" , err) ;
118
+ return ;
119
+ }
120
+ } ;
121
+
122
+ // You can write to the file if needed
123
+ if let Err ( err) = writeln ! ( file, "https://raw.githubusercontent.com/ya0211/magisk-modules-alt-repo/main/json/modules.json;" ) {
124
+ eprintln ! ( "Error writing to file: {}" , err) ;
125
+ }
126
+ }
127
+ }
128
+
95
129
#[ tokio:: main]
96
130
async fn main ( ) {
131
+ setup ( ) ;
97
132
let client = reqwest:: Client :: new ( ) ;
98
133
let args = Args :: parse ( ) ;
99
-
100
- let response = client. get ( args. repo ) . send ( ) . await . unwrap ( ) ;
101
-
102
- let json: Repo = response. json ( ) . await . unwrap ( ) ;
103
-
104
- println ! ( "\n Selected Repo: {}\n " , json. name) ;
105
- // println!("Root manager: {}\n", &get_root_manager());
134
+ let mut modules: Vec < Module > = vec ! [ ] ;
135
+ let mut file = File :: open ( "example.txt" ) . unwrap ( ) ;
136
+ let mut contents = String :: new ( ) ;
137
+ file. read_to_string ( & mut contents) . unwrap ( ) ;
138
+ println ! ( "Available repos:" ) ;
139
+ for repo in contents. split ( ";" ) {
140
+ let response = client. get ( repo) . send ( ) . await . unwrap ( ) ;
141
+ let mut json: Repo = response. json ( ) . await . unwrap ( ) ;
142
+ println ! ( "{}" , json. name) ;
143
+ modules. append ( & mut json. modules ) ;
144
+ }
106
145
107
146
match args. commands {
108
147
Commands :: Info { ids } => {
109
148
for id in ids {
110
- info ( & json , id) . await ;
149
+ info ( & modules , id) . await ;
111
150
}
112
151
exit ( 0 ) ;
113
152
}
@@ -117,7 +156,7 @@ async fn main() {
117
156
}
118
157
Commands :: Search { commands } => match commands {
119
158
SearchCommands :: All { query } => {
120
- search ( json . clone ( ) , |module| {
159
+ search ( modules . clone ( ) , |module| {
121
160
module. id . to_lowercase ( ) . contains ( & query. to_lowercase ( ) )
122
161
|| module. name . to_lowercase ( ) . contains ( & query. to_lowercase ( ) )
123
162
|| module
@@ -134,28 +173,28 @@ async fn main() {
134
173
exit ( 0 ) ;
135
174
}
136
175
SearchCommands :: Id { query } => {
137
- search ( json . clone ( ) , |module| {
176
+ search ( modules . clone ( ) , |module| {
138
177
module. id . to_lowercase ( ) . contains ( & query. to_lowercase ( ) )
139
178
} )
140
179
. await ;
141
180
exit ( 0 ) ;
142
181
}
143
182
SearchCommands :: Name { query } => {
144
- search ( json . clone ( ) , |module| {
183
+ search ( modules . clone ( ) , |module| {
145
184
module. name . to_lowercase ( ) . contains ( & query. to_lowercase ( ) )
146
185
} )
147
186
. await ;
148
187
exit ( 0 ) ;
149
188
}
150
189
SearchCommands :: Author { query } => {
151
- search ( json . clone ( ) , |module| {
190
+ search ( modules . clone ( ) , |module| {
152
191
module. author . to_lowercase ( ) . contains ( & query. to_lowercase ( ) )
153
192
} )
154
193
. await ;
155
194
exit ( 0 ) ;
156
195
}
157
196
SearchCommands :: Description { query } => {
158
- search ( json . clone ( ) , |module| {
197
+ search ( modules . clone ( ) , |module| {
159
198
module
160
199
. description
161
200
. to_lowercase ( )
@@ -165,7 +204,7 @@ async fn main() {
165
204
exit ( 0 ) ;
166
205
}
167
206
SearchCommands :: Version { query } => {
168
- search ( json . clone ( ) , |module| {
207
+ search ( modules . clone ( ) , |module| {
169
208
module
170
209
. version
171
210
. to_lowercase ( )
@@ -175,7 +214,7 @@ async fn main() {
175
214
exit ( 0 ) ;
176
215
}
177
216
SearchCommands :: License { query } => {
178
- search ( json . clone ( ) , |module| {
217
+ search ( modules . clone ( ) , |module| {
179
218
module
180
219
. track
181
220
. license
@@ -186,9 +225,9 @@ async fn main() {
186
225
exit ( 0 ) ;
187
226
}
188
227
} ,
189
- Commands :: Install { yes, requires, ids } => {
228
+ Commands :: Install { yes, requires, ids } => {
190
229
for id in ids {
191
- install ( client. clone ( ) , yes, requires, & json , id) . await ;
230
+ install ( client. clone ( ) , yes, requires, & modules , id) . await ;
192
231
}
193
232
exit ( 0 ) ;
194
233
}
@@ -256,7 +295,7 @@ async fn main() {
256
295
// }
257
296
Commands :: Download { ids } => {
258
297
for id in ids {
259
- download ( client. clone ( ) , & json , id) . await ;
298
+ download ( client. clone ( ) , & modules , id) . await ;
260
299
}
261
300
exit ( 0 ) ;
262
301
}
0 commit comments