29 lines
842 B
Rust
29 lines
842 B
Rust
use anyhow::Result;
|
|
use serde::{Deserialize, Serialize};
|
|
use std::path::PathBuf;
|
|
|
|
/// Gemeinsame Utility-Funktionen
|
|
pub fn get_project_dirs() -> Result<directories::ProjectDirs> {
|
|
directories::ProjectDirs::from("eu", "heimatlosen", "aegisaur")
|
|
.ok_or_else(|| anyhow::anyhow!("Konnte Projekt-Verzeichnisse nicht ermitteln"))
|
|
}
|
|
|
|
/// Formatiert Bytes als menschenlesbare Größe
|
|
pub fn format_bytes(bytes: u64) -> String {
|
|
const UNITS: [&str; 6] = ["B", "KB", "MB", "GB", "TB", "PB"];
|
|
let mut size = bytes as f64;
|
|
let mut unit_index = 0;
|
|
|
|
while size >= 1024.0 && unit_index < UNITS.len() - 1 {
|
|
size /= 1024.0;
|
|
unit_index += 1;
|
|
}
|
|
|
|
format!("{:.2} {}", size, UNITS[unit_index])
|
|
}
|
|
|
|
/// Prüft ob ein Befehl verfügbar ist
|
|
pub fn command_exists(cmd: &str) -> bool {
|
|
which::which(cmd).is_ok()
|
|
}
|