diff options
Diffstat (limited to 'src/commands/update.rs')
-rw-r--r-- | src/commands/update.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/commands/update.rs b/src/commands/update.rs new file mode 100644 index 0000000..14c37ec --- /dev/null +++ b/src/commands/update.rs | |||
@@ -0,0 +1,40 @@ | |||
1 | use std::io::{Error, ErrorKind}; | ||
2 | |||
3 | use crate::{config::Cfg, modrinth::projects, get_current_list, db::{get_mods_from_list, get_versions}}; | ||
4 | |||
5 | pub async fn update(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | ||
6 | |||
7 | let current_list = get_current_list(config.clone())?; | ||
8 | |||
9 | let mods = get_mods_from_list(config.clone(), current_list)?; | ||
10 | |||
11 | let mut projects = projects(String::from(&config.apis.modrinth), mods.clone()).await; | ||
12 | |||
13 | let mut versions = get_versions(config, mods)?; | ||
14 | |||
15 | projects.sort_by_key(|p| p.id.clone()); | ||
16 | |||
17 | versions.sort_by_key(|v| v.mod_id.clone()); | ||
18 | |||
19 | let mut update_stack: Vec<String> = vec![]; | ||
20 | |||
21 | for (index, project) in projects.iter().enumerate() { | ||
22 | |||
23 | let cmp_version = &versions[index]; | ||
24 | |||
25 | let p_id = &project.id; | ||
26 | let v_id = &cmp_version.mod_id; | ||
27 | |||
28 | if p_id != v_id { return Err(Box::new(Error::new(ErrorKind::Other, "COMPARE_SORTING_ERR"))); }; | ||
29 | println!("{}:{}", p_id, v_id); | ||
30 | |||
31 | if project.versions.join("|") != cmp_version.versions { | ||
32 | update_stack.push(String::from(&project.id)); | ||
33 | }; | ||
34 | }; | ||
35 | |||
36 | //TODO UPDATE | ||
37 | dbg!(update_stack); | ||
38 | |||
39 | Ok(()) | ||
40 | } | ||