pub fn firewall_rules(add: bool) -> Result<(), i32> {
    let exit_status;

    if cfg!(target_os = "linux") {
        let action = if add { "add" } else { "remove" };
        // run as normal user since we use pkexec to sudo
        exit_status = Command::new("bash")
            .arg("/usr/libexec/alvr/alvr_fw_config.sh")
            .arg(action)
            .status()
            .map_err(|_| -1)?;
    } else {
        let script_path = env::temp_dir().join("alvr_firewall_rules.bat");
        let firewall_rules_script_content = if add {
            format!(
                "{}\n{}",
                netsh_add_rule_command_string(
                    "SteamVR ALVR vrserver",
                    &crate::steamvr_root_dir()
                        .map_err(|_| -1)?
                        .join("bin")
                        .join("win64")
                        .join("vrserver.exe")
                ),
                netsh_add_rule_command_string(
                    "SteamVR ALVR vrserver",
                    &crate::steamvr_root_dir()
                        .map_err(|_| -1)?
                        .join("bin")
                        .join("win32")
                        .join("vrserver.exe")
                ),
            )
        } else {
            format!(
                "{}\n{}",
                netsh_delete_rule_command_string("ALVR Launcher"),
                netsh_delete_rule_command_string("SteamVR ALVR vrserver")
            )
        };
        fs::write(&script_path, firewall_rules_script_content).map_err(|_| -1)?;

        // run with admin privileges
        exit_status = runas::Command::new(script_path)
            .gui(true) // UAC, if available
            .status()
            .map_err(|_| -1)?;
    }

    if exit_status.success() {
        Ok(())
    } else {
        Err(exit_status.code().unwrap())
    }
}
// Errors:
// 1: firewall rule is already set
// 126: pkexec request dismissed
// other: command failed
firewall rule is already set
126: pkexec request dismissed
other: command failed
firewall rule is already set 126 : pkexec request dismissed other : command failed
pub fn firewall_rules(add: bool) -> Result<(), i32> {
    let exit_status;
    if cfg!(target_os = "linux") {
        let action = if add { "add" } else { "remove" };
        // run as normal user since we use pkexec to sudo
        exit_status = Command::new("bash")
            .arg("/usr/libexec/alvr/alvr_fw_config.sh")
            .arg(action)
            .status()
            .map_err(|_| -1)?;
    } else {
        let script_path = env::temp_dir().join("alvr_firewall_rules.bat");
        let firewall_rules_script_content = if add {
            format!(
                "{}\n{}",
                netsh_add_rule_command_string(
                    "SteamVR ALVR vrserver",
                    &crate::steamvr_root_dir()
                        .map_err(|_| -1)?
                        .join("bin")
                        .join("win64")
                        .join("vrserver.exe")
                ),
                netsh_add_rule_command_string(
                    "SteamVR ALVR vrserver",
                    &crate::steamvr_root_dir()
                        .map_err(|_| -1)?
                        .join("bin")
                        .join("win32")
                        .join("vrserver.exe")
                ),
            )
        } else {
            format!(
                "{}\n{}",
                netsh_delete_rule_command_string("ALVR Launcher"),
                netsh_delete_rule_command_string("SteamVR ALVR vrserver")
            )
        };
        fs::write(&script_path, firewall_rules_script_content).map_err(|_| -1)?;
        // run with admin privileges
        exit_status = runas::Command::new(script_path)
            .gui(true) // UAC, if available
            .status()
            .map_err(|_| -1)?;
    }
    if exit_status.success() {
        Ok(())
    } else {
        Err(exit_status.code().unwrap())
    }
}
pub fn firewall_rules ( add : bool ) -> Result < ( ) , i32 > { let exit_status ; if cfg ! ( target_os " " ) { let action = if add { " " } else { " " } ; // run as normal user since we use pkexec to sudo exit_status = Command :: new ( " " ) . arg ( " " ) . arg ( action ) . status ( ) . map_err ( | _ | - 1 ) ? ; } else { let script_path = env :: temp_dir ( ) . join ( " " ) ; let firewall_rules_script_content = if add { format ! ( " \n " netsh_add_rule_command_string ( " " crate steamvr_root_dir ( ) map_err ( 1 ) join ( " " ) join ( " " ) join ( " " ) ) netsh_add_rule_command_string ( " " crate steamvr_root_dir ( ) map_err ( 1 ) join ( " " ) join ( " " ) join ( " " ) ) ) } else { format ! ( " \n " netsh_delete_rule_command_string ( " " ) netsh_delete_rule_command_string ( " " ) ) } ; fs :: write ( & script_path , firewall_rules_script_content ) . map_err ( | _ | - 1 ) ? ; // run with admin privileges exit_status = runas :: Command :: new ( script_path ) . gui ( true ) // UAC, if available . status ( ) . map_err ( | _ | - 1 ) ? ; } if exit_status . success ( ) { Ok ( ( ) ) } else { Err ( exit_status . code ( ) . unwrap ( ) ) } }
Errors:
1: firewall rule is already set
126: pkexec request dismissed
other: command failed
Errors : 1 : firewall rule is already set 126 : pkexec request dismissed other : command failed
add
bool