This commit is contained in:
2025-11-13 23:42:12 +01:00
parent e19eda7919
commit a1dfc5cc89
2 changed files with 66 additions and 24 deletions
+35
View File
@@ -58,6 +58,7 @@ pub struct Game {
#[serde(default)]
pub downloaded: bool,
/// only relevant for client (yeah... I know)
#[serde(default)]
pub installed: bool,
/// ETI game version from version.ini (YYYYMMDD format) (server)
pub eti_game_version: Option<String>,
@@ -214,3 +215,37 @@ impl fmt::Debug for GameFileDescription {
)
}
}
#[cfg(test)]
mod tests {
use serde_json::json;
use super::Game;
#[test]
fn installed_defaults_to_false_when_missing() {
let raw = json!({
"id": "aoe2",
"name": "Age of Empires II",
"description": "desc",
"release_year": "1999",
"publisher": "Microsoft",
"max_players": 8,
"version": "1.0",
"genre": "RTS",
"size": 123456,
"thumbnail": null,
"downloaded": true,
"eti_game_version": "20240101",
"local_version": null,
"peer_count": 2
})
.to_string();
let game: Game = serde_json::from_str(&raw).expect("game should deserialize");
assert!(
!game.installed,
"missing installed flag should default to false"
);
}
}
+31 -24
View File
@@ -1117,31 +1117,38 @@ async fn load_local_game_db(game_dir: &str) -> eyre::Result<GameDB> {
continue;
}
if !local_dir_has_content(&path).await {
continue;
}
let installed = local_dir_has_content(&path).await;
let local_version = if installed {
match lanspread_db::db::read_version_from_ini(&path) {
Ok(version) => version,
Err(e) => {
log::warn!("Failed to read version.ini for installed game {game_id}: {e}");
None
}
}
} else {
None
};
if let Ok(version) = lanspread_db::db::read_version_from_ini(&path) {
let size = calculate_directory_size(&path).await?;
let game = Game {
id: game_id.to_string(),
name: game_id.to_string(),
description: String::new(),
release_year: String::new(),
publisher: String::new(),
max_players: 1,
version: "1.0".to_string(),
genre: String::new(),
size,
thumbnail: None,
downloaded,
installed: true,
eti_game_version: version.clone(),
local_version: version,
peer_count: 0, // Local games start with 0 peers
};
games.push(game);
}
let size = calculate_directory_size(&path).await?;
let game = Game {
id: game_id.to_string(),
name: game_id.to_string(),
description: String::new(),
release_year: String::new(),
publisher: String::new(),
max_players: 1,
version: "1.0".to_string(),
genre: String::new(),
size,
thumbnail: None,
downloaded,
installed,
eti_game_version: local_version.clone(),
local_version,
peer_count: 0, // Local games start with 0 peers
};
games.push(game);
}
}