Skip to content

Commit

Permalink
Add module state change
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Oct 23, 2023
1 parent dd66d59 commit 5445241
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 73 deletions.
28 changes: 27 additions & 1 deletion src/android_root.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use std::{
env, io,
env,
fs::File,
io::{self, Write},
path::{Path, PathBuf},
process::exit,
};

use ini::Ini;

#[cfg(target_os = "linux")]
pub fn get_downloads_dir() -> String {
return match env::var("HOME") {
Expand Down Expand Up @@ -80,3 +84,25 @@ pub fn get_install_cli(path: &str) -> (&str, Vec<&str>) {
exit(0)
}
}

pub fn module_state(id: String, state: &str) {
let base_path = Path::new("/data/adb/modules").join(id);
let mod_state = base_path.join(state);

let moduleprop = base_path.join("module.prop");

if base_path.exists() && moduleprop.exists() && !mod_state.exists() {
let conf = Ini::load_from_file(moduleprop.to_str().unwrap()).unwrap();
let prop = conf.section(None::<String>).unwrap();
let mut f = File::create(mod_state).unwrap();
match f.write_all(b"") {
Ok(_addr) => {
println!("{} will be {}d.", prop.get("name").unwrap(), state);
}
Err(err) => {
println!("{}", err);
exit(1);
}
}
}
}
108 changes: 36 additions & 72 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::cmd::{
};
use crate::repo::Module;

use android_root::module_state;
use clap::{Parser, Subcommand};
use repo::Repo;
use std::io::Write;
Expand Down Expand Up @@ -79,18 +80,18 @@ enum Commands {
/// Installs selected modules
ids: Vec<String>,
},
// Enable {
// /// Enabled selected modules
// ids: Vec<String>,
// },
// Disable {
// /// Disabled selected modules
// ids: Vec<String>,
// },
// Remove {
// /// Remove selected modules
// ids: Vec<String>,
// },
Enable {
/// Enabled selected modules
ids: Vec<String>,
},
Disable {
/// Disabled selected modules
ids: Vec<String>,
},
Remove {
/// Remove selected modules
ids: Vec<String>,
},
}

/// Magisk Module Repo Loader CLI
Expand Down Expand Up @@ -249,68 +250,31 @@ async fn main() {
}
exit(0);
}
// Commands::Enable { ids } => {
// let mut some_disabled= false;
// for id in ids {
// let module = find_module(json.clone(), id);
// let disable = &format!("/data/adb/modules/{}/disable", module.id);
// if !Path::new(&disable).exists() {
// if !File::create(disable).is_err() {
// some_disabled = true;
// println!("{} has been disabled.", module.name);
// }
// }
// }
// if !some_disabled {
// println!("Nothing were disabled");
// }
// }
// Commands::Disable { ids } => {
// let mut some_disabled= false;
// for id in ids {
// let module = find_module(&json, id);
// let disable = Path::new("/data/abd/modules").join(module.id).join("disable");
// if !disable.exists() {
// let mut f = File::create(disable).unwrap();
// match f.write_all(b"") {
// Ok(addr) => {
// some_disabled = true;
// println!("{} will be removed.", module.name);
// },
// Err(err) => {
// println!("{}", err);
// exit(1);
// },
// }
// }
// }
// if !some_disabled {
// println!("Nothing were disabled");
// }
// }
// Commands::Remove { ids } => {
// let mut some_removed= false;
// for id in ids {
// let module = find_module(&json, id);
Commands::Enable { ids } => {
for id in ids {
let base_path = Path::new("/data/adb/modules").join(id);
let disable = base_path.join("disable");
let remove = base_path.join("remove");

// // let remove = Path::new("/data/adb/modules/");
if disable.exists() {
fs::remove_file(disable).expect("File delete failed");
}

// // let gg = remove.join(module.id).join("remove");
// // println!("{:?}", gg);
// // if !remove.exists() {
// // match fs::write(remove, b"Lorem ipsum") {
// // Ok(addr) => {
// // some_removed = true;
// // println!("{} will be removed.", module.name);
// // },
// // Err(_) => (),
// // }
// // }
// }
// if !some_removed {
// println!("Nothing were removed");
// }
// }
if remove.exists() {
fs::remove_file(remove).expect("File delete failed");
}
}
}
Commands::Disable { ids } => {
for id in ids {
module_state(id, "disable");
}
}
Commands::Remove { ids } => {
for id in ids {
module_state(id, "remove");
}
}
Commands::Download { ids } => {
for id in ids {
download(client.clone(), &modules, id).await;
Expand Down

0 comments on commit 5445241

Please sign in to comment.