diff options
author | fxqnlr <[email protected]> | 2024-09-04 12:03:13 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-04 12:03:13 +0200 |
commit | 29635b9e3833296b2c908914104ba7165d22d3d5 (patch) | |
tree | f89e2807e664327fa26191d6f017512a87ba38e7 /src | |
parent | 6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043 (diff) | |
download | modlist-29635b9e3833296b2c908914104ba7165d22d3d5.tar modlist-29635b9e3833296b2c908914104ba7165d22d3d5.tar.gz modlist-29635b9e3833296b2c908914104ba7165d22d3d5.zip |
remove `# Panics` and fix clippy
Diffstat (limited to 'src')
-rw-r--r-- | src/apis/modrinth.rs | 49 | ||||
-rw-r--r-- | src/cache.rs | 31 | ||||
-rw-r--r-- | src/commands/download.rs | 48 | ||||
-rw-r--r-- | src/commands/io.rs | 3 | ||||
-rw-r--r-- | src/commands/modification.rs | 54 | ||||
-rw-r--r-- | src/commands/update.rs | 22 | ||||
-rw-r--r-- | src/files.rs | 18 | ||||
-rw-r--r-- | src/lib.rs | 6 |
8 files changed, 119 insertions, 112 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 75e65e6..7cdc719 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs | |||
@@ -131,7 +131,6 @@ pub enum GameVersionType { | |||
131 | } | 131 | } |
132 | 132 | ||
133 | /// # Errors | 133 | /// # Errors |
134 | /// # Panics | ||
135 | async fn get( | 134 | async fn get( |
136 | api: &str, | 135 | api: &str, |
137 | path: &str, | 136 | path: &str, |
@@ -156,54 +155,57 @@ async fn get( | |||
156 | } | 155 | } |
157 | 156 | ||
158 | /// # Errors | 157 | /// # Errors |
159 | /// # Panics | 158 | pub async fn project(api: &str, name: &str) -> MLE<Project> { |
160 | pub async fn project(api: &str, name: &str) -> Project { | ||
161 | let url = format!("project/{name}"); | 159 | let url = format!("project/{name}"); |
162 | let data = get(api, &url).await.unwrap().unwrap(); | 160 | let data = get(api, &url).await |
161 | .map_err(|_| MLErr::new(EType::Other, "geterr"))? | ||
162 | .ok_or(MLErr::new(EType::Other, "geterr2"))?; | ||
163 | 163 | ||
164 | serde_json::from_slice(&data).unwrap() | 164 | serde_json::from_slice(&data).map_err(|_| MLErr::new(EType::LibJson, "from project")) |
165 | } | 165 | } |
166 | 166 | ||
167 | /// # Errors | 167 | /// # Errors |
168 | /// # Panics | 168 | pub async fn projects(api: &str, ids: Vec<String>) -> MLE<Vec<Project>> { |
169 | pub async fn projects(api: &str, ids: Vec<String>) -> Vec<Project> { | ||
170 | let all = ids.join(r#"",""#); | 169 | let all = ids.join(r#"",""#); |
171 | let url = format!(r#"projects?ids=["{all}"]"#); | 170 | let url = format!(r#"projects?ids=["{all}"]"#); |
172 | 171 | ||
173 | let data = get(api, &url).await.unwrap().unwrap(); | 172 | let data = get(api, &url).await |
173 | .map_err(|_| MLErr::new(EType::Other, "geterr"))? | ||
174 | .ok_or(MLErr::new(EType::Other, "geterr2"))?; | ||
174 | 175 | ||
175 | serde_json::from_slice(&data).unwrap() | 176 | serde_json::from_slice(&data).map_err(|_| MLErr::new(EType::LibJson, "from projects")) |
176 | } | 177 | } |
177 | 178 | ||
178 | ///Get applicable versions from `mod_id` with list context | 179 | ///Get applicable versions from `mod_id` with list context |
179 | /// # Errors | 180 | /// # Errors |
180 | /// # Panics | 181 | pub async fn versions(api: &str, id: String, list: List) -> MLE<Vec<Version>> { |
181 | pub async fn versions(api: &str, id: String, list: List) -> Vec<Version> { | ||
182 | let url = format!( | 182 | let url = format!( |
183 | r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, | 183 | r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, |
184 | id, list.modloader, list.mc_version | 184 | id, list.modloader, list.mc_version |
185 | ); | 185 | ); |
186 | 186 | ||
187 | let data = get(api, &url).await.unwrap(); | 187 | let data = get(api, &url).await |
188 | .map_err(|_| MLErr::new(EType::Other, "geterr"))?; | ||
188 | 189 | ||
189 | match data { | 190 | Ok(match data { |
190 | Some(data) => serde_json::from_slice(&data).unwrap(), | 191 | Some(data) => serde_json::from_slice(&data).map_err(|_| MLErr::new(EType::LibJson, "from version"))?, |
191 | None => Vec::new(), | 192 | None => Vec::new(), |
192 | } | 193 | }) |
193 | } | 194 | } |
194 | 195 | ||
195 | ///Get version with the version ids | 196 | ///Get version with the version ids |
196 | /// # Errors | 197 | /// # Errors |
197 | /// # Panics | ||
198 | pub async fn get_raw_versions( | 198 | pub async fn get_raw_versions( |
199 | api: &str, | 199 | api: &str, |
200 | versions: Vec<String>, | 200 | versions: Vec<String>, |
201 | ) -> Vec<Version> { | 201 | ) -> MLE<Vec<Version>> { |
202 | let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#)); | 202 | let url = format!(r#"versions?ids=["{}"]"#, versions.join(r#"",""#)); |
203 | 203 | ||
204 | let data = get(api, &url).await.unwrap().unwrap(); | 204 | let data = get(api, &url).await |
205 | .map_err(|_| MLErr::new(EType::Other, "geterr"))? | ||
206 | .ok_or(MLErr::new(EType::Other, "geterr2"))?; | ||
205 | 207 | ||
206 | serde_json::from_slice(&data).unwrap() | 208 | serde_json::from_slice(&data).map_err(|_| MLErr::new(EType::LibJson, "from raw version")) |
207 | } | 209 | } |
208 | 210 | ||
209 | /// # Errors | 211 | /// # Errors |
@@ -224,12 +226,11 @@ pub fn extract_current_version(versions: Vec<Version>) -> MLE<String> { | |||
224 | } | 226 | } |
225 | 227 | ||
226 | /// # Errors | 228 | /// # Errors |
227 | /// # Panics | 229 | pub async fn get_game_versions() -> MLE<Vec<GameVersion>> { |
228 | pub async fn get_game_versions() -> Vec<GameVersion> { | ||
229 | let data = get("https://api.modrinth.com/v2/", "tag/game_version") | 230 | let data = get("https://api.modrinth.com/v2/", "tag/game_version") |
230 | .await | 231 | .await |
231 | .unwrap() | 232 | .map_err(|_| MLErr::new(EType::Other, "geterr"))? |
232 | .unwrap(); | 233 | .ok_or(MLErr::new(EType::Other, "geterr2"))?; |
233 | 234 | ||
234 | serde_json::from_slice(&data).unwrap() | 235 | serde_json::from_slice(&data).map_err(|_| MLErr::new(EType::LibJson, "from game version")) |
235 | } | 236 | } |
diff --git a/src/cache.rs b/src/cache.rs index ef096f7..6ffeb52 100644 --- a/src/cache.rs +++ b/src/cache.rs | |||
@@ -3,17 +3,15 @@ use std::{ | |||
3 | fs::{copy, read_dir}, | 3 | fs::{copy, read_dir}, |
4 | }; | 4 | }; |
5 | 5 | ||
6 | /// . | 6 | use crate::error::{EType, MLErr, MLE}; |
7 | /// | 7 | |
8 | /// # Panics | 8 | /// # Errors |
9 | /// | 9 | pub fn get_cached_versions(path: &str) -> MLE<HashMap<String, String>> { |
10 | /// Panics if . | ||
11 | #[must_use] pub fn get_cached_versions(path: &str) -> HashMap<String, String> { | ||
12 | let mut versions: HashMap<String, String> = HashMap::new(); | 10 | let mut versions: HashMap<String, String> = HashMap::new(); |
13 | for file in read_dir(path).unwrap() { | 11 | for file in read_dir(path).map_err(|_| MLErr::new(EType::IoError, "readdir"))? { |
14 | let path = file.unwrap().path(); | 12 | let path = file.map_err(|_| MLErr::new(EType::IoError, "file"))?.path(); |
15 | if path.is_file() && path.extension().ok_or("BAH").unwrap() == "jar" { | 13 | if path.is_file() && path.extension().ok_or(MLErr::new(EType::IoError, "ext"))? == "jar" { |
16 | let pathstr = path.to_str().ok_or("BAH").unwrap(); | 14 | let pathstr = path.to_str().ok_or(MLErr::new(EType::IoError, "path"))?; |
17 | let namesplit: Vec<&str> = pathstr.split('.').collect(); | 15 | let namesplit: Vec<&str> = pathstr.split('.').collect(); |
18 | versions.insert( | 16 | versions.insert( |
19 | String::from(namesplit[namesplit.len() - 2]), | 17 | String::from(namesplit[namesplit.len() - 2]), |
@@ -21,17 +19,14 @@ use std::{ | |||
21 | ); | 19 | ); |
22 | } | 20 | } |
23 | } | 21 | } |
24 | versions | 22 | Ok(versions) |
25 | } | 23 | } |
26 | 24 | ||
27 | /// . | 25 | /// # Errors |
28 | /// | 26 | pub fn copy_cached_version(version_path: &str, download_path: &str) -> MLE<()> { |
29 | /// # Panics | ||
30 | /// | ||
31 | /// Panics if . | ||
32 | pub fn copy_cached_version(version_path: &str, download_path: &str) { | ||
33 | let versplit: Vec<&str> = version_path.split('/').collect(); | 27 | let versplit: Vec<&str> = version_path.split('/').collect(); |
34 | let download = | 28 | let download = |
35 | format!("{}/{}", download_path, versplit[versplit.len() - 1]); | 29 | format!("{}/{}", download_path, versplit[versplit.len() - 1]); |
36 | copy(version_path, download).unwrap(); | 30 | copy(version_path, download).map_err(|err| MLErr::new(EType::IoError, &err.to_string()))?; |
31 | Ok(()) | ||
37 | } | 32 | } |
diff --git a/src/commands/download.rs b/src/commands/download.rs index 7321832..7af1066 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -15,7 +15,6 @@ use crate::{ | |||
15 | use crate::{PROGRESS_CHARS, STYLE_BAR_POS}; | 15 | use crate::{PROGRESS_CHARS, STYLE_BAR_POS}; |
16 | 16 | ||
17 | /// # Errors | 17 | /// # Errors |
18 | /// # Panics | ||
19 | pub async fn download( | 18 | pub async fn download( |
20 | config: &Cfg, | 19 | config: &Cfg, |
21 | liststack: Vec<List>, | 20 | liststack: Vec<List>, |
@@ -23,29 +22,31 @@ pub async fn download( | |||
23 | delete_old: bool, | 22 | delete_old: bool, |
24 | ) -> MLE<()> { | 23 | ) -> MLE<()> { |
25 | let mp = MultiProgress::new(); | 24 | let mp = MultiProgress::new(); |
26 | let download_p = | 25 | let download_p = mp.add(ProgressBar::new( |
27 | mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); | 26 | liststack |
27 | .len() | ||
28 | .try_into() | ||
29 | .map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?, | ||
30 | )); | ||
28 | download_p.set_style( | 31 | download_p.set_style( |
29 | ProgressStyle::with_template(STYLE_BAR_POS) | 32 | ProgressStyle::with_template(STYLE_BAR_POS) |
30 | .unwrap() | 33 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? |
31 | .progress_chars(PROGRESS_CHARS), | 34 | .progress_chars(PROGRESS_CHARS), |
32 | ); | 35 | ); |
33 | 36 | ||
34 | for current_list in liststack { | 37 | for current_list in liststack { |
35 | download_p.set_message(format!("Download in {}", current_list.id)); | 38 | download_p.set_message(format!("Download in {}", current_list.id)); |
36 | 39 | ||
37 | let downloaded_versions = | 40 | let downloaded_versions = get_downloaded_versions(¤t_list)?; |
38 | get_downloaded_versions(¤t_list)?; | ||
39 | let current_version_ids = | 41 | let current_version_ids = |
40 | match userlist_get_all_current_versions_with_mods( | 42 | match userlist_get_all_current_versions_with_mods( |
41 | config, | 43 | config, |
42 | ¤t_list.id, | 44 | ¤t_list.id, |
43 | ) { | 45 | ) { |
44 | Ok(i) => Ok(i), | 46 | Ok(i) => Ok(i), |
45 | Err(e) => Err(MLErr::new( | 47 | Err(e) => { |
46 | EType::DBError, | 48 | Err(MLErr::new(EType::DBError, e.to_string().as_str())) |
47 | e.to_string().as_str(), | 49 | } |
48 | )), | ||
49 | }?; | 50 | }?; |
50 | 51 | ||
51 | let mut to_download: Vec<String> = vec![]; | 52 | let mut to_download: Vec<String> = vec![]; |
@@ -62,8 +63,7 @@ pub async fn download( | |||
62 | to_download.push(current_version); | 63 | to_download.push(current_version); |
63 | } else { | 64 | } else { |
64 | let downloaded_version = current_download | 65 | let downloaded_version = current_download |
65 | .ok_or("SOMETHING_HAS_REALLY_GONE_WRONG") | 66 | .ok_or(MLErr::new(EType::Other, "IDK, WTF"))?; |
66 | .unwrap(); | ||
67 | if ¤t_version != downloaded_version { | 67 | if ¤t_version != downloaded_version { |
68 | to_disable.push(( | 68 | to_disable.push(( |
69 | mod_id.clone(), | 69 | mod_id.clone(), |
@@ -87,7 +87,7 @@ pub async fn download( | |||
87 | download_versions( | 87 | download_versions( |
88 | current_list.clone(), | 88 | current_list.clone(), |
89 | config.clone(), | 89 | config.clone(), |
90 | get_raw_versions(&config.apis.modrinth, to_download).await, | 90 | get_raw_versions(&config.apis.modrinth, to_download).await?, |
91 | &mp, | 91 | &mp, |
92 | &download_p, | 92 | &download_p, |
93 | ) | 93 | ) |
@@ -95,13 +95,18 @@ pub async fn download( | |||
95 | } | 95 | } |
96 | 96 | ||
97 | if !to_disable.is_empty() { | 97 | if !to_disable.is_empty() { |
98 | let d_p = mp.insert_before( | 98 | let d_p = |
99 | &download_p, | 99 | mp.insert_before( |
100 | ProgressBar::new(to_disable.len().try_into().unwrap()), | 100 | &download_p, |
101 | ); | 101 | ProgressBar::new(to_disable.len().try_into().map_err( |
102 | |_| MLErr::new(EType::Other, "ListStackLen"), | ||
103 | )?), | ||
104 | ); | ||
102 | d_p.set_style( | 105 | d_p.set_style( |
103 | ProgressStyle::with_template(STYLE_BAR_POS) | 106 | ProgressStyle::with_template(STYLE_BAR_POS) |
104 | .unwrap() | 107 | .map_err(|_| { |
108 | MLErr::new(EType::LibIndicatif, "template error") | ||
109 | })? | ||
105 | .progress_chars(PROGRESS_CHARS), | 110 | .progress_chars(PROGRESS_CHARS), |
106 | ); | 111 | ); |
107 | for ver in to_disable { | 112 | for ver in to_disable { |
@@ -112,12 +117,7 @@ pub async fn download( | |||
112 | } else { | 117 | } else { |
113 | d_p.set_message(format!("Disable version {}", ver.1)); | 118 | d_p.set_message(format!("Disable version {}", ver.1)); |
114 | d_p.inc(1); | 119 | d_p.inc(1); |
115 | disable_version( | 120 | disable_version(config, ¤t_list, ver.1, ver.0)?; |
116 | config, | ||
117 | ¤t_list, | ||
118 | ver.1, | ||
119 | ver.0, | ||
120 | )?; | ||
121 | }; | 121 | }; |
122 | } | 122 | } |
123 | 123 | ||
diff --git a/src/commands/io.rs b/src/commands/io.rs index c9691c4..3e171f1 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs | |||
@@ -68,7 +68,6 @@ impl ExportList { | |||
68 | } | 68 | } |
69 | 69 | ||
70 | /// # Errors | 70 | /// # Errors |
71 | /// # Panics | ||
72 | pub fn export(config: &Cfg, list: Option<String>) -> MLE<()> { | 71 | pub fn export(config: &Cfg, list: Option<String>) -> MLE<()> { |
73 | let progress = ProgressBar::new_spinner(); | 72 | let progress = ProgressBar::new_spinner(); |
74 | progress.set_style( | 73 | progress.set_style( |
@@ -103,7 +102,7 @@ pub fn export(config: &Cfg, list: Option<String>) -> MLE<()> { | |||
103 | .join("mlexport.toml") | 102 | .join("mlexport.toml") |
104 | .into_os_string() | 103 | .into_os_string() |
105 | .into_string() | 104 | .into_string() |
106 | .unwrap(); | 105 | .map_err(|_| MLErr::new(EType::IoError, "No String"))?; |
107 | 106 | ||
108 | progress.set_message("Create file"); | 107 | progress.set_message("Create file"); |
109 | let mut file = File::create(&filestr)?; | 108 | let mut file = File::create(&filestr)?; |
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 6e6213f..aa1174a 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -44,7 +44,6 @@ pub struct ProjectInfo { | |||
44 | } | 44 | } |
45 | 45 | ||
46 | /// # Errors | 46 | /// # Errors |
47 | /// # Panics | ||
48 | pub async fn mod_add( | 47 | pub async fn mod_add( |
49 | config: &Cfg, | 48 | config: &Cfg, |
50 | mods: Vec<AddMod>, | 49 | mods: Vec<AddMod>, |
@@ -56,11 +55,14 @@ pub async fn mod_add( | |||
56 | let mut mod_ids: Vec<(String, bool)> = Vec::new(); | 55 | let mut mod_ids: Vec<(String, bool)> = Vec::new(); |
57 | let mut ver_ids: Vec<(String, bool)> = Vec::new(); | 56 | let mut ver_ids: Vec<(String, bool)> = Vec::new(); |
58 | 57 | ||
59 | let add_p = mp.add(ProgressBar::new(mods.len().try_into().map_err(|_| MLErr::new(EType::Other, "MODSLENTRY"))?)); | 58 | let add_p = mp.add(ProgressBar::new( |
59 | mods.len() | ||
60 | .try_into() | ||
61 | .map_err(|_| MLErr::new(EType::Other, "MODSLENTRY"))?, | ||
62 | )); | ||
60 | add_p.set_style( | 63 | add_p.set_style( |
61 | ProgressStyle::with_template(STYLE_BAR_POS).map_err(|_| { | 64 | ProgressStyle::with_template(STYLE_BAR_POS) |
62 | MLErr::new(EType::LibIndicatif, "template error") | 65 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? |
63 | })? | ||
64 | .progress_chars(PROGRESS_CHARS), | 66 | .progress_chars(PROGRESS_CHARS), |
65 | ); | 67 | ); |
66 | add_p.set_message("Sort ids"); | 68 | add_p.set_message("Sort ids"); |
@@ -98,11 +100,16 @@ pub async fn mod_add( | |||
98 | //Adding each mod to the lists and downloadstack | 100 | //Adding each mod to the lists and downloadstack |
99 | let project_p = mp.insert_before( | 101 | let project_p = mp.insert_before( |
100 | &add_p, | 102 | &add_p, |
101 | ProgressBar::new(projectinfo.len().try_into().unwrap()), | 103 | ProgressBar::new( |
104 | projectinfo | ||
105 | .len() | ||
106 | .try_into() | ||
107 | .map_err(|_| MLErr::new(EType::Other, "infolen"))?, | ||
108 | ), | ||
102 | ); | 109 | ); |
103 | project_p.set_style( | 110 | project_p.set_style( |
104 | ProgressStyle::with_template(STYLE_BAR_POS) | 111 | ProgressStyle::with_template(STYLE_BAR_POS) |
105 | .unwrap() | 112 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? |
106 | .progress_chars(PROGRESS_CHARS), | 113 | .progress_chars(PROGRESS_CHARS), |
107 | ); | 114 | ); |
108 | 115 | ||
@@ -112,7 +119,11 @@ pub async fn mod_add( | |||
112 | let current_version_id = if project.current_version.is_none() { | 119 | let current_version_id = if project.current_version.is_none() { |
113 | String::from("NONE") | 120 | String::from("NONE") |
114 | } else { | 121 | } else { |
115 | project.current_version.clone().unwrap().id | 122 | project |
123 | .current_version | ||
124 | .clone() | ||
125 | .ok_or(MLErr::new(EType::Other, "cur_ver"))? | ||
126 | .id | ||
116 | }; | 127 | }; |
117 | 128 | ||
118 | match userlist_insert( | 129 | match userlist_insert( |
@@ -158,7 +169,11 @@ pub async fn mod_add( | |||
158 | }?; | 169 | }?; |
159 | 170 | ||
160 | if project.current_version.is_some() { | 171 | if project.current_version.is_some() { |
161 | downloadstack.push(project.current_version.unwrap()); | 172 | downloadstack.push( |
173 | project | ||
174 | .current_version | ||
175 | .ok_or(MLErr::new(EType::Other, "cur_ver"))?, | ||
176 | ); | ||
162 | }; | 177 | }; |
163 | 178 | ||
164 | project_p.inc(1); | 179 | project_p.inc(1); |
@@ -202,8 +217,8 @@ async fn get_mod_infos( | |||
202 | 217 | ||
203 | //Get required information from mod_ids | 218 | //Get required information from mod_ids |
204 | let m_projects = match ids.len() { | 219 | let m_projects = match ids.len() { |
205 | 1 => vec![project(&config.apis.modrinth, &ids[0]).await], | 220 | 1 => vec![project(&config.apis.modrinth, &ids[0]).await?], |
206 | 2.. => projects(&config.apis.modrinth, ids).await, | 221 | 2.. => projects(&config.apis.modrinth, ids).await?, |
207 | _ => panic!("PANIC"), | 222 | _ => panic!("PANIC"), |
208 | }; | 223 | }; |
209 | for project in m_projects { | 224 | for project in m_projects { |
@@ -212,7 +227,7 @@ async fn get_mod_infos( | |||
212 | String::from(&project.id), | 227 | String::from(&project.id), |
213 | list.clone(), | 228 | list.clone(), |
214 | ) | 229 | ) |
215 | .await; | 230 | .await?; |
216 | 231 | ||
217 | let mut available_versions_vec: Vec<String> = Vec::new(); | 232 | let mut available_versions_vec: Vec<String> = Vec::new(); |
218 | let current_version: Option<Version>; | 233 | let current_version: Option<Version>; |
@@ -228,7 +243,9 @@ async fn get_mod_infos( | |||
228 | current_version, | 243 | current_version, |
229 | applicable_versions: available_versions_vec, | 244 | applicable_versions: available_versions_vec, |
230 | download_link: file, | 245 | download_link: file, |
231 | set_version: *setmap.get(&project.id).unwrap(), | 246 | set_version: *setmap |
247 | .get(&project.id) | ||
248 | .ok_or(MLErr::new(EType::Other, "not in setmap"))?, | ||
232 | }); | 249 | }); |
233 | } else { | 250 | } else { |
234 | let current_id = | 251 | let current_id = |
@@ -285,12 +302,12 @@ async fn get_ver_info( | |||
285 | let mut projectinfo: Vec<ProjectInfo> = Vec::new(); | 302 | let mut projectinfo: Vec<ProjectInfo> = Vec::new(); |
286 | 303 | ||
287 | //Get required information from ver_ids | 304 | //Get required information from ver_ids |
288 | let mut v_versions = get_raw_versions(&config.apis.modrinth, ids).await; | 305 | let mut v_versions = get_raw_versions(&config.apis.modrinth, ids).await?; |
289 | let mut v_mod_ids: Vec<String> = Vec::new(); | 306 | let mut v_mod_ids: Vec<String> = Vec::new(); |
290 | for ver in v_versions.clone() { | 307 | for ver in v_versions.clone() { |
291 | v_mod_ids.push(ver.project_id); | 308 | v_mod_ids.push(ver.project_id); |
292 | } | 309 | } |
293 | let mut v_projects = projects(&config.apis.modrinth, v_mod_ids).await; | 310 | let mut v_projects = projects(&config.apis.modrinth, v_mod_ids).await?; |
294 | v_versions.sort_by(|a, b| a.project_id.cmp(&b.project_id)); | 311 | v_versions.sort_by(|a, b| a.project_id.cmp(&b.project_id)); |
295 | v_projects.sort_by(|a, b| a.id.cmp(&b.id)); | 312 | v_projects.sort_by(|a, b| a.id.cmp(&b.id)); |
296 | 313 | ||
@@ -328,9 +345,10 @@ async fn get_ver_info( | |||
328 | /// # Errors | 345 | /// # Errors |
329 | pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { | 346 | pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { |
330 | let progress = ProgressBar::new_spinner(); | 347 | let progress = ProgressBar::new_spinner(); |
331 | progress.set_style(ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { | 348 | progress.set_style( |
332 | MLErr::new(EType::LibIndicatif, "template error") | 349 | ProgressStyle::with_template(STYLE_OPERATION) |
333 | })?); | 350 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?, |
351 | ); | ||
334 | 352 | ||
335 | let mod_id = mods_get_id(&config.data, id)?; | 353 | let mod_id = mods_get_id(&config.data, id)?; |
336 | 354 | ||
diff --git a/src/commands/update.rs b/src/commands/update.rs index d0b930d..c7965e3 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -18,7 +18,6 @@ use crate::{ | |||
18 | }; | 18 | }; |
19 | 19 | ||
20 | /// # Errors | 20 | /// # Errors |
21 | /// # Panics | ||
22 | pub async fn update( | 21 | pub async fn update( |
23 | config: &Cfg, | 22 | config: &Cfg, |
24 | liststack: Vec<List>, | 23 | liststack: Vec<List>, |
@@ -44,19 +43,26 @@ pub async fn update( | |||
44 | update_p.set_message(format!("Update {}", current_list.id)); | 43 | update_p.set_message(format!("Update {}", current_list.id)); |
45 | 44 | ||
46 | let list_p = mp.insert_before(&update_p, ProgressBar::new(2)); | 45 | let list_p = mp.insert_before(&update_p, ProgressBar::new(2)); |
47 | list_p | 46 | list_p.set_style( |
48 | .set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); | 47 | ProgressStyle::with_template(STYLE_OPERATION).map_err(|_| { |
48 | MLErr::new(EType::LibIndicatif, "template error") | ||
49 | })?, | ||
50 | ); | ||
49 | list_p.set_message("Update mods"); | 51 | list_p.set_message("Update mods"); |
50 | 52 | ||
51 | let mods = userlist_get_all_ids(config, ¤t_list.id)?; | 53 | let mods = userlist_get_all_ids(config, ¤t_list.id)?; |
52 | 54 | ||
53 | let list_u_p = mp.insert_before( | 55 | let list_u_p = mp.insert_before( |
54 | &list_p, | 56 | &list_p, |
55 | ProgressBar::new(mods.len().try_into().unwrap()), | 57 | ProgressBar::new( |
58 | mods.len() | ||
59 | .try_into() | ||
60 | .map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?, | ||
61 | ), | ||
56 | ); | 62 | ); |
57 | list_u_p.set_style( | 63 | list_u_p.set_style( |
58 | ProgressStyle::with_template(STYLE_BAR_POS) | 64 | ProgressStyle::with_template(STYLE_BAR_POS) |
59 | .unwrap() | 65 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? |
60 | .progress_chars(PROGRESS_CHARS), | 66 | .progress_chars(PROGRESS_CHARS), |
61 | ); | 67 | ); |
62 | 68 | ||
@@ -129,12 +135,12 @@ pub async fn update( | |||
129 | let d_p = mp.insert_before( | 135 | let d_p = mp.insert_before( |
130 | &list_p, | 136 | &list_p, |
131 | ProgressBar::new( | 137 | ProgressBar::new( |
132 | current_versions.len().try_into().unwrap(), | 138 | current_versions.len().try_into().map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?, |
133 | ), | 139 | ), |
134 | ); | 140 | ); |
135 | d_p.set_style( | 141 | d_p.set_style( |
136 | ProgressStyle::with_template(STYLE_BAR_POS) | 142 | ProgressStyle::with_template(STYLE_BAR_POS) |
137 | .unwrap() | 143 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? |
138 | .progress_chars(PROGRESS_CHARS), | 144 | .progress_chars(PROGRESS_CHARS), |
139 | ); | 145 | ); |
140 | for ver in current_versions { | 146 | for ver in current_versions { |
@@ -175,7 +181,7 @@ async fn specific_update( | |||
175 | progress: &ProgressBar, | 181 | progress: &ProgressBar, |
176 | ) -> MLE<Version> { | 182 | ) -> MLE<Version> { |
177 | let applicable_versions = | 183 | let applicable_versions = |
178 | versions(&config.apis.modrinth, String::from(id), list.clone()).await; | 184 | versions(&config.apis.modrinth, String::from(id), list.clone()).await?; |
179 | 185 | ||
180 | let mut versions: Vec<String> = vec![]; | 186 | let mut versions: Vec<String> = vec![]; |
181 | 187 | ||
diff --git a/src/files.rs b/src/files.rs index 59f9ed1..636c934 100644 --- a/src/files.rs +++ b/src/files.rs | |||
@@ -19,7 +19,6 @@ use crate::{ | |||
19 | }; | 19 | }; |
20 | 20 | ||
21 | /// # Errors | 21 | /// # Errors |
22 | /// # Panics | ||
23 | pub async fn download_versions( | 22 | pub async fn download_versions( |
24 | list: List, | 23 | list: List, |
25 | config: Cfg, | 24 | config: Cfg, |
@@ -27,19 +26,19 @@ pub async fn download_versions( | |||
27 | progress: &MultiProgress, | 26 | progress: &MultiProgress, |
28 | progress_before: &ProgressBar, | 27 | progress_before: &ProgressBar, |
29 | ) -> MLE<()> { | 28 | ) -> MLE<()> { |
30 | let cached = get_cached_versions(&config.cache); | 29 | let cached = get_cached_versions(&config.cache)?; |
31 | 30 | ||
32 | let mut js = JoinSet::new(); | 31 | let mut js = JoinSet::new(); |
33 | 32 | ||
34 | let style_spinner = ProgressStyle::with_template(STYLE_SPINNER).unwrap(); | 33 | let style_spinner = ProgressStyle::with_template(STYLE_SPINNER).map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?; |
35 | 34 | ||
36 | let all = progress.insert_before( | 35 | let all = progress.insert_before( |
37 | progress_before, | 36 | progress_before, |
38 | ProgressBar::new(versions.len().try_into().unwrap()), | 37 | ProgressBar::new(versions.len().try_into().map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?), |
39 | ); | 38 | ); |
40 | all.set_style( | 39 | all.set_style( |
41 | ProgressStyle::with_template(STYLE_BAR_POS) | 40 | ProgressStyle::with_template(STYLE_BAR_POS) |
42 | .unwrap() | 41 | .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? |
43 | .progress_chars(PROGRESS_CHARS), | 42 | .progress_chars(PROGRESS_CHARS), |
44 | ); | 43 | ); |
45 | all.set_message(format!("✓Downloading {}", list.id)); | 44 | all.set_message(format!("✓Downloading {}", list.id)); |
@@ -66,7 +65,6 @@ pub async fn download_versions( | |||
66 | } | 65 | } |
67 | 66 | ||
68 | /// # Errors | 67 | /// # Errors |
69 | /// # Panics | ||
70 | async fn download_version( | 68 | async fn download_version( |
71 | config: Cfg, | 69 | config: Cfg, |
72 | list: List, | 70 | list: List, |
@@ -86,7 +84,7 @@ async fn download_version( | |||
86 | if c.is_some() { | 84 | if c.is_some() { |
87 | progress.set_message(format!("Get {} from cache", version.id)); | 85 | progress.set_message(format!("Get {} from cache", version.id)); |
88 | cache_msg = " (cached)"; | 86 | cache_msg = " (cached)"; |
89 | copy_cached_version(&c.unwrap(), &dl_path); | 87 | copy_cached_version(&c.unwrap(), &dl_path)?; |
90 | } else { | 88 | } else { |
91 | let files = version.files; | 89 | let files = version.files; |
92 | let file = match files.clone().into_iter().find(|f| f.primary) { | 90 | let file = match files.clone().into_iter().find(|f| f.primary) { |
@@ -124,7 +122,6 @@ async fn download_version( | |||
124 | } | 122 | } |
125 | 123 | ||
126 | /// # Errors | 124 | /// # Errors |
127 | /// # Panics | ||
128 | async fn download_file( | 125 | async fn download_file( |
129 | url: &str, | 126 | url: &str, |
130 | path: &str, | 127 | path: &str, |
@@ -166,7 +163,6 @@ async fn download_file( | |||
166 | } | 163 | } |
167 | 164 | ||
168 | /// # Errors | 165 | /// # Errors |
169 | /// # Panics | ||
170 | pub fn disable_version( | 166 | pub fn disable_version( |
171 | config: &Cfg, | 167 | config: &Cfg, |
172 | current_list: &List, | 168 | current_list: &List, |
@@ -184,7 +180,6 @@ pub fn disable_version( | |||
184 | } | 180 | } |
185 | 181 | ||
186 | /// # Errors | 182 | /// # Errors |
187 | /// # Panics | ||
188 | pub fn delete_version(list: &List, version: &str) -> MLE<()> { | 183 | pub fn delete_version(list: &List, version: &str) -> MLE<()> { |
189 | let file = get_file_path(list, version)?; | 184 | let file = get_file_path(list, version)?; |
190 | 185 | ||
@@ -194,7 +189,6 @@ pub fn delete_version(list: &List, version: &str) -> MLE<()> { | |||
194 | } | 189 | } |
195 | 190 | ||
196 | /// # Errors | 191 | /// # Errors |
197 | /// # Panics | ||
198 | pub fn get_file_path(list: &List, versionid: &str) -> MLE<String> { | 192 | pub fn get_file_path(list: &List, versionid: &str) -> MLE<String> { |
199 | let mut names: HashMap<String, String> = HashMap::new(); | 193 | let mut names: HashMap<String, String> = HashMap::new(); |
200 | for file in read_dir(&list.download_folder)? { | 194 | for file in read_dir(&list.download_folder)? { |
@@ -220,7 +214,6 @@ pub fn get_file_path(list: &List, versionid: &str) -> MLE<String> { | |||
220 | } | 214 | } |
221 | 215 | ||
222 | /// # Errors | 216 | /// # Errors |
223 | /// # Panics | ||
224 | pub fn get_downloaded_versions(list: &List) -> MLE<HashMap<String, String>> { | 217 | pub fn get_downloaded_versions(list: &List) -> MLE<HashMap<String, String>> { |
225 | let mut versions: HashMap<String, String> = HashMap::new(); | 218 | let mut versions: HashMap<String, String> = HashMap::new(); |
226 | for file in read_dir(&list.download_folder)? { | 219 | for file in read_dir(&list.download_folder)? { |
@@ -243,7 +236,6 @@ pub fn get_downloaded_versions(list: &List) -> MLE<HashMap<String, String>> { | |||
243 | } | 236 | } |
244 | 237 | ||
245 | /// # Errors | 238 | /// # Errors |
246 | /// # Panics | ||
247 | pub fn clean_list_dir(list: &List) -> MLE<()> { | 239 | pub fn clean_list_dir(list: &List) -> MLE<()> { |
248 | let dl_path = &list.download_folder; | 240 | let dl_path = &list.download_folder; |
249 | for entry in std::fs::read_dir(dl_path)? { | 241 | for entry in std::fs::read_dir(dl_path)? { |
@@ -40,7 +40,6 @@ pub enum Modloader { | |||
40 | 40 | ||
41 | impl Modloader { | 41 | impl Modloader { |
42 | /// # Errors | 42 | /// # Errors |
43 | /// # Panics | ||
44 | pub fn from(string: &str) -> MLE<Modloader> { | 43 | pub fn from(string: &str) -> MLE<Modloader> { |
45 | match string { | 44 | match string { |
46 | "forge" => Ok(Modloader::Forge), | 45 | "forge" => Ok(Modloader::Forge), |
@@ -75,7 +74,6 @@ pub enum VersionLevel { | |||
75 | /// Checks if update needed (time) | 74 | /// Checks if update needed (time) |
76 | /// if yes: get versions, update | 75 | /// if yes: get versions, update |
77 | /// # Errors | 76 | /// # Errors |
78 | /// # Panics | ||
79 | pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { | 77 | pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { |
80 | let p = ProgressBar::new(1); | 78 | let p = ProgressBar::new(1); |
81 | p.set_style(ProgressStyle::with_template(STYLE_MESSAGE).map_err(|_| { | 79 | p.set_style(ProgressStyle::with_template(STYLE_MESSAGE).map_err(|_| { |
@@ -90,7 +88,7 @@ pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { | |||
90 | return Ok(()); | 88 | return Ok(()); |
91 | } | 89 | } |
92 | 90 | ||
93 | let versions = get_game_versions().await; | 91 | let versions = get_game_versions().await?; |
94 | remove_file(path)?; | 92 | remove_file(path)?; |
95 | let mut file = File::create(path)?; | 93 | let mut file = File::create(path)?; |
96 | file.write_all(serde_json::to_string_pretty(&versions)?.as_bytes())?; | 94 | file.write_all(serde_json::to_string_pretty(&versions)?.as_bytes())?; |
@@ -121,8 +119,6 @@ impl VersionLevel { | |||
121 | 119 | ||
122 | /// . | 120 | /// . |
123 | /// | 121 | /// |
124 | /// # Panics | ||
125 | /// | ||
126 | /// Panics if . | 122 | /// Panics if . |
127 | /// # Errors | 123 | /// # Errors |
128 | pub async fn get( | 124 | pub async fn get( |