diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-06-26 10:26:11 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-06-26 11:57:58 -0300 |
| commit | f505a97a034c3295c74a968ce027772f44579f1e (patch) | |
| tree | 04c86b724a2b1e93c94bf9cf76bf228e1fd47cde | |
| parent | fcb82716f1827d565ebee7b883581d82f9f257da (diff) | |
| download | mullvadvpn-f505a97a034c3295c74a968ce027772f44579f1e.tar.xz mullvadvpn-f505a97a034c3295c74a968ce027772f44579f1e.zip | |
Use `systeminfo` command to get Windows version
| -rw-r--r-- | mullvad-daemon/src/bin/problem-report.rs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/mullvad-daemon/src/bin/problem-report.rs b/mullvad-daemon/src/bin/problem-report.rs index 063dbf0838..c4db962ab5 100644 --- a/mullvad-daemon/src/bin/problem-report.rs +++ b/mullvad-daemon/src/bin/problem-report.rs @@ -28,6 +28,7 @@ use std::ffi::OsStr; use std::fs::{self, File}; use std::io::{self, BufWriter, Read, Seek, SeekFrom, Write}; use std::path::{Path, PathBuf}; +use std::process::Command; /// Maximum number of bytes to read from each log file const LOG_MAX_READ_BYTES: usize = 1 * 1024 * 1024; @@ -477,14 +478,34 @@ fn os_version() -> String { #[cfg(windows)] fn os_version() -> String { - String::from("Windows") + let system_info = + command_stdout_lossy("systeminfo", &["/FO", "LIST"]).unwrap_or_else(String::new); + + let mut os_name = None; + let mut os_version = None; + + for info_line in system_info.lines() { + let mut info_parts = info_line.split(":"); + + match info_parts.next() { + Some("OS Name") => os_name = info_parts.next(), + Some("OS Version") => os_version = info_parts.next(), + _ => {} + } + } + + match (os_name, os_version) { + (None, None) => String::from("Windows [Failed to detect version]"), + (Some(os_name), None) => os_name.trim().to_owned(), + (None, Some(os_version)) => format!("Windows version {}", os_version.trim()), + (Some(os_name), Some(os_version)) => { + format!("{} version {}", os_name.trim(), os_version.trim()) + } + } } /// Helper for getting stdout of some command as a String. Ignores the exit code of the command. -#[cfg(any(target_os = "linux", target_os = "macos"))] fn command_stdout_lossy(cmd: &str, args: &[&str]) -> Option<String> { - use std::process::Command; - Command::new(cmd) .args(args) .output() |
