pacenotes_installer\install/
configure.rs1#[derive(Clone, Debug, PartialEq, Eq)]
2pub enum ConfigureError {
3 PluginMissing,
5 Io {
6 doing: String,
7 reason: String,
8 },
9}
10
11impl std::fmt::Display for ConfigureError {
12 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13 match self {
14 ConfigureError::PluginMissing => write!(
15 formatter,
16 "the Pacenote plugin is not installed in this folder, so there is \
17 nothing to configure. Install it from the RSF installer first."
18 ),
19 ConfigureError::Io { doing, reason } => write!(formatter, "{doing}: {reason}"),
20 }
21 }
22}
23
24#[derive(Clone, Debug, Default, PartialEq, Eq)]
25pub struct Configured {
26 pub files: Vec<String>,
28 pub notes: Vec<String>,
30}
31
32pub fn configure(
35 game: crate::gamedir::Game,
36 game_dir: &std::path::Path,
37 picks: &std::collections::BTreeMap<String, String>,
38) -> Result<Configured, ConfigureError> {
39 match game {
40 crate::gamedir::Game::Rbr => super::rbr::configure(game_dir, picks),
41 crate::gamedir::Game::DirtRally2
42 | crate::gamedir::Game::AssettoCorsa
43 | crate::gamedir::Game::BeamNg => Ok(Configured::default()),
44 }
45}
46
47#[cfg(test)]
48mod tests {
49 #[test]
50 fn a_game_with_no_step_leaves_its_folder_untouched() {
51 for game in [
52 crate::gamedir::Game::DirtRally2,
53 crate::gamedir::Game::AssettoCorsa,
54 crate::gamedir::Game::BeamNg,
55 ] {
56 let folder = crate::scratch_dir::ScratchDir::new("configure-other");
57 let picks = [(
58 pacenotes_shared::CATEGORY_LANGUAGE.to_string(),
59 "rbr/public/language/english".to_string(),
60 )]
61 .into();
62 let done = super::configure(game, &folder.0, &picks).expect("no step is not an error");
63 assert_eq!(done, super::Configured::default());
64 assert_eq!(
65 std::fs::read_dir(&folder.0).expect("scratch").count(),
66 0,
67 "{game:?}"
68 );
69 }
70 }
71}