diff options
Diffstat (limited to 'src/commands/update.rs')
-rw-r--r-- | src/commands/update.rs | 41 |
1 files changed, 16 insertions, 25 deletions
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 | ||