flashpoint_archive/game_data/
mod.rs

1use rusqlite::{Connection, Result, params};
2use serde::{Deserialize, Serialize};
3
4#[cfg_attr(feature = "napi", napi(object))]
5#[derive(Debug, Clone, Deserialize, Serialize)]
6pub struct GameData {
7    pub id: i64,
8    pub game_id: String,
9    pub title: String,
10    pub date_added: String,
11    pub sha256: String,
12    pub crc32: i32,
13    pub present_on_disk: bool,
14    pub path: Option<String>,
15    pub size: i64,
16    pub parameters: Option<String>,
17    pub application_path: String,
18    pub launch_command: String,
19}
20
21#[cfg_attr(feature = "napi", napi(object))]
22#[derive(Debug, Clone, Deserialize, Serialize)]
23pub struct PartialGameData {
24    pub id: Option<i64>,
25    pub game_id: String,
26    pub title: Option<String>,
27    pub date_added: Option<String>,
28    pub sha256: Option<String>,
29    pub crc32: Option<i32>,
30    pub present_on_disk: Option<bool>,
31    pub path: Option<String>,
32    pub size: Option<i64>,
33    pub parameters: Option<String>,
34    pub application_path: Option<String>,
35    pub launch_command: Option<String>,
36}
37
38impl From<GameData> for PartialGameData {
39    fn from(value: GameData) -> Self {
40        PartialGameData {
41            id: Some(value.id),
42            game_id: value.game_id,
43            title: Some(value.title),
44            date_added: Some(value.date_added),
45            sha256: Some(value.sha256),
46            crc32: Some(value.crc32),
47            present_on_disk: Some(value.present_on_disk),
48            path: value.path,
49            size: Some(value.size),
50            parameters: value.parameters,
51            application_path: Some(value.application_path),
52            launch_command: Some(value.launch_command),
53        }
54    }
55}
56
57pub fn delete(conn: &Connection, id: i64) -> Result<()> {
58    let mut stmt = conn.prepare("DELETE FROM game_data WHERE id = ?")?;
59    stmt.execute(params![id])?;
60
61    stmt = conn.prepare("UPDATE game SET activeDataId = NULL, activeDataOnDisk = false WHERE activeDataId = ?")?;
62    stmt.execute(params![id])?;
63    Ok(())
64}