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 | |
parent | f3f746be6c1c19c93d440bbc210dec631e2b42bb (diff) | |
download | modlist-2ec20c50e7c02d82b248835988df040bd266b659.tar modlist-2ec20c50e7c02d82b248835988df040bd266b659.tar.gz modlist-2ec20c50e7c02d82b248835988df040bd266b659.zip |
fully added mod remove; fixed update from NONE
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | data.db | bin | 24576 -> 24576 bytes | |||
-rw-r--r-- | dl2/Capes-1.4.5+1.19.mric9rDGCw.jar | bin | 0 -> 87580 bytes | |||
-rw-r--r-- | src/apis/modrinth.rs | 7 | ||||
-rw-r--r-- | src/commands/modification.rs | 19 | ||||
-rw-r--r-- | src/commands/update.rs | 9 | ||||
-rw-r--r-- | src/db.rs | 1 |
8 files changed, 24 insertions, 16 deletions
@@ -647,7 +647,7 @@ dependencies = [ | |||
647 | 647 | ||
648 | [[package]] | 648 | [[package]] |
649 | name = "modlist" | 649 | name = "modlist" |
650 | version = "0.3.1" | 650 | version = "0.4.0" |
651 | dependencies = [ | 651 | dependencies = [ |
652 | "chrono", | 652 | "chrono", |
653 | "config", | 653 | "config", |
@@ -1,6 +1,6 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "modlist" | 2 | name = "modlist" |
3 | version = "0.3.1" | 3 | version = "0.4.0" |
4 | edition = "2021" | 4 | edition = "2021" |
5 | 5 | ||
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
Binary files differ | |||
diff --git a/dl2/Capes-1.4.5+1.19.mric9rDGCw.jar b/dl2/Capes-1.4.5+1.19.mric9rDGCw.jar new file mode 100644 index 0000000..26193e6 --- /dev/null +++ b/dl2/Capes-1.4.5+1.19.mric9rDGCw.jar | |||
Binary files differ | |||
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index fb1e666..3880fa0 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs | |||
@@ -135,7 +135,6 @@ async fn get(api: String, path: String) -> Result<Option<Vec<u8>>, Box<dyn std:: | |||
135 | } | 135 | } |
136 | 136 | ||
137 | pub async fn project(api: String, name: &str) -> Project { | 137 | pub async fn project(api: String, name: &str) -> Project { |
138 | println!("!!!PROJECT"); | ||
139 | let url = format!("project/{}", name); | 138 | let url = format!("project/{}", name); |
140 | let data = get(api, url).await.unwrap().unwrap(); | 139 | let data = get(api, url).await.unwrap().unwrap(); |
141 | 140 | ||
@@ -143,11 +142,9 @@ pub async fn project(api: String, name: &str) -> Project { | |||
143 | } | 142 | } |
144 | 143 | ||
145 | pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> { | 144 | pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> { |
146 | //println!("!!!PROJECTS"); | ||
147 | println!("Getting versions for all mods from modrinth"); | 145 | println!("Getting versions for all mods from modrinth"); |
148 | let all = ids.join(r#"",""#); | 146 | let all = ids.join(r#"",""#); |
149 | let url = format!(r#"projects?ids=["{}"]"#, all); | 147 | let url = format!(r#"projects?ids=["{}"]"#, all); |
150 | //println!("{}", url); | ||
151 | 148 | ||
152 | let data = get(api, url).await.unwrap().unwrap(); | 149 | let data = get(api, url).await.unwrap().unwrap(); |
153 | 150 | ||
@@ -155,7 +152,6 @@ pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> { | |||
155 | } | 152 | } |
156 | 153 | ||
157 | pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { | 154 | pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { |
158 | println!("!!!VERSIONS"); | ||
159 | let loaderstr = match list.modloader { | 155 | let loaderstr = match list.modloader { |
160 | Modloader::Forge => String::from("forge"), | 156 | Modloader::Forge => String::from("forge"), |
161 | Modloader::Fabric => String::from("fabric"), | 157 | Modloader::Fabric => String::from("fabric"), |
@@ -165,8 +161,6 @@ pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { | |||
165 | 161 | ||
166 | let data = get(api, url).await.unwrap(); | 162 | let data = get(api, url).await.unwrap(); |
167 | 163 | ||
168 | dbg!(&data); | ||
169 | |||
170 | match data { | 164 | match data { |
171 | Some(data) => serde_json::from_slice(&data).unwrap(), | 165 | Some(data) => serde_json::from_slice(&data).unwrap(), |
172 | None => Vec::new(), | 166 | None => Vec::new(), |
@@ -174,7 +168,6 @@ pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { | |||
174 | } | 168 | } |
175 | 169 | ||
176 | pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version> { | 170 | pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version> { |
177 | println!("!!!RAWVERSIONS"); | ||
178 | println!("Getting versions {}", &versions.join(", ")); | 171 | println!("Getting versions {}", &versions.join(", ")); |
179 | 172 | ||
180 | let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#)); | 173 | let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#)); |
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 | } |
@@ -365,7 +365,6 @@ pub fn lists_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error: | |||
365 | })?; | 365 | })?; |
366 | 366 | ||
367 | for id in id_iter { | 367 | for id in id_iter { |
368 | println!("Found id {:?}", id.as_ref().unwrap()); | ||
369 | list_ids.push(id?) | 368 | list_ids.push(id?) |
370 | }; | 369 | }; |
371 | 370 | ||