use crate::cli::styles::{info, reset, success, warning};
use crate::config::BASE_CONFIG_FILENAME;
use human_repr::HumanCount as _;
use std::path::PathBuf;
#[allow(missing_copy_implementations, missing_debug_implementations)]
pub struct WindowsPlatform {}
impl super::AbstractPlatform for WindowsPlatform {
fn system_ssh_config() -> Option<PathBuf> {
let mut pb = WindowsPlatform::system_ssh_dir_path()?;
pb.push("ssh_config");
Some(pb)
}
fn user_ssh_config() -> Option<PathBuf> {
let Ok(pd) = std::env::var("UserProfile") else {
return None;
};
let mut pb = PathBuf::new();
pb.push(pd);
pb.push(".ssh");
pb.push("config");
Some(pb)
}
fn user_config_path_extra() -> Option<PathBuf> {
None
}
fn system_config_path() -> Option<PathBuf> {
let Ok(progdata) = std::env::var("ProgramData") else {
return None;
};
let mut p: PathBuf = PathBuf::from(progdata);
p.push("qcp");
p.push(BASE_CONFIG_FILENAME);
Some(p)
}
fn system_ssh_dir_path() -> Option<PathBuf> {
let Ok(progdata) = std::env::var("ProgramData") else {
return None;
};
let mut p: PathBuf = PathBuf::from(progdata);
p.push("ssh");
Some(p)
}
#[cfg_attr(coverage_nightly, coverage(off))]
fn help_buffers_mode(udp: u64) -> String {
help_buffers_win(udp)
}
fn override_path_is_local(path: &str) -> bool {
let b = path.as_bytes();
path.chars().filter(|c| *c == ':').count() == 1
&& b.len() > 2
&& b[0].is_ascii_alphabetic()
&& b[1] == b':'
&& (b[2] == b'/' || b[2] == b'\\')
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
fn help_buffers_win(udp: u64) -> String {
#![allow(non_snake_case)]
let RESET = reset();
let result = super::test_udp_buffers(udp, udp);
let mut output = String::from(super::TESTING_BUFFERS_MESSAGE);
match result {
Err(e) => {
format!(
r"⚠️ {WARNING}Unable to test local UdpSocket parameters:{RESET} {e}
Sorry, we can't predict performance. Proceed with caution.",
WARNING = warning()
)
}
Ok(r) => {
use std::fmt::Write as _;
let _ = write!(
output,
"\n{INFO}Test result:{RESET} {rx} (read) / {tx} (write)",
rx = r.recv.human_count_bytes(),
tx = r.send.human_count_bytes(),
INFO = info(),
);
if let Some(warning) = r.warning {
let _ = write!(output, "\n😞 {INFO}{warning}{RESET}", INFO = info());
} else {
let _ = write!(output, "\n🚀 {SUCCESS}Great!{RESET}", SUCCESS = success());
}
output
}
}
}
#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod test {
use super::WindowsPlatform as Platform;
use crate::os::AbstractPlatform;
#[cfg(unix)]
#[test]
fn config_paths_unset() {
assert!(Platform::system_ssh_config().is_none());
assert!(Platform::user_ssh_config().is_none());
assert!(Platform::system_config_path().is_none());
}
#[cfg(windows)]
#[test]
fn config_paths_win() {
assert!(Platform::system_ssh_config().is_some());
assert!(Platform::user_ssh_config().is_some());
assert!(Platform::system_config_path().is_some());
}
}