mirror of
https://github.com/Atsukoro1/ponyfetch.git
synced 2024-11-23 12:47:59 +01:00
fix: 🐛 Resolution
This commit is contained in:
parent
591a06373a
commit
4bc54ae5a6
5 changed files with 295 additions and 5 deletions
|
@ -13,4 +13,19 @@ pub fn get_pony_path() -> String {
|
|||
.unwrap()
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_pony_path() -> String {
|
||||
if std::env::current_exe().unwrap().to_str().unwrap().contains("target") {
|
||||
PathBuf::from("ponies/")
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
} else {
|
||||
PathBuf::from("C:\\Program Files\\Ponyfetch\\ponies\\")
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
}
|
||||
}
|
20
src/main.rs
20
src/main.rs
|
@ -31,15 +31,22 @@ const ACTIONS: [Action; 13] = [
|
|||
name: None,
|
||||
func: None,
|
||||
},
|
||||
#[cfg(target_os = "linux")]
|
||||
Action {
|
||||
action_type: ActionType::Details,
|
||||
name: Some("Distro"),
|
||||
func: Some(system::host::get_distro),
|
||||
},
|
||||
#[cfg(target_os = "windows")]
|
||||
Action {
|
||||
action_type: ActionType::Details,
|
||||
name: Some("Product"),
|
||||
func: Some(system::specs::get_kernel),
|
||||
},
|
||||
Action {
|
||||
action_type: ActionType::Details,
|
||||
name: Some("Kernel"),
|
||||
func: Some(system::specs::get_kernel),
|
||||
func: Some(system::host::get_distro),
|
||||
},
|
||||
Action {
|
||||
action_type: ActionType::Details,
|
||||
|
@ -71,11 +78,18 @@ const ACTIONS: [Action; 13] = [
|
|||
name: Some("RAM"),
|
||||
func: Some(system::specs::get_ram_used),
|
||||
},
|
||||
#[cfg(target_os = "linux")]
|
||||
Action {
|
||||
action_type: ActionType::Details,
|
||||
name: Some("Init System"),
|
||||
func: Some(system::host::get_init_system),
|
||||
},
|
||||
#[cfg(target_os = "windows")]
|
||||
Action {
|
||||
action_type: ActionType::Details,
|
||||
name: Some("GPU"),
|
||||
func: Some(system::specs::get_gpu),
|
||||
},
|
||||
Action {
|
||||
action_type: ActionType::Delimiter,
|
||||
name: None,
|
||||
|
@ -91,8 +105,6 @@ const ACTIONS: [Action; 13] = [
|
|||
fn main() {
|
||||
let args: Args = Args::parse();
|
||||
|
||||
println!("{}", system::host::get_init_system());
|
||||
|
||||
let line_count = helpers::file::get_file_linecount(
|
||||
&format!("{}{}.txt", helpers::paths::get_pony_path(), &args.pony)
|
||||
);
|
||||
|
@ -149,4 +161,4 @@ fn main() {
|
|||
|
||||
println!();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,163 @@
|
|||
#[cfg(target_os = "linux")]
|
||||
use crate::helpers::file::file_open;
|
||||
#[cfg(target_os = "linux")]
|
||||
use std::{fs::File, io::Read};
|
||||
|
||||
#[cfg(any(target_os = "windows", target_os = "linux"))]
|
||||
use std::process::Command;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_hostname() -> String {
|
||||
let mut hostname = String::new();
|
||||
|
||||
let output = Command::new("reg")
|
||||
.args(&["query", "HKLM\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ComputerName", "/v", "ComputerName"])
|
||||
.output()
|
||||
.expect("Failed to execute process");
|
||||
|
||||
let output = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
for line in output.lines() {
|
||||
if line.contains("ComputerName") {
|
||||
hostname = line.split_whitespace().last().unwrap().to_string();
|
||||
}
|
||||
}
|
||||
|
||||
hostname
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_user() -> String {
|
||||
let mut user = String::new();
|
||||
|
||||
let output = Command::new("reg")
|
||||
.args(&["query", "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList", "/s"])
|
||||
.output()
|
||||
.expect("Failed to execute process");
|
||||
|
||||
let output = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
for line in output.lines() {
|
||||
if line.contains("ProfileImagePath") {
|
||||
user = line.split_whitespace().last().unwrap().to_string();
|
||||
user = user.split("\\").last().unwrap().to_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();
|
||||
|
||||
let output = Command::new("reg")
|
||||
.args(&["query", "HKCU\\Console", "/v", "FaceName"])
|
||||
.output()
|
||||
.expect("Failed to execute process");
|
||||
|
||||
let output = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
for line in output.lines() {
|
||||
if line.contains("FaceName") {
|
||||
shell = line.split_whitespace().last().unwrap().to_string();
|
||||
}
|
||||
}
|
||||
|
||||
if shell == "Lucida Console" {
|
||||
shell = "PowerShell".to_string();
|
||||
} else {
|
||||
shell = "CMD".to_string();
|
||||
}
|
||||
|
||||
shell
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_resolution() -> String {
|
||||
let mut temp_horiz = String::new();
|
||||
let mut temp_vert = String::new();
|
||||
|
||||
let output = Command::new("wmic")
|
||||
.args(&[
|
||||
"path",
|
||||
"Win32_VideoController",
|
||||
"get",
|
||||
"CurrentVerticalResolution,CurrentHorizontalResolution",
|
||||
"/format:value"
|
||||
])
|
||||
.output()
|
||||
.expect("Failed to execute process");
|
||||
|
||||
let output = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
let split_by_equals = |item: &str| -> String {
|
||||
item.split("=")
|
||||
.collect::<Vec<&str>>()
|
||||
.iter()
|
||||
.nth(1)
|
||||
.unwrap()
|
||||
.trim()
|
||||
.to_string()
|
||||
};
|
||||
|
||||
for line in output.lines() {
|
||||
if line.contains("CurrentHorizontalResolution") {
|
||||
temp_horiz = split_by_equals(line);
|
||||
}
|
||||
|
||||
if line.contains("CurrentVerticalResolution") {
|
||||
temp_vert = split_by_equals(line);
|
||||
}
|
||||
}
|
||||
|
||||
format!(
|
||||
"{}x{}",
|
||||
temp_horiz,
|
||||
temp_vert
|
||||
).to_string()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn get_hostname() -> String {
|
||||
let mut hostname = file_open("/etc/hostname");
|
||||
|
|
|
@ -3,6 +3,26 @@ use std::process::Command;
|
|||
use std::sync::Mutex;
|
||||
use std::ops::Add;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_ipaddr() -> String {
|
||||
let mut ipaddr = String::new();
|
||||
|
||||
let output = Command::new("ipconfig")
|
||||
.args(&["/all"])
|
||||
.output()
|
||||
.expect("Failed to execute process");
|
||||
|
||||
let output = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
for line in output.lines() {
|
||||
if line.contains("IPv4 Address") {
|
||||
ipaddr = line.split_whitespace().last().unwrap().to_string();
|
||||
}
|
||||
}
|
||||
|
||||
ipaddr
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn get_ipaddr() -> String {
|
||||
let final_str: Mutex<String> = Mutex::new(String::new());
|
||||
|
|
|
@ -3,6 +3,72 @@ use std::fs::File;
|
|||
use std::io::Read;
|
||||
use std::rc::Rc;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_cpu() -> String {
|
||||
use std::process::Command;
|
||||
|
||||
let mut cpu = String::new();
|
||||
|
||||
let output = Command::new("wmic")
|
||||
.args(&["cpu", "get", "name"])
|
||||
.output()
|
||||
.expect("Failed to execute process");
|
||||
|
||||
let output = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
for line in output.lines() {
|
||||
if !line.contains("Name") && line.trim().len() > 0 {
|
||||
cpu = line.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
cpu
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_ram_used() -> String {
|
||||
use std::process::Command;
|
||||
|
||||
let mut ram_used = String::new();
|
||||
|
||||
let output = Command::new("wmic")
|
||||
.args(&["OS", "get", "FreePhysicalMemory"])
|
||||
.output()
|
||||
.expect("Failed to execute process");
|
||||
|
||||
let output = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
for line in output.lines() {
|
||||
if !line.contains("FreePhysicalMemory") && line.trim().len() > 0 {
|
||||
ram_used = line.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
ram_used
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_kernel() -> String {
|
||||
use std::process::Command;
|
||||
|
||||
let mut kernel = String::new();
|
||||
|
||||
let output = Command::new("wmic")
|
||||
.args(&["OS", "get", "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 {
|
||||
kernel = line.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
kernel
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn get_cpu() -> String {
|
||||
let mut cpu: Rc<String> = Rc::new(String::new());
|
||||
|
@ -51,7 +117,6 @@ pub fn get_ram_used() -> String {
|
|||
)
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn eval_ram(line: String) -> u128 {
|
||||
let kbs: u128 = line.split(":")
|
||||
.collect::<Vec<&str>>()[1].to_string()
|
||||
|
@ -71,4 +136,26 @@ pub fn get_kernel() -> String {
|
|||
temp_buf.split(" ")
|
||||
.collect::<Vec<&str>>()[2]
|
||||
.to_string()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub fn get_gpu() -> String {
|
||||
use std::process::Command;
|
||||
|
||||
let mut gpu = String::new();
|
||||
|
||||
let output = Command::new("wmic")
|
||||
.args(&["path", "win32_VideoController", "get", "Name"])
|
||||
.output()
|
||||
.expect("Failed to execute process");
|
||||
|
||||
let output = String::from_utf8_lossy(&output.stdout);
|
||||
|
||||
for line in output.lines() {
|
||||
if !line.contains("Name") && line.trim().len() > 0 {
|
||||
gpu = line.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
gpu
|
||||
}
|
Loading…
Reference in a new issue