From 7d5336b92877dd40abf874683559850204ae3e57 Mon Sep 17 00:00:00 2001 From: William Edwards Date: Fri, 13 Jun 2025 12:59:22 -0700 Subject: [PATCH] fix(dmi_override): use XDG to discover platform config directory --- src/performance/gpu/platform/hardware.rs | 31 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/performance/gpu/platform/hardware.rs b/src/performance/gpu/platform/hardware.rs index 72d2201..19421cf 100644 --- a/src/performance/gpu/platform/hardware.rs +++ b/src/performance/gpu/platform/hardware.rs @@ -2,7 +2,7 @@ use crate::performance::gpu::platform::model_config::{Config, ModelConfig}; use std::collections::HashMap; use std::fs; use std::io::ErrorKind; -use std::path::Path; +use std::path::{Path, PathBuf}; #[derive(Default, Clone)] pub struct Hardware { @@ -28,9 +28,9 @@ impl Hardware { } } - // Internal method to load and apply configurations + /// Internal method to load and apply configurations fn load_and_apply_configs() -> Result> { - let platform_dir = Path::new(Self::PLATFORM_DIR); + let platform_dir = Self::get_platform_dir(); // Read each database file let amd_db_path = platform_dir.join(Self::AMD_APU_DATABASE); @@ -180,7 +180,7 @@ impl Hardware { // Helper method to check if a model exists in our configuration fn check_model_exists(model: &str) -> Result> { - let platform_dir = Path::new(Self::PLATFORM_DIR); + let platform_dir = Self::get_platform_dir(); // Read each database file let amd_db_path = platform_dir.join(Self::AMD_APU_DATABASE); @@ -205,6 +205,29 @@ impl Hardware { Ok(false) } + /// Returns the platform directory with platform configs (e.g. + /// "/usr/share/powerstation/platform") + fn get_platform_dir() -> PathBuf { + let Ok(base_dirs) = xdg::BaseDirectories::with_prefix("powerstation") else { + log::warn!("Unable to determine config base path. Using fallback path."); + return PathBuf::from(Self::PLATFORM_DIR); + }; + let data_dirs = base_dirs.get_data_dirs(); + for dir in data_dirs { + if !dir.exists() { + continue; + } + let platform_dir = dir.join("platform"); + if !platform_dir.exists() { + continue; + } + + return platform_dir; + } + + PathBuf::from(Self::PLATFORM_DIR) + } + pub fn min_tdp(&self) -> f64 { self.min_tdp }