Skip to content

Commit 5445241

Browse files
committed
Add module state change
1 parent dd66d59 commit 5445241

File tree

2 files changed

+63
-73
lines changed

2 files changed

+63
-73
lines changed

src/android_root.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
use std::{
2-
env, io,
2+
env,
3+
fs::File,
4+
io::{self, Write},
35
path::{Path, PathBuf},
46
process::exit,
57
};
68

9+
use ini::Ini;
10+
711
#[cfg(target_os = "linux")]
812
pub fn get_downloads_dir() -> String {
913
return match env::var("HOME") {
@@ -80,3 +84,25 @@ pub fn get_install_cli(path: &str) -> (&str, Vec<&str>) {
8084
exit(0)
8185
}
8286
}
87+
88+
pub fn module_state(id: String, state: &str) {
89+
let base_path = Path::new("/data/adb/modules").join(id);
90+
let mod_state = base_path.join(state);
91+
92+
let moduleprop = base_path.join("module.prop");
93+
94+
if base_path.exists() && moduleprop.exists() && !mod_state.exists() {
95+
let conf = Ini::load_from_file(moduleprop.to_str().unwrap()).unwrap();
96+
let prop = conf.section(None::<String>).unwrap();
97+
let mut f = File::create(mod_state).unwrap();
98+
match f.write_all(b"") {
99+
Ok(_addr) => {
100+
println!("{} will be {}d.", prop.get("name").unwrap(), state);
101+
}
102+
Err(err) => {
103+
println!("{}", err);
104+
exit(1);
105+
}
106+
}
107+
}
108+
}

src/main.rs

Lines changed: 36 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::cmd::{
99
};
1010
use crate::repo::Module;
1111

12+
use android_root::module_state;
1213
use clap::{Parser, Subcommand};
1314
use repo::Repo;
1415
use std::io::Write;
@@ -79,18 +80,18 @@ enum Commands {
7980
/// Installs selected modules
8081
ids: Vec<String>,
8182
},
82-
// Enable {
83-
// /// Enabled selected modules
84-
// ids: Vec<String>,
85-
// },
86-
// Disable {
87-
// /// Disabled selected modules
88-
// ids: Vec<String>,
89-
// },
90-
// Remove {
91-
// /// Remove selected modules
92-
// ids: Vec<String>,
93-
// },
83+
Enable {
84+
/// Enabled selected modules
85+
ids: Vec<String>,
86+
},
87+
Disable {
88+
/// Disabled selected modules
89+
ids: Vec<String>,
90+
},
91+
Remove {
92+
/// Remove selected modules
93+
ids: Vec<String>,
94+
},
9495
}
9596

9697
/// Magisk Module Repo Loader CLI
@@ -249,68 +250,31 @@ async fn main() {
249250
}
250251
exit(0);
251252
}
252-
// Commands::Enable { ids } => {
253-
// let mut some_disabled= false;
254-
// for id in ids {
255-
// let module = find_module(json.clone(), id);
256-
// let disable = &format!("/data/adb/modules/{}/disable", module.id);
257-
// if !Path::new(&disable).exists() {
258-
// if !File::create(disable).is_err() {
259-
// some_disabled = true;
260-
// println!("{} has been disabled.", module.name);
261-
// }
262-
// }
263-
// }
264-
// if !some_disabled {
265-
// println!("Nothing were disabled");
266-
// }
267-
// }
268-
// Commands::Disable { ids } => {
269-
// let mut some_disabled= false;
270-
// for id in ids {
271-
// let module = find_module(&json, id);
272-
// let disable = Path::new("/data/abd/modules").join(module.id).join("disable");
273-
// if !disable.exists() {
274-
// let mut f = File::create(disable).unwrap();
275-
// match f.write_all(b"") {
276-
// Ok(addr) => {
277-
// some_disabled = true;
278-
// println!("{} will be removed.", module.name);
279-
// },
280-
// Err(err) => {
281-
// println!("{}", err);
282-
// exit(1);
283-
// },
284-
// }
285-
// }
286-
// }
287-
// if !some_disabled {
288-
// println!("Nothing were disabled");
289-
// }
290-
// }
291-
// Commands::Remove { ids } => {
292-
// let mut some_removed= false;
293-
// for id in ids {
294-
// let module = find_module(&json, id);
253+
Commands::Enable { ids } => {
254+
for id in ids {
255+
let base_path = Path::new("/data/adb/modules").join(id);
256+
let disable = base_path.join("disable");
257+
let remove = base_path.join("remove");
295258

296-
// // let remove = Path::new("/data/adb/modules/");
259+
if disable.exists() {
260+
fs::remove_file(disable).expect("File delete failed");
261+
}
297262

298-
// // let gg = remove.join(module.id).join("remove");
299-
// // println!("{:?}", gg);
300-
// // if !remove.exists() {
301-
// // match fs::write(remove, b"Lorem ipsum") {
302-
// // Ok(addr) => {
303-
// // some_removed = true;
304-
// // println!("{} will be removed.", module.name);
305-
// // },
306-
// // Err(_) => (),
307-
// // }
308-
// // }
309-
// }
310-
// if !some_removed {
311-
// println!("Nothing were removed");
312-
// }
313-
// }
263+
if remove.exists() {
264+
fs::remove_file(remove).expect("File delete failed");
265+
}
266+
}
267+
}
268+
Commands::Disable { ids } => {
269+
for id in ids {
270+
module_state(id, "disable");
271+
}
272+
}
273+
Commands::Remove { ids } => {
274+
for id in ids {
275+
module_state(id, "remove");
276+
}
277+
}
314278
Commands::Download { ids } => {
315279
for id in ids {
316280
download(client.clone(), &modules, id).await;

0 commit comments

Comments
 (0)