summaryrefslogtreecommitdiff
path: root/src/cli/updates.rs
blob: 3e0bc5d9842b4426b5f7712ac8e5debcf680fd44 (plain) (blame)
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
35
36
37
38
39
use thirtyfour::{DesiredCapabilities, WebDriver};
use tracing::{info, error};
use std::{path::Path, process::exit};

use toml::Value;
use crate::{errors::CliError, util::{PackConfig, read_pack_lock, self}};

pub async fn check_updates(cfg: PackConfig) -> Result<(), CliError> {
    info!("Checking for pack updates for {} ({})", cfg.pack.name,cfg.pack.game_version); 
    let mut old_urls: Vec<String> = Vec::new();
    if Path::new("./pack.lock").exists() {
        let lock = read_pack_lock()?; 

        for url in lock.mod_versions.keys() {
            old_urls.push((&lock.mod_versions.get(url).unwrap_or(&Value::String("none".to_string()))).to_string());
        }
    } else {
        error!("No pack.lock found, can't check for updates to something that doesn't exist!");
        exit(-1);
    }

    let mut num_updates: u32 = 0;

    let caps = DesiredCapabilities::firefox();
    let driver = WebDriver::new("http://localhost:9515", caps).await;

    for url in old_urls {
        info!("Checking for updates to {}", url);
    }
    Ok(())
}


pub async fn apply_updates(cfg: PackConfig) -> Result<(), CliError> {
    info!("Fetching new mod versions and updating pack.lock...");
    let mod_urls = util::find_updated_urls(cfg.mods.values(), cfg.pack.game_version).await?;

    Ok(())
}