feat: add get_beatmapsets_count command and utility to retrieve osu! user config

This commit is contained in:
2025-07-03 11:46:02 +02:00
parent c93ace3158
commit 892f2cea07
2 changed files with 69 additions and 4 deletions

View File

@@ -21,4 +21,34 @@ pub fn check_folder_completeness<P: AsRef<Path>>(folder_path: P, required_files:
} else {
(found as f32 / required_files.len() as f32) * 100.0
}
}
}
pub fn get_osu_user_config<P: AsRef<Path>>(
osu_folder_path: P,
) -> Option<std::collections::HashMap<String, String>> {
// Ensure the osu! folder path is valid
if !osu_folder_path.as_ref().exists() {
return None;
}
// get the osu!{username}.cfg file from the osu! folder
let current_user = std::env::var("USERNAME").unwrap_or_else(|_| "Admin".to_string());
let osu_config_path = osu_folder_path
.as_ref()
.join(format!("osu!.{}.cfg", current_user));
if !osu_config_path.exists() {
return None;
}
// read the osu config and return it as a map, key and value are separated by ' = '
let mut config_map = std::collections::HashMap::new();
if let Ok(contents) = std::fs::read_to_string(osu_config_path) {
for line in contents.lines() {
if let Some((key, value)) = line.split_once(" = ") {
config_map.insert(key.trim().to_string(), value.trim().to_string());
}
}
}
return Some(config_map);
}