diff --git a/install.bat b/install.bat new file mode 100644 index 0000000..6b37aa4 --- /dev/null +++ b/install.bat @@ -0,0 +1,22 @@ +@echo off +set PONY_DIR="C:\Program Files\Ponyfetch\" +set IMAGES_DIR=%PONY_DIR%ponies + +:compile_tool +echo Compiling Ponyfetch... +cargo build --release + +:createdirectories +echo Creating directories... +if not exist %PONY_DIR% mkdir %PONY_DIR% +if not exist %IMAGES_DIR% mkdir %IMAGES_DIR% + +:copyfiles +echo Copying files... +xcopy /s ponies\ %IMAGES_DIR% +copy target\release\ponyfetch.exe %PONY_DIR% + +:setpath +echo Setting PATH... +set PATH=%PATH%;%PONY_DIR% +echo Done! \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 4c49cc8..7821e11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,6 +43,7 @@ const ACTIONS: [Action; 13] = [ name: Some("Product"), func: Some(system::specs::get_kernel), }, + #[cfg(target_os = "linux")] Action { action_type: ActionType::Details, name: Some("Kernel"), @@ -50,8 +51,8 @@ const ACTIONS: [Action; 13] = [ }, Action { action_type: ActionType::Details, - name: Some("Uptime"), - func: Some(system::host::get_uptime), + name: Some("Arch"), + func: Some(system::specs::get_arch), }, Action { action_type: ActionType::Details, @@ -73,6 +74,12 @@ const ACTIONS: [Action; 13] = [ name: Some("CPU"), func: Some(system::specs::get_cpu), }, + #[cfg(target_os = "windows")] + Action { + action_type: ActionType::Details, + name: Some("Disk usage"), + func: Some(system::specs::get_disk_usage), + }, Action { action_type: ActionType::Details, name: Some("RAM"), @@ -105,6 +112,8 @@ const ACTIONS: [Action; 13] = [ fn main() { let args: Args = Args::parse(); + println!("{}", system::specs::get_disk_usage()); + let line_count = helpers::file::get_file_linecount( &format!("{}{}.txt", helpers::paths::get_pony_path(), &args.pony) ); diff --git a/src/system/host.rs b/src/system/host.rs index c87154a..7c1dd2b 100644 --- a/src/system/host.rs +++ b/src/system/host.rs @@ -47,46 +47,6 @@ pub fn get_user() -> String { user } -#[cfg(target_os = "windows")] -pub fn get_distro() -> String { - let mut distro = String::new(); - - let output = Command::new("reg") - .args(&["query", "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "/v", "ProductName"]) - .output() - .expect("Failed to execute process"); - - let output = String::from_utf8_lossy(&output.stdout); - - for line in output.lines() { - if line.contains("ProductName") { - distro = line.split_whitespace().last().unwrap().to_string(); - } - } - - distro -} - -#[cfg(target_os = "windows")] -pub fn get_uptime() -> String { - let mut uptime = String::new(); - - let output = Command::new("reg") - .args(&["query", "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment", "/v", "NUMBER_OF_PROCESSORS"]) - .output() - .expect("Failed to execute process"); - - let output = String::from_utf8_lossy(&output.stdout); - - for line in output.lines() { - if line.contains("NUMBER_OF_PROCESSORS") { - uptime = line.split_whitespace().last().unwrap().to_string(); - } - } - - uptime -} - #[cfg(target_os = "windows")] pub fn get_shell() -> String { let mut shell = String::new(); diff --git a/src/system/specs.rs b/src/system/specs.rs index 8efb851..6937eab 100644 --- a/src/system/specs.rs +++ b/src/system/specs.rs @@ -80,6 +80,67 @@ pub fn get_kernel() -> String { kernel } +#[cfg(target_os = "windows")] +pub fn get_disk_usage() -> String { + use std::process::Command; + + let mut disk = String::new(); + + let output = Command::new("wmic") + .args(&["logicaldisk", "get", "size,freespace,caption"]) + .output() + .expect("Failed to execute process"); + + let output = String::from_utf8_lossy(&output.stdout); + + for line in output.lines() { + if line.contains("Caption") || line.trim().len() == 0 {continue}; + + let mut split = line.split_whitespace(); + + let name = split.next().unwrap().trim().to_string(); + let free = split.next().unwrap().trim().to_string(); + let size = split.next().unwrap().trim().to_string(); + + disk.push_str(&format!( + "{} {}GB / {}GB", + name, + ( + size.parse::().unwrap() - + free.parse::().unwrap() + ) + / 1024 / 1024 / 1024, + + size.parse::().unwrap() + / 1024 / 1024 / 1024 + )); + } + + disk +} + +#[cfg(target_os = "windows")] +pub fn get_arch() -> String { + use std::process::Command; + + let mut uptime = String::new(); + + let output = Command::new("wmic") + .args(&["path", "Win32_OperatingSystem", "get", "OSArchitecture"]) + .output() + .expect("Failed to execute process"); + + let output = String::from_utf8_lossy(&output.stdout); + + for line in output.lines() { + if !line.contains("OSArchitecture") && line.trim().len() > 0 { + uptime = line.trim().to_string() + } + }; + + uptime +} + #[cfg(target_os = "linux")] pub fn get_cpu() -> String { let mut cpu: Rc = Rc::new(String::new());