elemental_driver/inspect/
installed.rs1use elemental_core::storage::{Storage, layout::Layout};
2
3use crate::{
4 driver::{Driver, InstalledDriver},
5 error::Result,
6 families::version_json::{
7 VersionJsonGameStorageExt, VersionJsonInstanceLayout, VersionJsonRootLayout,
8 },
9};
10
11use super::InstanceProbe;
12
13#[derive(Debug, Clone)]
14pub struct InstalledInstance<L: Layout, VL: Layout> {
15 pub storage: Storage<VL, Storage<L>>,
16 pub driver: InstalledDriver,
17}
18
19impl<L: Layout + Clone, VL: VersionJsonInstanceLayout + Clone> InstalledInstance<L, VL> {
20 pub async fn detect(
21 storage: Storage<VL, Storage<L>>,
22 drivers: &[&dyn Driver<L, VL>],
23 ) -> Result<Option<Self>> {
24 let probe = InstanceProbe::collect(&storage)?;
25 for driver in drivers {
26 if let Some(installed) = driver.inspect(&probe).await? {
27 return Ok(Some(Self {
28 storage,
29 driver: installed,
30 }));
31 }
32 }
33
34 Ok(None)
35 }
36}
37
38impl<L, VL> InstalledInstance<L, VL>
39where
40 L: VersionJsonRootLayout + Clone,
41 VL: VersionJsonInstanceLayout + Clone,
42{
43 pub async fn detect_all(
44 storage: &Storage<L>,
45 version_layout: VL,
46 drivers: &[&dyn Driver<L, VL>],
47 ) -> Result<Vec<Self>> {
48 let mut instances = Vec::new();
49
50 for instance in storage.instances(version_layout)? {
51 if let Some(installed) = Self::detect(instance, drivers).await? {
52 instances.push(installed);
53 }
54 }
55
56 Ok(instances)
57 }
58}