diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/download.rs | 69 | ||||
-rw-r--r-- | src/commands/update.rs | 41 |
2 files changed, 51 insertions, 59 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs index 421f058..9f70499 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -1,50 +1,51 @@ | |||
1 | use crate::{files::get_downloaded_versions, db::{userlist_get_all_applicable_versions_with_mods, userlist_get_all_current_versions_with_mods}}; | 1 | use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version}, db::userlist_get_all_current_versions_with_mods, modrinth::get_raw_versions}; |
2 | #[allow(unused_imports)] | 2 | #[allow(unused_imports)] |
3 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; | 3 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; |
4 | 4 | ||
5 | pub async fn download(config: Cfg, _input: Input) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { |
6 | 6 | ||
7 | let current_list = get_current_list(config.clone())?; | 7 | let current_list = get_current_list(config.clone())?; |
8 | 8 | ||
9 | println!("NO IMPLEMENTATION FOR DOWNLOAD YET"); | ||
10 | |||
11 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; | 9 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; |
12 | println!("DL: {:?}", downloaded_versions); | ||
13 | |||
14 | let current_version_ids = userlist_get_all_current_versions_with_mods(config.clone(), String::from(¤t_list.id))?; | 10 | let current_version_ids = userlist_get_all_current_versions_with_mods(config.clone(), String::from(¤t_list.id))?; |
15 | println!("CU: {:?}", current_version_ids); | ||
16 | 11 | ||
17 | let applicable_version_ids = userlist_get_all_applicable_versions_with_mods(config, current_list.id)?; | 12 | let mut to_download: Vec<String> = vec![]; |
18 | println!("AP: {:?}", applicable_version_ids); | 13 | //(mod_id, version_id) |
19 | 14 | let mut to_disable: Vec<(String, String)> = vec![]; | |
20 | /* | ||
21 | let list = get_current_list(config.clone())?; | ||
22 | 15 | ||
23 | let links = userlist_get_all_downloads(config.clone(), list.clone().id)?; | 16 | for version in current_version_ids { |
17 | let mod_id = version.0; | ||
18 | let current_version = version.1; | ||
24 | 19 | ||
25 | download_links(config, input, list, links).await?; | 20 | let current_download = downloaded_versions.get(&mod_id); |
26 | */ | ||
27 | Ok(()) | ||
28 | } | ||
29 | 21 | ||
30 | #[allow(dead_code)] | 22 | if current_download.is_none() { |
31 | async fn download_links(_config: Cfg, _input: Input, _current_list: List, _links: Vec<String>) -> Result<String, Box<dyn std::error::Error>> { | 23 | to_download.push(current_version); |
32 | println!("NO DL IMPLEMENTATION FOR DOWNLOAD YET"); | 24 | } else { |
33 | //TODO copy dl from update if possible | 25 | let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG")?; |
34 | /* | 26 | if ¤t_version != downloaded_version { |
35 | let dl_path = String::from(¤t_list.download_folder); | 27 | to_disable.push((mod_id.clone(), String::from(downloaded_version))); |
36 | 28 | to_download.push(current_version); | |
37 | if input.clean { | 29 | } |
38 | let dl_path = ¤t_list.download_folder; | 30 | } |
39 | println!("Cleaning {}", dl_path); | 31 | } |
40 | for entry in std::fs::read_dir(dl_path)? { | 32 | |
41 | let entry = entry?; | 33 | if !to_download.is_empty() { |
42 | std::fs::remove_file(entry.path())?; | 34 | download_versions(current_list.clone(), get_raw_versions(String::from(&config.apis.modrinth), to_download).await).await?; |
35 | } else { | ||
36 | println!("There are no new versions to download"); | ||
37 | } | ||
38 | |||
39 | if !to_disable.is_empty() { | ||
40 | for ver in to_disable { | ||
41 | if input.delete_old { | ||
42 | println!("Deleting version {} for mod {}", ver.1, ver.0); | ||
43 | delete_version(current_list.clone(), ver.1)?; | ||
44 | } else { | ||
45 | disable_version(config.clone(), current_list.clone(), ver.1, ver.0)?; | ||
46 | }; | ||
43 | } | 47 | } |
44 | } | 48 | } |
45 | */ | ||
46 | 49 | ||
47 | Ok(String::new()) | 50 | Ok(()) |
48 | } | 51 | } |
49 | |||
50 | |||
diff --git a/src/commands/update.rs b/src/commands/update.rs index eeb5a4d..498b6a9 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::{io::{Error, ErrorKind}, fs::rename}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get, userlist_get_current_version, userlist_add_disabled_versions, mods_change_versions}, List, input::Input, files::{get_file_path, delete_version, download_versions}}; | 3 | use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get, userlist_get_current_version, mods_change_versions}, List, input::Input, files::{delete_version, download_versions, disable_version}}; |
4 | 4 | ||
5 | pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { |
6 | 6 | ||
@@ -69,18 +69,21 @@ pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error: | |||
69 | } | 69 | } |
70 | } | 70 | } |
71 | 71 | ||
72 | if input.direct_download { download_versions(current_list.clone(), updatestack).await?; }; | 72 | if input.direct_download { |
73 | download_versions(current_list.clone(), updatestack).await?; | ||
74 | |||
75 | //Disable old versions | ||
76 | for ver in current_versions { | ||
77 | if input.delete_old { | ||
78 | println!("Deleting version {} for mod {}", ver.0, ver.1); | ||
79 | delete_version(current_list.clone(), ver.0)?; | ||
80 | } else if ver.0 != "NONE" { | ||
81 | println!("Disabling version {} for mod {}", ver.0, ver.1); | ||
82 | disable_version(config.clone(), current_list.clone(), ver.0, ver.1)?; | ||
83 | }; | ||
84 | } | ||
85 | }; | ||
73 | 86 | ||
74 | //Disable old versions | ||
75 | for ver in current_versions { | ||
76 | if input.delete_old { | ||
77 | println!("Deleting version {} for mod {}", ver.0, ver.1); | ||
78 | delete_version(current_list.clone(), ver.0)?; | ||
79 | } else if ver.0 != "NONE" { | ||
80 | println!("Disabling version {} for mod {}", ver.0, ver.1); | ||
81 | disable_old(config.clone(), current_list.clone(), ver.0, ver.1)?; | ||
82 | }; | ||
83 | } | ||
84 | } | 87 | } |
85 | 88 | ||
86 | Ok(()) | 89 | Ok(()) |
@@ -120,18 +123,6 @@ async fn specific_update(config: Cfg, input: Input, list: List, project: Project | |||
120 | Ok(current[0].clone()) | 123 | Ok(current[0].clone()) |
121 | } | 124 | } |
122 | 125 | ||
123 | fn disable_old(config: Cfg, current_list: List, versionid: String, mod_id: String) -> Result<(), Box<dyn std::error::Error>> { | ||
124 | println!("Disabling version {} for mod {}", versionid, mod_id); | ||
125 | let file = get_file_path(current_list.clone(), String::from(&versionid))?; | ||
126 | let disabled = format!("{}.disabled", file); | ||
127 | |||
128 | rename(file, disabled)?; | ||
129 | |||
130 | userlist_add_disabled_versions(config, current_list.id, versionid, mod_id)?; | ||
131 | |||
132 | Ok(()) | ||
133 | } | ||
134 | |||
135 | #[tokio::test] | 126 | #[tokio::test] |
136 | async fn download_updates_test() { | 127 | async fn download_updates_test() { |
137 | 128 | ||