Skip to content

Commit fd7b81c

Browse files
committed
Test mutilple repos
1 parent 4bad22f commit fd7b81c

File tree

7 files changed

+85
-46
lines changed

7 files changed

+85
-46
lines changed

module/module.prop

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
id=mmrl
22
name=MMRL CLI
3-
version=0.1.1
4-
versionCode=011
3+
version=0.1.2
4+
versionCode=012
55
author=Der_Googler
66
description=MMRL Command Line Interface is a free tool to install Magisk/KernelSU modules. Build on 2023-10-21 with Rust 1.73.0.

src/cmd/download.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use crate::{
22
android_root::get_downloads_dir,
3-
repo::{find_module, find_version, get_id_details, Repo},
3+
repo::{find_module, find_version, get_id_details, Module},
44
utils::{download_from_url, is_url, get_last},
55
};
66
use reqwest::Client;
77

8-
pub async fn download(client: Client, json: &Repo, id: String) -> () {
8+
pub async fn download(client: Client, modules: &Vec<Module>, id: String) -> () {
99
let _url = &id.to_owned()[..];
1010
if !is_url(_url) {
1111
let (_id, _ver) = get_id_details(id);
12-
let module = find_module(&json, _id.clone());
12+
let module = find_module(&modules, _id.clone());
1313

1414
let version = find_version(module.versions.clone(), _ver);
1515
println!("Downloading {}", module.name);

src/cmd/info.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use std::path::Path;
22

33
use ini::Ini;
44

5-
use crate::repo::{find_module, Repo};
5+
use crate::repo::{find_module, Module};
66

7-
pub async fn info(json: &Repo, id: String) {
8-
let module = find_module(&json, id);
7+
pub async fn info(modules: &Vec<Module>, id: String) {
8+
let module = find_module(&modules, id);
99

1010
let _id = &module.id;
1111

src/cmd/install.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ extern crate serde_ini;
33

44
use crate::utils::{confirm, download_from_url, get_last, get_mmrl_json, is_url};
55
use crate::android_root::{get_downloads_dir, get_install_cli};
6-
use crate::repo::{find_module, find_version, get_id_details, Repo};
6+
use crate::repo::{find_module, find_version, get_id_details, Module};
77
use reqwest::Client;
88
use async_recursion::async_recursion;
99
use std::io::{BufRead, BufReader, Error, ErrorKind};
@@ -16,7 +16,7 @@ async fn check_requires(
1616
install_requires: bool,
1717
client: Client,
1818
yes: bool,
19-
json: &Repo,
19+
modules: &Vec<Module>,
2020
) {
2121
let mini = get_mmrl_json(&path);
2222

@@ -30,7 +30,7 @@ async fn check_requires(
3030
if !(dep_path_update.exists() || dep_path.exists()) {
3131
if install_requires {
3232
println!("Install requires");
33-
install(client.clone(), yes, install_requires, json, req).await;
33+
install(client.clone(), yes, install_requires, modules, req).await;
3434
} else {
3535
println!("This module requires {} to be installed", req.clone());
3636
exit(1)
@@ -40,11 +40,11 @@ async fn check_requires(
4040
}
4141

4242
#[async_recursion]
43-
pub async fn install(client: Client, yes: bool, requires: bool, json: &Repo, id: String) {
43+
pub async fn install(client: Client, yes: bool, requires: bool, modules: &Vec<Module>, id: String) {
4444
let _url = &id.to_owned()[..];
4545
if !is_url(_url) {
4646
let (_id, _ver) = get_id_details(id);
47-
let module = find_module(&json, _id.clone());
47+
let module = find_module(&modules, _id.clone());
4848
let version = find_version(module.versions.clone(), _ver);
4949

5050
let path = &[
@@ -61,7 +61,7 @@ pub async fn install(client: Client, yes: bool, requires: bool, json: &Repo, id:
6161
println!("Version: {}", &version.version);
6262

6363
download_from_url(client.clone(), version.zip_url, module.name, path).await;
64-
check_requires(path.clone(), requires, client.clone(), yes, json).await;
64+
check_requires(path.clone(), requires, client.clone(), yes, modules).await;
6565

6666
let success = yes || confirm("Do you want to continue [y/N]? ");
6767

@@ -94,7 +94,7 @@ pub async fn install(client: Client, yes: bool, requires: bool, json: &Repo, id:
9494
]
9595
.join("/");
9696
download_from_url(client.clone(), id.clone(), name.unwrap(), path).await;
97-
check_requires(path.clone(), requires, client.clone(), yes, json).await;
97+
check_requires(path.clone(), requires, client.clone(), yes, modules).await;
9898

9999
println!("Info not availabe in url install");
100100
let success = yes || confirm("\nDo you want to continue [y/N]? ");

src/cmd/search.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use crate::repo::{Module, Repo};
1+
use crate::repo::Module;
22

3-
pub async fn search(json: Repo, cb: impl Fn(&Module) -> bool) {
3+
pub async fn search(modules: Vec<Module>, cb: impl Fn(&Module) -> bool) {
44
print!("\x1B[1mFound these modules:\x1B[0m\n\n");
5-
for module in json.modules {
5+
for module in modules {
66
let m = module.clone();
77
if cb(&m) {
88
println!(

src/main.rs

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ pub mod android_root;
44
pub mod cmd;
55
pub mod repo;
66
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;
811

912
use clap::{Parser, Subcommand};
1013
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+
};
1220

1321
#[derive(Debug, Subcommand)]
1422
enum SearchCommands {
@@ -84,30 +92,61 @@ enum Commands {
8492
#[derive(Parser, Debug)]
8593
#[command(author, version, about, long_about = None)]
8694
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-
9195
#[clap(subcommand)]
9296
commands: Commands,
9397
}
9498

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+
95129
#[tokio::main]
96130
async fn main() {
131+
setup();
97132
let client = reqwest::Client::new();
98133
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!("\nSelected 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+
}
106145

107146
match args.commands {
108147
Commands::Info { ids } => {
109148
for id in ids {
110-
info(&json, id).await;
149+
info(&modules, id).await;
111150
}
112151
exit(0);
113152
}
@@ -117,7 +156,7 @@ async fn main() {
117156
}
118157
Commands::Search { commands } => match commands {
119158
SearchCommands::All { query } => {
120-
search(json.clone(), |module| {
159+
search(modules.clone(), |module| {
121160
module.id.to_lowercase().contains(&query.to_lowercase())
122161
|| module.name.to_lowercase().contains(&query.to_lowercase())
123162
|| module
@@ -134,28 +173,28 @@ async fn main() {
134173
exit(0);
135174
}
136175
SearchCommands::Id { query } => {
137-
search(json.clone(), |module| {
176+
search(modules.clone(), |module| {
138177
module.id.to_lowercase().contains(&query.to_lowercase())
139178
})
140179
.await;
141180
exit(0);
142181
}
143182
SearchCommands::Name { query } => {
144-
search(json.clone(), |module| {
183+
search(modules.clone(), |module| {
145184
module.name.to_lowercase().contains(&query.to_lowercase())
146185
})
147186
.await;
148187
exit(0);
149188
}
150189
SearchCommands::Author { query } => {
151-
search(json.clone(), |module| {
190+
search(modules.clone(), |module| {
152191
module.author.to_lowercase().contains(&query.to_lowercase())
153192
})
154193
.await;
155194
exit(0);
156195
}
157196
SearchCommands::Description { query } => {
158-
search(json.clone(), |module| {
197+
search(modules.clone(), |module| {
159198
module
160199
.description
161200
.to_lowercase()
@@ -165,7 +204,7 @@ async fn main() {
165204
exit(0);
166205
}
167206
SearchCommands::Version { query } => {
168-
search(json.clone(), |module| {
207+
search(modules.clone(), |module| {
169208
module
170209
.version
171210
.to_lowercase()
@@ -175,7 +214,7 @@ async fn main() {
175214
exit(0);
176215
}
177216
SearchCommands::License { query } => {
178-
search(json.clone(), |module| {
217+
search(modules.clone(), |module| {
179218
module
180219
.track
181220
.license
@@ -186,9 +225,9 @@ async fn main() {
186225
exit(0);
187226
}
188227
},
189-
Commands::Install { yes, requires, ids } => {
228+
Commands::Install { yes, requires, ids } => {
190229
for id in ids {
191-
install(client.clone(), yes, requires, &json, id).await;
230+
install(client.clone(), yes, requires, &modules, id).await;
192231
}
193232
exit(0);
194233
}
@@ -256,7 +295,7 @@ async fn main() {
256295
// }
257296
Commands::Download { ids } => {
258297
for id in ids {
259-
download(client.clone(), &json, id).await;
298+
download(client.clone(), &modules, id).await;
260299
}
261300
exit(0);
262301
}

src/repo.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ pub struct Version {
5454
pub changelog: String,
5555
}
5656

57-
pub(crate) fn find_module(json: &Repo, id: String) -> Module {
58-
let module_exists = json.modules.iter().any(|m| m.id == id);
57+
pub(crate) fn find_module(modules: &Vec<Module>, id: String) -> Module {
58+
let module_exists = modules.iter().any(|m| m.id == id);
5959
if !module_exists {
6060
println!("Unable to find {}", id);
6161
exit(1);
6262
}
63-
let module_pos = json.modules.iter().position(|m| m.id == id).unwrap();
64-
return json.modules[module_pos].clone();
63+
let module_pos = modules.iter().position(|m| m.id == id).unwrap();
64+
return modules[module_pos].clone();
6565
}
6666

6767
pub(crate) fn find_version(versions: Vec<Version>, version_name: String) -> Version {

0 commit comments

Comments
 (0)