wip
This commit is contained in:
@@ -58,6 +58,7 @@ pub struct Game {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub downloaded: bool,
|
pub downloaded: bool,
|
||||||
/// only relevant for client (yeah... I know)
|
/// only relevant for client (yeah... I know)
|
||||||
|
#[serde(default)]
|
||||||
pub installed: bool,
|
pub installed: bool,
|
||||||
/// ETI game version from version.ini (YYYYMMDD format) (server)
|
/// ETI game version from version.ini (YYYYMMDD format) (server)
|
||||||
pub eti_game_version: Option<String>,
|
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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1117,11 +1117,19 @@ async fn load_local_game_db(game_dir: &str) -> eyre::Result<GameDB> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !local_dir_has_content(&path).await {
|
let installed = local_dir_has_content(&path).await;
|
||||||
continue;
|
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 size = calculate_directory_size(&path).await?;
|
||||||
let game = Game {
|
let game = Game {
|
||||||
id: game_id.to_string(),
|
id: game_id.to_string(),
|
||||||
@@ -1135,15 +1143,14 @@ async fn load_local_game_db(game_dir: &str) -> eyre::Result<GameDB> {
|
|||||||
size,
|
size,
|
||||||
thumbnail: None,
|
thumbnail: None,
|
||||||
downloaded,
|
downloaded,
|
||||||
installed: true,
|
installed,
|
||||||
eti_game_version: version.clone(),
|
eti_game_version: local_version.clone(),
|
||||||
local_version: version,
|
local_version,
|
||||||
peer_count: 0, // Local games start with 0 peers
|
peer_count: 0, // Local games start with 0 peers
|
||||||
};
|
};
|
||||||
games.push(game);
|
games.push(game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Ok(GameDB::from(games))
|
Ok(GameDB::from(games))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user