summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2022-12-04 20:32:51 +0100
committerfxqnlr <[email protected]>2022-12-04 20:32:51 +0100
commit2ec20c50e7c02d82b248835988df040bd266b659 (patch)
treea8306a2c07438068dcd190762d3f77e68064b448 /src
parentf3f746be6c1c19c93d440bbc210dec631e2b42bb (diff)
downloadmodlist-2ec20c50e7c02d82b248835988df040bd266b659.tar
modlist-2ec20c50e7c02d82b248835988df040bd266b659.tar.gz
modlist-2ec20c50e7c02d82b248835988df040bd266b659.zip
fully added mod remove; fixed update from NONE
Diffstat (limited to 'src')
-rw-r--r--src/apis/modrinth.rs7
-rw-r--r--src/commands/modification.rs19
-rw-r--r--src/commands/update.rs9
-rw-r--r--src/db.rs1
4 files changed, 22 insertions, 14 deletions
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
137pub async fn project(api: String, name: &str) -> Project { 137pub 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
145pub async fn projects(api: String, ids: Vec<String>) -> Vec<Project> { 144pub 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
157pub async fn versions(api: String, id: String, list: List) -> Vec<Version> { 154pub 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
176pub async fn get_raw_versions(api: String, versions: Vec<String>) -> Vec<Version> { 170pub 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 @@
1use std::io::{Error, ErrorKind}; 1use std::io::{Error, ErrorKind};
2 2
3use 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}; 3use 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
5pub async fn modification(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { 5pub 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(&current_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(&current_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 @@
1use std::{io::{Error, ErrorKind}, fs::{rename, remove_file}}; 1use std::{io::{Error, ErrorKind}, fs::rename};
2 2
3use 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}; 3use 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 }
diff --git a/src/db.rs b/src/db.rs
index 542c162..9d862d6 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -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