aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/platform_specific/windows.rs
blob: 5d0548086254397fd35224c220289621bf09fe75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/// Windows specific code
use anyhow::{anyhow, Result};

use crate::{check_is_valid_game_path, constants::TITANFALL2_ORIGIN_IDS};

/// Runs a powershell command and parses output to get Titanfall2 install location on Origin
pub fn origin_install_location_detection() -> Result<String, anyhow::Error> {
    // Iterate over known Titanfall2 Origin IDs
    for origin_id in TITANFALL2_ORIGIN_IDS {
        match game_scanner::origin::find(origin_id) {
            // Origin ID found as installed game
            Ok(game) => {
                if game.path.is_some() {
                    let game_path = game.path.unwrap();
                    let game_path_str = game_path.to_str().unwrap();
                    match check_is_valid_game_path(game_path_str) {
                        Ok(()) => {
                            return Ok(game_path_str.to_string());
                        }
                        Err(err) => {
                            println!("{}", err);
                            continue; // Not a valid game path
                        }
                    }
                }
            }
            Err(err) => {
                println!("Couldn't find {origin_id}: {err}")
            }
        }
    }

    Err(anyhow!("No Origin install path found"))
}