chore: update version to 3.2.7 and refactor skin handling functions

This commit is contained in:
HorizonCode committed 2026-08-09 23:24:50 +02:00
1 parent 5a06700748
commit 01628e8514
10 files changed
+45 -120

No files matched your search

+12 -78
View File
@@ -186,75 +186,6 @@ pub async fn get_beatmapsets_count(folder: String) -> Option<u64> {
Some(beatmap_sets as u64)
}
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct SkinInfo {
pub name: String,
pub author: Option<String>,
pub modified: u64,
}
#[tauri::command]
pub async fn get_skins(folder: String) -> Option<Vec<SkinInfo>> {
use std::path::PathBuf;
use std::time::UNIX_EPOCH;
use tokio::fs;
let skins_folder = PathBuf::from(folder).join("Skins");
if !skins_folder.exists() {
return None;
}
let mut entries = fs::read_dir(skins_folder).await.ok()?;
let mut skins = Vec::new();
while let Some(entry) = entries.next_entry().await.ok()? {
if !entry.file_type().await.ok()?.is_dir() {
continue;
}
let dir_path = entry.path();
let skin_ini = dir_path.join("skin.ini");
if !skin_ini.exists() {
continue;
}
let name = entry.file_name().to_string_lossy().to_string();
let author = fs::read_to_string(&skin_ini)
.await
.ok()
.and_then(|content| {
content.lines().find_map(|line| {
let (key, value) = line.split_once(':')?;
key.trim()
.eq_ignore_ascii_case("Author")
.then(|| value.trim().to_string())
})
});
let modified = entry
.metadata()
.await
.ok()
.and_then(|m| m.modified().ok())
.and_then(|t| t.duration_since(UNIX_EPOCH).ok())
.map(|d| d.as_secs())
.unwrap_or(0);
skins.push(SkinInfo {
name,
author,
modified,
});
}
Some(skins)
}
#[tauri::command]
pub async fn get_skins_count(folder: String) -> Option<u64> {
let path = PathBuf::from(folder);
@@ -267,20 +198,23 @@ pub async fn get_skins_count(folder: String) -> Option<u64> {
let mut count = 0;
if let Ok(mut entries) = fs::read_dir(skins_folder).await {
while let Ok(Some(entry)) = entries.next_entry().await {
if entry.file_type().await.map_or(false, |ft| ft.is_dir()) {
let dir_path = entry.path();
if let Ok(mut files) = fs::read_dir(&dir_path).await {
while let Ok(Some(file)) = files.next_entry().await {
if file.path().extension().map_or(false, |ext| ext == "ini") {
count += 1;
break;
}
if let Ok(ft) = entry.file_type().await {
if ft.is_dir() {
let dir_path = entry.path();
let has_ini = tokio::fs::try_exists(dir_path.join("skin.ini"))
.await
.unwrap_or(false)
|| tokio::fs::try_exists(dir_path.join("Skin.ini"))
.await
.unwrap_or(false);
if has_ini {
count += 1;
}
}
}
}
}
return Some(count);
Some(count)
}
#[tauri::command]