wows_data_mgr/lib.rs
1//! Test helper API for accessing downloaded World of Warships game data.
2//!
3//! Use these functions in integration tests to get VFS access to game builds.
4//! Tests should skip gracefully when game data is unavailable.
5//!
6//! # Example
7//!
8//! ```ignore
9//! use wows_data_mgr::{available_builds, vfs_for_build};
10//!
11//! #[test]
12//! fn test_game_params_load() {
13//! let builds = available_builds();
14//! if builds.is_empty() {
15//! eprintln!("Skipping: no game data available");
16//! return;
17//! }
18//! for build in builds {
19//! let vfs = vfs_for_build(build).unwrap();
20//! // test with vfs...
21//! }
22//! }
23//! ```
24
25pub mod builds;
26pub mod cas;
27#[cfg(feature = "constants")]
28pub mod constants;
29#[cfg(feature = "download")]
30pub mod download_repo;
31pub mod dump;
32pub mod manifest;
33pub mod registry;
34
35use std::path::PathBuf;
36
37use wowsunpack::game_data;
38use wowsunpack::vfs::VfsPath;
39
40/// Returns the path to the game_data/ directory.
41///
42/// Checks `WOWS_GAME_DATA` env var first, then walks up from the current
43/// directory to find the workspace root (identified by `game_versions.toml`).
44pub fn game_data_dir() -> Option<PathBuf> {
45 if let Ok(dir) = std::env::var("WOWS_GAME_DATA") {
46 let path = PathBuf::from(dir);
47 if path.exists() {
48 return Some(path);
49 }
50 }
51
52 // Walk up from current dir to find repo root
53 let mut dir = std::env::current_dir().ok()?;
54 loop {
55 if dir.join("game_versions.toml").exists() {
56 let data_dir = dir.join("game_data");
57 return Some(data_dir);
58 }
59 if !dir.pop() {
60 return None;
61 }
62 }
63}
64
65/// Returns sorted list of locally available build numbers.
66///
67/// Reads the local registry to find both downloaded builds
68/// (in `game_data/builds/<build>/`) and registered overrides.
69pub fn available_builds() -> Vec<u32> {
70 let Some(data_dir) = game_data_dir() else {
71 return Vec::new();
72 };
73 let reg = registry::load_registry(&data_dir.join("versions.toml"));
74 reg.available_builds()
75}
76
77/// Returns the game root path for a specific build.
78///
79/// For registered overrides, returns the override path.
80/// For downloaded builds, returns `game_data/builds/<build>/`.
81pub fn game_dir_for_build(build: u32) -> Option<PathBuf> {
82 let data_dir = game_data_dir()?;
83 let reg = registry::load_registry(&data_dir.join("versions.toml"));
84 reg.game_dir_for_build(build, &data_dir)
85}
86
87/// Constructs a VFS for a specific build.
88///
89/// Resolves path via [`game_dir_for_build`], then calls
90/// [`wowsunpack::game_data::build_game_vfs`].
91pub fn vfs_for_build(build: u32) -> Option<VfsPath> {
92 let game_dir = game_dir_for_build(build)?;
93 game_data::build_game_vfs(&game_dir).ok()
94}
95
96/// Returns the latest available build number and its VFS.
97pub fn latest_build() -> Option<(u32, VfsPath)> {
98 let builds = available_builds();
99 let build = *builds.last()?;
100 let vfs = vfs_for_build(build)?;
101 Some((build, vfs))
102}