Skip to content

Commit

Permalink
Port compat tool (#50)
Browse files Browse the repository at this point in the history
* add method to query configured compatibility tool

* Update things to better match new structure

---------

Co-authored-by: Jan200101 <[email protected]>
  • Loading branch information
CosmicHorrorDev and Jan200101 authored Nov 30, 2023
1 parent 64cd466 commit 4cfc60b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use serde::Deserialize;
use std::collections::HashMap;

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub(crate) struct Store {
pub(crate) software: Software,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub(crate) struct Software {
pub(crate) valve: Valve,
}

#[derive(Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub(crate) struct Valve {
pub(crate) steam: Steam,
}

#[derive(Deserialize, Debug)]
pub(crate) struct Steam {
#[serde(rename = "CompatToolMapping")]
pub(crate) mapping: HashMap<u32, CompatTool>,
}

/// An instance of a compatibility tool.
#[derive(Deserialize, Debug, Clone)]
pub struct CompatTool {
/// The name of the tool.
///
/// Example: `proton_411`
pub name: Option<String>,

// Unknown option, may be used in the future
pub config: Option<String>,

// Unknown option, may be used in the future
pub priority: Option<u64>,
}
1 change: 1 addition & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl Error {
#[derive(Copy, Clone, Debug)]
#[non_exhaustive]
pub enum ParseErrorKind {
Config,
LibraryFolders,
App,
Shortcut,
Expand Down
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
)]

pub mod app;
pub mod config;
pub mod error;
pub mod library;
#[cfg(feature = "locate")]
Expand All @@ -129,9 +130,14 @@ pub mod shortcut;
#[cfg(any(test, doctest))]
pub mod tests;

use std::collections::HashMap;
use std::fs;
use std::path::{Path, PathBuf};

use crate::error::{ParseError, ParseErrorKind};

pub use crate::app::App;
pub use crate::config::CompatTool;
pub use crate::error::{Error, Result};
pub use crate::library::Library;
pub use crate::shortcut::Shortcut;
Expand Down Expand Up @@ -204,6 +210,21 @@ impl InstallDir {
}
}

pub fn compat_tool_mapping(&self) -> Result<HashMap<u32, CompatTool>> {
let config_path = self.path.join("config").join("config.vdf");
let vdf_text =
fs::read_to_string(&config_path).map_err(|io| Error::io(io, &config_path))?;
let store: config::Store = keyvalues_serde::from_str(&vdf_text).map_err(|de| {
Error::parse(
ParseErrorKind::Config,
ParseError::from_serde(de),
&config_path,
)
})?;

Ok(store.software.valve.steam.mapping)
}

/// Returns a listing of all added non-Steam games
pub fn shortcuts(&mut self) -> Result<shortcut::Iter> {
shortcut::Iter::new(&self.path)
Expand Down

0 comments on commit 4cfc60b

Please sign in to comment.