From 5f6cdcf1efe6b0bed2e806abfb0619e199f2b6f9 Mon Sep 17 00:00:00 2001 From: Starscouts Date: Thu, 18 Jul 2024 11:57:31 +0200 Subject: Fixes to make the client work on Windows --- .envrc | 0 .github/workflows/build_where.yml | 0 .gitignore | 0 .idea/.gitignore | 0 .idea/deployment.xml | 42 ++++++++++++++++++++++++++++ .idea/discord.xml | 0 .idea/inspectionProfiles/Project_Default.xml | 0 .idea/modules.xml | 0 .idea/vcs.xml | 0 .idea/where-rs.iml | 0 Cargo.lock | 14 +++++----- Cargo.toml | 1 + LICENSE | 0 TODO | 0 build.sh | 0 flake.lock | 0 flake.nix | 0 shell.nix | 0 where-rs/Cargo.toml | 2 +- where-rs/default_config.toml | 0 where-rs/src/args.rs | 0 where-rs/src/config.rs | 31 +++++++++++++++++++- where-rs/src/main.rs | 0 where-rs/src/servers.rs | 0 where-rs/src/ui.rs | 0 whered/Cargo.toml | 2 +- whered/services/dev.equestria.whered.plist | 0 whered/services/whered | 0 whered/services/whered.service | 0 whered/src/args.rs | 0 whered/src/main.rs | 0 whrd/Cargo.toml | 6 ++-- whrd/src/error.rs | 0 whrd/src/lib.rs | 9 ++++-- whrd/src/parse.rs | 0 35 files changed, 91 insertions(+), 16 deletions(-) mode change 100755 => 100644 .envrc mode change 100755 => 100644 .github/workflows/build_where.yml mode change 100755 => 100644 .gitignore mode change 100755 => 100644 .idea/.gitignore create mode 100644 .idea/deployment.xml mode change 100755 => 100644 .idea/discord.xml mode change 100755 => 100644 .idea/inspectionProfiles/Project_Default.xml mode change 100755 => 100644 .idea/modules.xml mode change 100755 => 100644 .idea/vcs.xml mode change 100755 => 100644 .idea/where-rs.iml mode change 100755 => 100644 Cargo.lock mode change 100755 => 100644 Cargo.toml mode change 100755 => 100644 LICENSE mode change 100755 => 100644 TODO mode change 100755 => 100644 build.sh mode change 100755 => 100644 flake.lock mode change 100755 => 100644 flake.nix mode change 100755 => 100644 shell.nix mode change 100755 => 100644 where-rs/Cargo.toml mode change 100755 => 100644 where-rs/default_config.toml mode change 100755 => 100644 where-rs/src/args.rs mode change 100755 => 100644 where-rs/src/config.rs mode change 100755 => 100644 where-rs/src/main.rs mode change 100755 => 100644 where-rs/src/servers.rs mode change 100755 => 100644 where-rs/src/ui.rs mode change 100755 => 100644 whered/Cargo.toml mode change 100755 => 100644 whered/services/dev.equestria.whered.plist mode change 100755 => 100644 whered/services/whered mode change 100755 => 100644 whered/services/whered.service mode change 100755 => 100644 whered/src/args.rs mode change 100755 => 100644 whered/src/main.rs mode change 100755 => 100644 whrd/Cargo.toml mode change 100755 => 100644 whrd/src/error.rs mode change 100755 => 100644 whrd/src/lib.rs mode change 100755 => 100644 whrd/src/parse.rs diff --git a/.envrc b/.envrc old mode 100755 new mode 100644 diff --git a/.github/workflows/build_where.yml b/.github/workflows/build_where.yml old mode 100755 new mode 100644 diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/.idea/.gitignore b/.idea/.gitignore old mode 100755 new mode 100644 diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 0000000..15c3750 --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/discord.xml b/.idea/discord.xml old mode 100755 new mode 100644 diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml old mode 100755 new mode 100644 diff --git a/.idea/modules.xml b/.idea/modules.xml old mode 100755 new mode 100644 diff --git a/.idea/vcs.xml b/.idea/vcs.xml old mode 100755 new mode 100644 diff --git a/.idea/where-rs.iml b/.idea/where-rs.iml old mode 100755 new mode 100644 diff --git a/Cargo.lock b/Cargo.lock old mode 100755 new mode 100644 index a4029e2..f3c4d44 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,9 +189,9 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "coreutils_core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9d8005352bd31280d624a3fb5f0dca74023256bab70d31c1556ea6a37e66f3a" +checksum = "fec76ea324887aa9a28bccb604b48b0ce21a981dd256921511aefba336bdbda4" dependencies = [ "bstr", "libc", @@ -542,9 +542,9 @@ dependencies = [ [[package]] name = "time" -version = "0.2.27" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4752a97f8eebd6854ff91f1c1824cd6160626ac4bd44287f7f4ea2035a02a242" +checksum = "bcdaeea317915d59b2b4cd3b5efcd156c309108664277793f5351700c02ce98b" dependencies = [ "const_fn", "libc", @@ -686,7 +686,7 @@ checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "where-rs" -version = "1.1.0" +version = "1.2.0" dependencies = [ "chrono", "clap", @@ -697,7 +697,7 @@ dependencies = [ [[package]] name = "whered" -version = "1.1.0" +version = "1.2.0" dependencies = [ "clap", "whrd", @@ -705,7 +705,7 @@ dependencies = [ [[package]] name = "whrd" -version = "1.1.0" +version = "1.2.0" dependencies = [ "coreutils_core", ] diff --git a/Cargo.toml b/Cargo.toml old mode 100755 new mode 100644 index a8b5c47..37f3431 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +default-members = ["where-rs", "whrd"] members = ["where-rs", "whered", "whrd"] resolver = "2" diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/TODO b/TODO old mode 100755 new mode 100644 diff --git a/build.sh b/build.sh old mode 100755 new mode 100644 diff --git a/flake.lock b/flake.lock old mode 100755 new mode 100644 diff --git a/flake.nix b/flake.nix old mode 100755 new mode 100644 diff --git a/shell.nix b/shell.nix old mode 100755 new mode 100644 diff --git a/where-rs/Cargo.toml b/where-rs/Cargo.toml old mode 100755 new mode 100644 index 9f4aeaf..a15883a --- a/where-rs/Cargo.toml +++ b/where-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "where-rs" -version = "1.1.0" +version = "1.2.0" edition = "2021" description = "A small Rust client for the WHRD/UDP protocol, to access a list of logged in users on multiple systems at once." authors = ["Starscouts", "ryze132"] diff --git a/where-rs/default_config.toml b/where-rs/default_config.toml old mode 100755 new mode 100644 diff --git a/where-rs/src/args.rs b/where-rs/src/args.rs old mode 100755 new mode 100644 diff --git a/where-rs/src/config.rs b/where-rs/src/config.rs old mode 100755 new mode 100644 index c45ba93..ae261d3 --- a/where-rs/src/config.rs +++ b/where-rs/src/config.rs @@ -47,7 +47,8 @@ impl Default for GlobalConfig { impl Config { fn get_config_locations() -> Vec { - vec![ + #[cfg(unix)] + return vec![ { let mut path = PathBuf::new(); @@ -70,6 +71,34 @@ impl Config { path.push(CONFIG_FILENAME); path } + ]; + + #[cfg(not(unix))] + vec![ + { + let mut path = PathBuf::new(); + + if let Ok(home) = env::var("APPDATA") { + path.push(home); + } else if let Ok(home) = env::var("USERPROFILE") { + path.push(home); + path.push("AppData"); + path.push("Roaming") + } else { + path.push("\\"); + } + + path.push(CONFIG_FILENAME); + path + }, + { + let mut path = PathBuf::new(); + + path.push("C:\\"); + path.push("ProgramData"); + path.push(CONFIG_FILENAME); + path + } ] } diff --git a/where-rs/src/main.rs b/where-rs/src/main.rs old mode 100755 new mode 100644 diff --git a/where-rs/src/servers.rs b/where-rs/src/servers.rs old mode 100755 new mode 100644 diff --git a/where-rs/src/ui.rs b/where-rs/src/ui.rs old mode 100755 new mode 100644 diff --git a/whered/Cargo.toml b/whered/Cargo.toml old mode 100755 new mode 100644 index f29949c..3dbc1ab --- a/whered/Cargo.toml +++ b/whered/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "whered" -version = "1.1.0" +version = "1.2.0" edition = "2021" description = "A small Rust server for the WHRD/UDP protocol, to access a list of logged in users on multiple systems at once." authors = ["Starscouts", "ryze132"] diff --git a/whered/services/dev.equestria.whered.plist b/whered/services/dev.equestria.whered.plist old mode 100755 new mode 100644 diff --git a/whered/services/whered b/whered/services/whered old mode 100755 new mode 100644 diff --git a/whered/services/whered.service b/whered/services/whered.service old mode 100755 new mode 100644 diff --git a/whered/src/args.rs b/whered/src/args.rs old mode 100755 new mode 100644 diff --git a/whered/src/main.rs b/whered/src/main.rs old mode 100755 new mode 100644 diff --git a/whrd/Cargo.toml b/whrd/Cargo.toml old mode 100755 new mode 100644 index d1602a8..7d797ea --- a/whrd/Cargo.toml +++ b/whrd/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "whrd" -version = "1.1.0" +version = "1.2.0" edition = "2021" description = "A Rust library to work with the WHRD/UDP protocol, a protocol to access a list of logged in users on multiple systems at once." authors = ["Starscouts", "ryze132"] @@ -9,5 +9,5 @@ authors = ["Starscouts", "ryze132"] name = "whrd" crate-type = ["dylib", "lib"] -[dependencies] -coreutils_core = "0.1.1" +[target."cfg(unix)".dependencies] +coreutils_core = "0.1.2" diff --git a/whrd/src/error.rs b/whrd/src/error.rs old mode 100755 new mode 100644 diff --git a/whrd/src/lib.rs b/whrd/src/lib.rs old mode 100755 new mode 100644 index fb45f74..50c9ef8 --- a/whrd/src/lib.rs +++ b/whrd/src/lib.rs @@ -1,5 +1,6 @@ use std::io::Cursor; -use std::path::PathBuf; + +#[cfg(unix)] use coreutils_core::os::utmpx::*; use crate::error::{WhereResult, EncodeDecodeResult, EncodeDecodeError}; @@ -34,6 +35,7 @@ pub struct SessionCollection { } impl SessionCollection { + #[cfg(unix)] pub fn fetch() -> Self { let inner: Vec = UtmpxSet::system() .into_iter() @@ -174,6 +176,7 @@ impl Session { } } +#[cfg(unix)] impl From for Session { fn from(utmpx: Utmpx) -> Self { // BStr doesn't have a known size at compile time, so we can't use it instead of String @@ -198,8 +201,8 @@ impl From for Session { // active when they are not. let mut path = PathBuf::from("/dev"); path.push(utmpx.device_name().to_string()); - let active = utmpx.entry_type() == UtmpxKind::UserProcess && path.exists(); - let login_time = utmpx.timeval().tv_sec; + let active = utmpx.entry_type() == UtmpxKind::UserProcess && utmpx.is_active(); + let login_time = utmpx.timeval().tv_sec as i64; Self { host: None, diff --git a/whrd/src/parse.rs b/whrd/src/parse.rs old mode 100755 new mode 100644 -- cgit