tiger-lib 1.13.0

Library used by the tools ck3-tiger, vic3-tiger, and imperator-tiger. This library holds the bulk of the code for them. It can be built either for ck3-tiger with the feature ck3, or for vic3-tiger with the feature vic3, or for imperator-tiger with the feature imperator, but not both at the same time.
Documentation
//! Loader for the `launcher-settings.json` file.

use std::path::Path;

use anyhow::{bail, Context, Result};

use crate::fileset::{FileEntry, FileKind};
use crate::game::Game;
use crate::parse::json::parse_json_file;

/// Looks up the game's version in the launcher settings.
pub fn get_version_from_launcher(game_dir: &Path) -> Result<String> {
    let launcher_pathname = if Game::is_hoi4() {
        game_dir.join("launcher-settings.json")
    } else {
        game_dir.join("launcher/launcher-settings.json")
    };
    let launcher_entry =
        FileEntry::new(launcher_pathname.clone(), FileKind::Vanilla, launcher_pathname.clone());
    let block = parse_json_file(&launcher_entry).with_context(|| {
        format!("Could not parse launcher file {}", launcher_pathname.display())
    })?;
    if let Some(topblock) = block.iter_blocks().next() {
        if let Some(version) = topblock.get_field_value("rawVersion") {
            return Ok(version.as_str().to_owned());
        }
    }
    bail!("Version not found in {}", launcher_pathname.display())
}