mirror of
https://github.com/Atsukoro1/ponyfetch.git
synced 2024-11-27 06:17:59 +01:00
feat: 🎸 Part of windows installation script
This commit is contained in:
parent
1215df5a2c
commit
60479e36cb
4 changed files with 94 additions and 42 deletions
22
install.bat
Normal file
22
install.bat
Normal file
|
@ -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!
|
13
src/main.rs
13
src/main.rs
|
@ -43,6 +43,7 @@ const ACTIONS: [Action; 13] = [
|
||||||
name: Some("Product"),
|
name: Some("Product"),
|
||||||
func: Some(system::specs::get_kernel),
|
func: Some(system::specs::get_kernel),
|
||||||
},
|
},
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
Action {
|
Action {
|
||||||
action_type: ActionType::Details,
|
action_type: ActionType::Details,
|
||||||
name: Some("Kernel"),
|
name: Some("Kernel"),
|
||||||
|
@ -50,8 +51,8 @@ const ACTIONS: [Action; 13] = [
|
||||||
},
|
},
|
||||||
Action {
|
Action {
|
||||||
action_type: ActionType::Details,
|
action_type: ActionType::Details,
|
||||||
name: Some("Uptime"),
|
name: Some("Arch"),
|
||||||
func: Some(system::host::get_uptime),
|
func: Some(system::specs::get_arch),
|
||||||
},
|
},
|
||||||
Action {
|
Action {
|
||||||
action_type: ActionType::Details,
|
action_type: ActionType::Details,
|
||||||
|
@ -73,6 +74,12 @@ const ACTIONS: [Action; 13] = [
|
||||||
name: Some("CPU"),
|
name: Some("CPU"),
|
||||||
func: Some(system::specs::get_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 {
|
||||||
action_type: ActionType::Details,
|
action_type: ActionType::Details,
|
||||||
name: Some("RAM"),
|
name: Some("RAM"),
|
||||||
|
@ -105,6 +112,8 @@ const ACTIONS: [Action; 13] = [
|
||||||
fn main() {
|
fn main() {
|
||||||
let args: Args = Args::parse();
|
let args: Args = Args::parse();
|
||||||
|
|
||||||
|
println!("{}", system::specs::get_disk_usage());
|
||||||
|
|
||||||
let line_count = helpers::file::get_file_linecount(
|
let line_count = helpers::file::get_file_linecount(
|
||||||
&format!("{}{}.txt", helpers::paths::get_pony_path(), &args.pony)
|
&format!("{}{}.txt", helpers::paths::get_pony_path(), &args.pony)
|
||||||
);
|
);
|
||||||
|
|
|
@ -47,46 +47,6 @@ pub fn get_user() -> String {
|
||||||
user
|
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")]
|
#[cfg(target_os = "windows")]
|
||||||
pub fn get_shell() -> String {
|
pub fn get_shell() -> String {
|
||||||
let mut shell = String::new();
|
let mut shell = String::new();
|
||||||
|
|
|
@ -80,6 +80,67 @@ pub fn get_kernel() -> String {
|
||||||
kernel
|
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::<u64>().unwrap() -
|
||||||
|
free.parse::<u64>().unwrap()
|
||||||
|
)
|
||||||
|
/ 1024 / 1024 / 1024,
|
||||||
|
|
||||||
|
size.parse::<u64>().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")]
|
#[cfg(target_os = "linux")]
|
||||||
pub fn get_cpu() -> String {
|
pub fn get_cpu() -> String {
|
||||||
let mut cpu: Rc<String> = Rc::new(String::new());
|
let mut cpu: Rc<String> = Rc::new(String::new());
|
||||||
|
|
Loading…
Reference in a new issue