diff --git a/src/config.rs b/src/config.rs index 3ae7c29..8bfedb9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -70,34 +70,34 @@ mod ffi { #[serde(default)] pub struct Config { /// 做不做每日任务 - is_daily_missions: bool, + is_daily_missions: u8, /// 做不做群岛 - is_archipelago: bool, + is_archipelago: u8, /// 做不做深渊 - is_spiral_abyss: bool, + is_spiral_abyss: u8, /// 做不做妖气 - is_demonic_energy: bool, + is_demonic_energy: u8, /// 森林 - is_forest: bool, + is_forest: u8, /// 分解 - is_decompose: bool, + is_decompose: u8, /// 倍攻 - is_attack_power: bool, + is_attack_power: u8, /// 装备变换 - is_equip_transform: bool, + is_equip_transform: u8, } impl Default for Config { fn default() -> Self { Self { - is_daily_missions: true, - is_archipelago: true, - is_spiral_abyss: true, - is_demonic_energy: true, - is_forest: false, - is_decompose: true, - is_attack_power: false, - is_equip_transform: true, + is_daily_missions: 1, + is_archipelago: 1, + is_spiral_abyss: 1, + is_demonic_energy: 1, + is_forest: 0, + is_decompose: 1, + is_attack_power: 0, + is_equip_transform: 1, } } } @@ -201,65 +201,65 @@ pub(crate) fn save_config( } pub(crate) fn is_daily_missions(this: &Box) -> bool { - this.is_daily_missions + this.is_daily_missions != 0 } pub(crate) fn set_daily_missions(this: &mut Box, flag: bool) { - this.is_daily_missions = flag; + this.is_daily_missions = flag as u8; } pub(crate) fn is_archipelago(this: &Box) -> bool { - this.is_archipelago + this.is_archipelago != 0 } pub(crate) fn set_archipelago(this: &mut Box, flag: bool) { - this.is_archipelago = flag; + this.is_archipelago = flag as u8; } pub(crate) fn is_spiral_abyss(this: &Box) -> bool { - this.is_spiral_abyss + this.is_spiral_abyss != 0 } pub(crate) fn set_spiral_abyss(this: &mut Box, flag: bool) { - this.is_spiral_abyss = flag; + this.is_spiral_abyss = flag as u8; } pub(crate) fn is_demonic_energy(this: &Box) -> bool { - this.is_demonic_energy + this.is_demonic_energy != 0 } pub(crate) fn set_demonic_energy(this: &mut Box, flag: bool) { - this.is_demonic_energy = flag; + this.is_demonic_energy = flag as u8; } pub(crate) fn is_forest(this: &Box) -> bool { - this.is_forest + this.is_forest != 0 } pub(crate) fn set_forest(this: &mut Box, flag: bool) { - this.is_forest = flag; + this.is_forest = flag as u8; } pub(crate) fn is_decompose(this: &Box) -> bool { - this.is_decompose + this.is_decompose != 0 } pub(crate) fn set_decompose(this: &mut Box, flag: bool) { - this.is_decompose = flag; + this.is_decompose = flag as u8; } fn is_attack_power(cfg: &Box) -> bool { - cfg.is_attack_power + cfg.is_attack_power != 0 } fn set_attack_power(cfg: &mut Box, value: bool) { - cfg.is_attack_power = value; + cfg.is_attack_power = value as u8; } fn is_equip_transform(cfg: &Box) -> bool { - cfg.is_equip_transform + cfg.is_equip_transform != 0 } fn set_equip_transform(cfg: &mut Box, value: bool) { - cfg.is_equip_transform = value; + cfg.is_equip_transform = value as u8; } pub(crate) fn set_config_value( diff --git a/src/lib.rs b/src/lib.rs index 924b91f..a1f3f4b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -142,6 +142,8 @@ fn init_log(is_debug: bool, ws_uel: &CxxString) { } } Err(_) => { + // 先丢弃管道内数据 + while let Ok(_) = rx.try_recv() {} tokio::time::sleep(std::time::Duration::from_secs(2)).await; } } diff --git a/src/login.rs b/src/login.rs index 6472f8c..0cebe08 100644 --- a/src/login.rs +++ b/src/login.rs @@ -48,7 +48,9 @@ mod ffi { fn get_server(cfg: &Box, index: usize) -> String; - fn is_process_running() -> bool; + fn is_process_running(process_name: &CxxString) -> bool; + + fn get_process_pid(process_name: &CxxString) -> Vec; } } @@ -106,11 +108,23 @@ pub(crate) fn login_game(p0: &Box, p1: usize) -> bool { status.success() } -fn is_process_running() -> bool { +fn is_process_running(process_name: &CxxString) -> bool { + let process_name = cxx_string_to_string(process_name); let mut sys = System::new(); sys.refresh_processes(ProcessesToUpdate::All, true); sys.processes() .values() - .any(|p| p.name().eq_ignore_ascii_case("dnf.exe")) + .any(|p| p.name().eq_ignore_ascii_case(&process_name)) +} + +fn get_process_pid(process_name: &CxxString) -> Vec { + let process_name = cxx_string_to_string(process_name); + let mut sys = System::new(); + sys.refresh_processes(ProcessesToUpdate::All, true); + sys.processes() + .values() + .filter(|p| p.name().eq_ignore_ascii_case(&process_name)) + .map(|p| p.pid().as_u32()) + .collect() }