move module

This commit is contained in:
sqlerrorthing
2025-11-03 05:15:40 +08:00
parent 574bbbd8cc
commit d1e56df7fc
3 changed files with 24 additions and 20 deletions

View File

@@ -0,0 +1,20 @@
use tokio::fs::File;
use tokio::fs;
use crate::MODULE_PATH;
pub async fn set_autostart(autostart: bool) -> Result<(), anyhow::Error> {
let autostart_path = MODULE_PATH.join("autostart");
if autostart {
File::create(autostart_path).await?;
} else {
fs::remove_file(autostart_path).await?;
}
Ok(())
}
pub fn get_autostart() {
let file = MODULE_PATH.join("autostart");
println!("{}", file.exists());
}

View File

@@ -1,7 +1,8 @@
use crate::service::{restart_service, service_status, start_service, stop_service}; use crate::service::{restart_service, service_status, start_service, stop_service};
use crate::{bin_version, get_autostart, module_version, set_autostart}; use crate::{bin_version, module_version};
use clap::Subcommand; use clap::Subcommand;
use log::error; use log::error;
use crate::autostart::{get_autostart, set_autostart};
#[derive(Subcommand)] #[derive(Subcommand)]
pub enum Command { pub enum Command {

View File

@@ -3,6 +3,7 @@ pub mod config;
mod daemon; mod daemon;
pub mod iptables_rust; pub mod iptables_rust;
mod service; mod service;
mod autostart;
use ini::Ini; use ini::Ini;
use libnfqws::nfqws_main; use libnfqws::nfqws_main;
@@ -11,9 +12,8 @@ use std::ffi::CString;
use std::os::raw::c_char; use std::os::raw::c_char;
use std::path::Path; use std::path::Path;
use std::sync::LazyLock; use std::sync::LazyLock;
use tokio::fs;
use tokio::fs::File; use tokio::fs::File;
use tokio::io::{AsyncWriteExt, copy}; use tokio::io::{copy, AsyncWriteExt};
pub static MODULE_PATH: LazyLock<&Path> = LazyLock::new(|| Path::new("/data/adb/modules/zaprett")); pub static MODULE_PATH: LazyLock<&Path> = LazyLock::new(|| Path::new("/data/adb/modules/zaprett"));
pub static ZAPRETT_DIR_PATH: LazyLock<&Path> = pub static ZAPRETT_DIR_PATH: LazyLock<&Path> =
@@ -28,23 +28,6 @@ pub static DEFAULT_START: &str = "
--filter-udp=443 --dpi-desync=fake --dpi-desync-repeats=6 $hostlist --filter-udp=443 --dpi-desync=fake --dpi-desync-repeats=6 $hostlist
"; ";
async fn set_autostart(autostart: bool) -> Result<(), anyhow::Error> {
let autostart_path = MODULE_PATH.join("autostart");
if autostart {
File::create(autostart_path).await?;
} else {
fs::remove_file(autostart_path).await?;
}
Ok(())
}
fn get_autostart() {
let file = MODULE_PATH.join("autostart");
println!("{}", file.exists());
}
fn module_version() { fn module_version() {
if let Ok(prop) = Ini::load_from_file(MODULE_PATH.join("module.prop")) if let Ok(prop) = Ini::load_from_file(MODULE_PATH.join("module.prop"))
&& let Some(props) = prop.section::<String>(None) && let Some(props) = prop.section::<String>(None)