diff options
author | fxqnlr <[email protected]> | 2022-12-04 20:32:51 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-12-04 20:32:51 +0100 |
commit | 2ec20c50e7c02d82b248835988df040bd266b659 (patch) | |
tree | a8306a2c07438068dcd190762d3f77e68064b448 /src/commands | |
parent | f3f746be6c1c19c93d440bbc210dec631e2b42bb (diff) | |
download | modlist-2ec20c50e7c02d82b248835988df040bd266b659.tar modlist-2ec20c50e7c02d82b248835988df040bd266b659.tar.gz modlist-2ec20c50e7c02d82b248835988df040bd266b659.zip |
fully added mod remove; fixed update from NONE
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/modification.rs | 19 | ||||
-rw-r--r-- | src/commands/update.rs | 9 |
2 files changed, 22 insertions, 6 deletions
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index ac23970..f36c8c6 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | use crate::{modrinth::{project, versions, extract_current_version, Version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids}, input::{Input, Subcmd}, get_current_list, download_versions}; | 3 | use crate::{modrinth::{project, versions, extract_current_version, Version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, Subcmd}, get_current_list, download_versions, files::delete_version}; |
4 | 4 | ||
5 | pub async fn modification(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub async fn modification(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { |
6 | 6 | ||
@@ -87,6 +87,21 @@ fn remove(config: Cfg, args: Vec<String>) -> Result<(), Box<dyn std::error::Erro | |||
87 | let current_list = get_current_list(config.clone())?; | 87 | let current_list = get_current_list(config.clone())?; |
88 | let mod_id = mods_get_id(config.clone(), String::from(&args[0]))?; | 88 | let mod_id = mods_get_id(config.clone(), String::from(&args[0]))?; |
89 | 89 | ||
90 | let version = userlist_get_current_version(config.clone(), String::from(¤t_list.id), String::from(&mod_id))?; | ||
91 | |||
90 | //TODO implement remove from modlist if not in any other lists && config clean is true | 92 | //TODO implement remove from modlist if not in any other lists && config clean is true |
91 | userlist_remove(config, current_list.id, mod_id) | 93 | userlist_remove(config.clone(), String::from(¤t_list.id), String::from(&mod_id))?; |
94 | delete_version(current_list, version)?; | ||
95 | |||
96 | let list_ids = lists_get_all_ids(config.clone())?; | ||
97 | |||
98 | let mut mod_used = false; | ||
99 | for id in list_ids { | ||
100 | let mods = userlist_get_all_ids(config.clone(), id)?; | ||
101 | if mods.contains(&mod_id) { mod_used = true; break; }; | ||
102 | }; | ||
103 | |||
104 | if !mod_used { mods_remove(config, mod_id)?; }; | ||
105 | |||
106 | Ok(()) | ||
92 | } | 107 | } |
diff --git a/src/commands/update.rs b/src/commands/update.rs index 482e588..bf13319 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use std::{io::{Error, ErrorKind}, fs::{rename, remove_file}}; | 1 | use std::{io::{Error, ErrorKind}, fs::rename}; |
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, userlist_add_disabled_versions, mods_change_versions}, List, input::Input, files::{get_file_path, delete_version}, download_versions}; |
4 | 4 | ||
@@ -70,14 +70,15 @@ pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error: | |||
70 | } | 70 | } |
71 | 71 | ||
72 | if input.direct_download { download_versions(current_list.clone(), updatestack).await?; }; | 72 | if input.direct_download { download_versions(current_list.clone(), updatestack).await?; }; |
73 | 73 | ||
74 | //Disable old versions | 74 | //Disable old versions |
75 | for ver in current_versions { | 75 | for ver in current_versions { |
76 | if input.delete_old { | 76 | if input.delete_old { |
77 | println!("Deleting version {} for mod {}", ver.0, ver.1); | 77 | println!("Deleting version {} for mod {}", ver.0, ver.1); |
78 | delete_version(current_list.clone(), ver.0)?; | 78 | delete_version(current_list.clone(), ver.0)?; |
79 | } else { | 79 | } else if ver.0 != "NONE" { |
80 | disable_old(config.clone(), current_list.clone(), ver.0, ver.1)? | 80 | println!("Disabling version {} for mod {}", ver.0, ver.1); |
81 | disable_old(config.clone(), current_list.clone(), ver.0, ver.1)?; | ||
81 | }; | 82 | }; |
82 | } | 83 | } |
83 | } | 84 | } |