saving current changes

This commit is contained in:
2025-06-28 12:41:53 +01:00
parent 0cdfab9d5d
commit 0e8d2ef45e
2 changed files with 46 additions and 8 deletions

View File

@@ -1,5 +1,6 @@
use std::fs;
use std::io::Error;
use std::net::IpAddr;
use std::process::{Command, Output};
use serde::{Deserialize, Serialize};
use serde::de::DeserializeOwned;
@@ -90,6 +91,20 @@ pub struct MapPort {
pub entire_address: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Specs {
#[serde(rename = "Hostname")]
pub hostname: String,
#[serde(rename = "Platform")]
pub platform: String,
#[serde(rename = "CPU")]
pub cpu: String,
#[serde(rename = "RAM")]
pub ram: i64,
#[serde(rename = "Disk")]
pub disk: i64,
}
// Runs p2prc with custom arguments called.
// Function implemented as an identity function
pub fn run_p2prc_command<T>(arguments: &str) -> T
@@ -103,7 +118,7 @@ where
.arg(&command_str)
.output()
.expect("Failed to execute command");
let stdout = String::from_utf8_lossy(&output.stdout);
serde_json::from_str(&stdout).expect("Failed to deserialize JSON output")
}
@@ -160,3 +175,17 @@ pub fn p2prc_write_config(config: Config) {
fs::write(config.config_path, json).expect("Panic message: ");
}
// Set default config (--dc command)
pub fn p2prc_default_config() {
let _: Option<bool> = run_p2prc_command(&*"--dc".to_string());
}
// Get hardware information of a remote server
pub fn p2prc_get_specs(ip_addr: String) -> Specs {
let command: String = format!("--specs {}", ip_addr);
let specs: Specs = run_p2prc_command(&*command);
specs
}