diff options
author | fxqnlr <[email protected]> | 2024-09-04 09:56:42 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-04 09:56:42 +0200 |
commit | f5e070cdf6628a5ebd981d373929802317104e24 (patch) | |
tree | e31c88371737e20b2cc79bf9ee0c1dbfdeb6e727 | |
parent | 1d64516ed95266a4fc1f8a18652f99158a4004f1 (diff) | |
download | modlist-f5e070cdf6628a5ebd981d373929802317104e24.tar modlist-f5e070cdf6628a5ebd981d373929802317104e24.tar.gz modlist-f5e070cdf6628a5ebd981d373929802317104e24.zip |
clippy --fix
-rw-r--r-- | src/apis/modrinth.rs | 10 | ||||
-rw-r--r-- | src/cache.rs | 2 | ||||
-rw-r--r-- | src/commands/download.rs | 2 | ||||
-rw-r--r-- | src/commands/io.rs | 8 | ||||
-rw-r--r-- | src/commands/list.rs | 20 | ||||
-rw-r--r-- | src/commands/modification.rs | 12 | ||||
-rw-r--r-- | src/config.rs | 19 | ||||
-rw-r--r-- | src/db.rs | 62 | ||||
-rw-r--r-- | src/error.rs | 2 | ||||
-rw-r--r-- | src/files.rs | 6 | ||||
-rw-r--r-- | src/lib.rs | 4 | ||||
-rw-r--r-- | src/main.rs | 6 |
12 files changed, 72 insertions, 81 deletions
diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 9a22633..5366f3d 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs | |||
@@ -134,7 +134,7 @@ async fn get( | |||
134 | api: &str, | 134 | api: &str, |
135 | path: &str, | 135 | path: &str, |
136 | ) -> Result<Option<Vec<u8>>, Box<dyn std::error::Error>> { | 136 | ) -> Result<Option<Vec<u8>>, Box<dyn std::error::Error>> { |
137 | let url = format!(r#"{}{}"#, api, path); | 137 | let url = format!(r#"{api}{path}"#); |
138 | 138 | ||
139 | let client = Client::builder() | 139 | let client = Client::builder() |
140 | .user_agent(format!( | 140 | .user_agent(format!( |
@@ -154,7 +154,7 @@ async fn get( | |||
154 | } | 154 | } |
155 | 155 | ||
156 | pub async fn project(api: &str, name: &str) -> Project { | 156 | pub async fn project(api: &str, name: &str) -> Project { |
157 | let url = format!("project/{}", name); | 157 | let url = format!("project/{name}"); |
158 | let data = get(api, &url).await.unwrap().unwrap(); | 158 | let data = get(api, &url).await.unwrap().unwrap(); |
159 | 159 | ||
160 | serde_json::from_slice(&data).unwrap() | 160 | serde_json::from_slice(&data).unwrap() |
@@ -162,14 +162,14 @@ pub async fn project(api: &str, name: &str) -> Project { | |||
162 | 162 | ||
163 | pub async fn projects(api: &str, ids: Vec<String>) -> Vec<Project> { | 163 | pub async fn projects(api: &str, ids: Vec<String>) -> Vec<Project> { |
164 | let all = ids.join(r#"",""#); | 164 | let all = ids.join(r#"",""#); |
165 | let url = format!(r#"projects?ids=["{}"]"#, all); | 165 | let url = format!(r#"projects?ids=["{all}"]"#); |
166 | 166 | ||
167 | let data = get(api, &url).await.unwrap().unwrap(); | 167 | let data = get(api, &url).await.unwrap().unwrap(); |
168 | 168 | ||
169 | serde_json::from_slice(&data).unwrap() | 169 | serde_json::from_slice(&data).unwrap() |
170 | } | 170 | } |
171 | 171 | ||
172 | ///Get applicable versions from mod_id with list context | 172 | ///Get applicable versions from `mod_id` with list context |
173 | pub async fn versions(api: &str, id: String, list: List) -> Vec<Version> { | 173 | pub async fn versions(api: &str, id: String, list: List) -> Vec<Version> { |
174 | let url = format!( | 174 | let url = format!( |
175 | r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, | 175 | r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, |
@@ -203,7 +203,7 @@ pub fn extract_current_version(versions: Vec<Version>) -> MLE<String> { | |||
203 | let mut times: Vec<(String, DateTime<FixedOffset>)> = vec![]; | 203 | let mut times: Vec<(String, DateTime<FixedOffset>)> = vec![]; |
204 | for ver in versions { | 204 | for ver in versions { |
205 | let stamp = DateTime::parse_from_rfc3339(&ver.date_published)?; | 205 | let stamp = DateTime::parse_from_rfc3339(&ver.date_published)?; |
206 | times.push((ver.id, stamp)) | 206 | times.push((ver.id, stamp)); |
207 | } | 207 | } |
208 | times.sort_by_key(|t| t.1); | 208 | times.sort_by_key(|t| t.1); |
209 | times.reverse(); | 209 | times.reverse(); |
diff --git a/src/cache.rs b/src/cache.rs index 8df4d2f..ef096f7 100644 --- a/src/cache.rs +++ b/src/cache.rs | |||
@@ -8,7 +8,7 @@ use std::{ | |||
8 | /// # Panics | 8 | /// # Panics |
9 | /// | 9 | /// |
10 | /// Panics if . | 10 | /// Panics if . |
11 | pub fn get_cached_versions(path: &str) -> HashMap<String, String> { | 11 | #[must_use] pub fn get_cached_versions(path: &str) -> HashMap<String, String> { |
12 | let mut versions: HashMap<String, String> = HashMap::new(); | 12 | let mut versions: HashMap<String, String> = HashMap::new(); |
13 | for file in read_dir(path).unwrap() { | 13 | for file in read_dir(path).unwrap() { |
14 | let path = file.unwrap().path(); | 14 | let path = file.unwrap().path(); |
diff --git a/src/commands/download.rs b/src/commands/download.rs index a7cf744..3e50c87 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -71,7 +71,7 @@ pub async fn download( | |||
71 | } | 71 | } |
72 | 72 | ||
73 | if clean { | 73 | if clean { |
74 | clean_list_dir(¤t_list)? | 74 | clean_list_dir(¤t_list)?; |
75 | }; | 75 | }; |
76 | 76 | ||
77 | if !to_download.is_empty() { | 77 | if !to_download.is_empty() { |
diff --git a/src/commands/io.rs b/src/commands/io.rs index 8e44b2b..1d17f7c 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs | |||
@@ -48,13 +48,13 @@ impl ExportList { | |||
48 | 48 | ||
49 | let mut dl_folder = None; | 49 | let mut dl_folder = None; |
50 | if download { | 50 | if download { |
51 | dl_folder = Some(list.download_folder) | 51 | dl_folder = Some(list.download_folder); |
52 | }; | 52 | }; |
53 | 53 | ||
54 | let mods = userlist_get_all_ids(config, list_id)?; | 54 | let mods = userlist_get_all_ids(config, list_id)?; |
55 | let mut versions = vec![]; | 55 | let mut versions = vec![]; |
56 | for m in mods { | 56 | for m in mods { |
57 | versions.push(ExportVersion::from(config, list_id, &m)?) | 57 | versions.push(ExportVersion::from(config, list_id, &m)?); |
58 | } | 58 | } |
59 | 59 | ||
60 | Ok(Self { | 60 | Ok(Self { |
@@ -80,7 +80,7 @@ pub fn export(config: &Cfg, list: Option<String>) -> MLE<()> { | |||
80 | 80 | ||
81 | let mut lists: Vec<ExportList> = vec![]; | 81 | let mut lists: Vec<ExportList> = vec![]; |
82 | for list_id in list_ids { | 82 | for list_id in list_ids { |
83 | progress.set_message(format!("Export {}", list_id)); | 83 | progress.set_message(format!("Export {list_id}")); |
84 | //TODO download option/ new download on import | 84 | //TODO download option/ new download on import |
85 | lists.push(ExportList::from(config, &list_id, true)?); | 85 | lists.push(ExportList::from(config, &list_id, true)?); |
86 | } | 86 | } |
@@ -97,7 +97,7 @@ pub fn export(config: &Cfg, list: Option<String>) -> MLE<()> { | |||
97 | progress.set_message("Create file"); | 97 | progress.set_message("Create file"); |
98 | let mut file = File::create(&filestr)?; | 98 | let mut file = File::create(&filestr)?; |
99 | file.write_all(toml.as_bytes())?; | 99 | file.write_all(toml.as_bytes())?; |
100 | progress.finish_with_message(format!("Exported to {}", filestr)); | 100 | progress.finish_with_message(format!("Exported to {filestr}")); |
101 | 101 | ||
102 | Ok(()) | 102 | Ok(()) |
103 | } | 103 | } |
diff --git a/src/commands/list.rs b/src/commands/list.rs index 3665446..63105cf 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs | |||
@@ -32,32 +32,32 @@ pub fn list_add( | |||
32 | ) -> MLE<()> { | 32 | ) -> MLE<()> { |
33 | let p = ProgressBar::new_spinner(); | 33 | let p = ProgressBar::new_spinner(); |
34 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); | 34 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); |
35 | p.set_message(format!("Create {}", id)); | 35 | p.set_message(format!("Create {id}")); |
36 | lists_insert(config, id, mc_version, modloader, directory)?; | 36 | lists_insert(config, id, mc_version, modloader, directory)?; |
37 | p.finish_with_message(format!("Created {}", id)); | 37 | p.finish_with_message(format!("Created {id}")); |
38 | Ok(()) | 38 | Ok(()) |
39 | } | 39 | } |
40 | 40 | ||
41 | pub fn list_change(config: &Cfg, id: &str) -> MLE<()> { | 41 | pub fn list_change(config: &Cfg, id: &str) -> MLE<()> { |
42 | let p = ProgressBar::new_spinner(); | 42 | let p = ProgressBar::new_spinner(); |
43 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); | 43 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); |
44 | p.set_message(format!("Change default list to {}", id)); | 44 | p.set_message(format!("Change default list to {id}")); |
45 | 45 | ||
46 | if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { | 46 | if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { |
47 | return Err(MLError::new(ErrorType::ArgumentError, "List not found")); | 47 | return Err(MLError::new(ErrorType::ArgumentError, "List not found")); |
48 | }; | 48 | }; |
49 | config_change_current_list(config, id)?; | 49 | config_change_current_list(config, id)?; |
50 | 50 | ||
51 | p.finish_with_message(format!("Changed default list to {}", id)); | 51 | p.finish_with_message(format!("Changed default list to {id}")); |
52 | Ok(()) | 52 | Ok(()) |
53 | } | 53 | } |
54 | 54 | ||
55 | pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> { | 55 | pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> { |
56 | let p = ProgressBar::new_spinner(); | 56 | let p = ProgressBar::new_spinner(); |
57 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); | 57 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); |
58 | p.set_message(format!("Remove {}", id)); | 58 | p.set_message(format!("Remove {id}")); |
59 | lists_remove(config, id)?; | 59 | lists_remove(config, id)?; |
60 | p.finish_with_message(format!("Removed {}", id)); | 60 | p.finish_with_message(format!("Removed {id}")); |
61 | Ok(()) | 61 | Ok(()) |
62 | } | 62 | } |
63 | 63 | ||
@@ -77,15 +77,13 @@ pub async fn list_version( | |||
77 | let p = ProgressBar::new_spinner(); | 77 | let p = ProgressBar::new_spinner(); |
78 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); | 78 | p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); |
79 | p.set_message(format!( | 79 | p.set_message(format!( |
80 | "Change version for list {} to minecraft version: {}", | 80 | "Change version for list {id} to minecraft version: {mc_version}" |
81 | id, mc_version | ||
82 | )); | 81 | )); |
83 | 82 | ||
84 | lists_version(config, id, &mc_version)?; | 83 | lists_version(config, id, &mc_version)?; |
85 | 84 | ||
86 | p.finish_with_message(format!( | 85 | p.finish_with_message(format!( |
87 | "Changed version for list {} to minecraft version: {}", | 86 | "Changed version for list {id} to minecraft version: {mc_version}" |
88 | id, mc_version | ||
89 | )); | 87 | )); |
90 | 88 | ||
91 | let list = lists_get(config, id)?; | 89 | let list = lists_get(config, id)?; |
@@ -96,7 +94,7 @@ pub fn list_list(config: &Cfg) -> MLE<()> { | |||
96 | let lists = lists_get_all_ids(config)?; | 94 | let lists = lists_get_all_ids(config)?; |
97 | for list in lists { | 95 | for list in lists { |
98 | let l = lists_get(config, &list)?; | 96 | let l = lists_get(config, &list)?; |
99 | println!("{}: | {} | {}", l.id, l.mc_version, l.modloader) | 97 | println!("{}: | {} | {}", l.id, l.mc_version, l.modloader); |
100 | } | 98 | } |
101 | Ok(()) | 99 | Ok(()) |
102 | } | 100 | } |
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 4488b70..e0e54b2 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -65,7 +65,7 @@ pub async fn mod_add( | |||
65 | add_p.inc(1); | 65 | add_p.inc(1); |
66 | match m.id { | 66 | match m.id { |
67 | IDSelector::ModificationID(pid) => { | 67 | IDSelector::ModificationID(pid) => { |
68 | mod_ids.push((pid, m.set_version)) | 68 | mod_ids.push((pid, m.set_version)); |
69 | } | 69 | } |
70 | IDSelector::VersionID(vid) => ver_ids.push((vid, m.set_version)), | 70 | IDSelector::VersionID(vid) => ver_ids.push((vid, m.set_version)), |
71 | } | 71 | } |
@@ -153,7 +153,7 @@ pub async fn mod_add( | |||
153 | }?; | 153 | }?; |
154 | 154 | ||
155 | if project.current_version.is_some() { | 155 | if project.current_version.is_some() { |
156 | downloadstack.push(project.current_version.unwrap()) | 156 | downloadstack.push(project.current_version.unwrap()); |
157 | }; | 157 | }; |
158 | 158 | ||
159 | project_p.inc(1); | 159 | project_p.inc(1); |
@@ -245,7 +245,7 @@ async fn get_mod_infos( | |||
245 | applicable_versions: available_versions_vec, | 245 | applicable_versions: available_versions_vec, |
246 | download_link: file, | 246 | download_link: file, |
247 | set_version: *setmap.get(&project.slug).unwrap(), | 247 | set_version: *setmap.get(&project.slug).unwrap(), |
248 | }) | 248 | }); |
249 | } else { | 249 | } else { |
250 | current_version = None; | 250 | current_version = None; |
251 | file = String::from("NONE"); | 251 | file = String::from("NONE"); |
@@ -258,7 +258,7 @@ async fn get_mod_infos( | |||
258 | applicable_versions: available_versions_vec, | 258 | applicable_versions: available_versions_vec, |
259 | download_link: file, | 259 | download_link: file, |
260 | set_version: *setmap.get(&project.id).unwrap(), | 260 | set_version: *setmap.get(&project.id).unwrap(), |
261 | }) | 261 | }); |
262 | } | 262 | } |
263 | } | 263 | } |
264 | 264 | ||
@@ -308,7 +308,7 @@ async fn get_ver_info( | |||
308 | applicable_versions: vec![String::from(&version.id)], | 308 | applicable_versions: vec![String::from(&version.id)], |
309 | download_link: file, | 309 | download_link: file, |
310 | set_version: *setmap.get(&version.id).unwrap(), | 310 | set_version: *setmap.get(&version.id).unwrap(), |
311 | }) | 311 | }); |
312 | } | 312 | } |
313 | Ok(projectinfo) | 313 | Ok(projectinfo) |
314 | } | 314 | } |
@@ -335,7 +335,7 @@ pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { | |||
335 | 335 | ||
336 | progress.set_message("Delete file"); | 336 | progress.set_message("Delete file"); |
337 | match delete_version(list, version) { | 337 | match delete_version(list, version) { |
338 | Ok(_) => (), | 338 | Ok(()) => (), |
339 | Err(err) => { | 339 | Err(err) => { |
340 | if err.to_string() | 340 | if err.to_string() |
341 | != "User input not accepted: VERSION_NOT_FOUND_IN_FILES" | 341 | != "User input not accepted: VERSION_NOT_FOUND_IN_FILES" |
diff --git a/src/config.rs b/src/config.rs index f0eb8f7..3538a69 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -70,12 +70,9 @@ impl Cfg { | |||
70 | }; | 70 | }; |
71 | //Check versions | 71 | //Check versions |
72 | let versionfile = format!("{}/versions.json", config.versions); | 72 | let versionfile = format!("{}/versions.json", config.versions); |
73 | match File::open(&versionfile) { | 73 | if let Ok(..) = File::open(&versionfile) { } else { |
74 | Ok(..) => (), | 74 | create_versions_dummy(&versionfile).await?; |
75 | Err(..) => { | 75 | check_game_versions(&versionfile, true).await?; |
76 | create_versions_dummy(&versionfile).await?; | ||
77 | check_game_versions(&versionfile, true).await?; | ||
78 | } | ||
79 | } | 76 | } |
80 | 77 | ||
81 | Ok(config) | 78 | Ok(config) |
@@ -94,7 +91,7 @@ fn create_config(path: &str) -> MLE<()> { | |||
94 | .to_string(); | 91 | .to_string(); |
95 | let default_cfg = Cfg { | 92 | let default_cfg = Cfg { |
96 | data: cache_dir.clone(), | 93 | data: cache_dir.clone(), |
97 | cache: format!("{}/cache", cache_dir), | 94 | cache: format!("{cache_dir}/cache"), |
98 | versions: cache_dir, | 95 | versions: cache_dir, |
99 | defaults: Defaults { | 96 | defaults: Defaults { |
100 | modloader: Modloader::Fabric, | 97 | modloader: Modloader::Fabric, |
@@ -107,7 +104,7 @@ fn create_config(path: &str) -> MLE<()> { | |||
107 | create_dir_all(path.split("config.toml").collect::<Vec<&str>>()[0])?; | 104 | create_dir_all(path.split("config.toml").collect::<Vec<&str>>()[0])?; |
108 | let mut file = File::create(path)?; | 105 | let mut file = File::create(path)?; |
109 | file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; | 106 | file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; |
110 | p.finish_with_message(format!("Created default config ({})", path)); | 107 | p.finish_with_message(format!("Created default config ({path})")); |
111 | Ok(()) | 108 | Ok(()) |
112 | } | 109 | } |
113 | 110 | ||
@@ -118,7 +115,7 @@ fn create_database(path: &str) -> MLE<()> { | |||
118 | 115 | ||
119 | File::create(path)?; | 116 | File::create(path)?; |
120 | db_setup(path)?; | 117 | db_setup(path)?; |
121 | p.finish_with_message(format!("Created database ({})", path)); | 118 | p.finish_with_message(format!("Created database ({path})")); |
122 | Ok(()) | 119 | Ok(()) |
123 | } | 120 | } |
124 | 121 | ||
@@ -128,7 +125,7 @@ fn create_cache(path: &str) -> MLE<()> { | |||
128 | p.set_message("Create cache"); | 125 | p.set_message("Create cache"); |
129 | 126 | ||
130 | create_dir_all(path)?; | 127 | create_dir_all(path)?; |
131 | p.finish_with_message(format!("Created cache ({})", path)); | 128 | p.finish_with_message(format!("Created cache ({path})")); |
132 | Ok(()) | 129 | Ok(()) |
133 | } | 130 | } |
134 | 131 | ||
@@ -137,6 +134,6 @@ async fn create_versions_dummy(path: &str) -> MLE<()> { | |||
137 | p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); | 134 | p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); |
138 | p.set_message("Create version file"); | 135 | p.set_message("Create version file"); |
139 | File::create(path)?; | 136 | File::create(path)?; |
140 | p.finish_with_message(format!("Created version file ({})", path)); | 137 | p.finish_with_message(format!("Created version file ({path})")); |
141 | Ok(()) | 138 | Ok(()) |
142 | } | 139 | } |
@@ -52,7 +52,7 @@ pub fn mods_get_all_ids( | |||
52 | /// | 52 | /// |
53 | ///Will return `MLError` when no mod id is found | 53 | ///Will return `MLError` when no mod id is found |
54 | pub fn mods_get_id(data: &str, slug: &str) -> MLE<String> { | 54 | pub fn mods_get_id(data: &str, slug: &str) -> MLE<String> { |
55 | let data = format!("{}/data.db", data); | 55 | let data = format!("{data}/data.db"); |
56 | let connection = Connection::open(data)?; | 56 | let connection = Connection::open(data)?; |
57 | 57 | ||
58 | let mut mod_id = String::new(); | 58 | let mut mod_id = String::new(); |
@@ -157,14 +157,14 @@ pub fn mods_get_versions( | |||
157 | for (i, id) in mods.iter().enumerate() { | 157 | for (i, id) in mods.iter().enumerate() { |
158 | let mut or = " OR"; | 158 | let mut or = " OR"; |
159 | if i == mods.len() - 1 { | 159 | if i == mods.len() - 1 { |
160 | or = "" | 160 | or = ""; |
161 | }; | 161 | }; |
162 | wherestr = format!("{} id = '{}'{}", wherestr, id, or); | 162 | wherestr = format!("{wherestr} id = '{id}'{or}"); |
163 | } | 163 | } |
164 | 164 | ||
165 | let mut versionmaps: Vec<DBModlistVersions> = Vec::new(); | 165 | let mut versionmaps: Vec<DBModlistVersions> = Vec::new(); |
166 | let mut stmt = connection.prepare( | 166 | let mut stmt = connection.prepare( |
167 | format!("SELECT id, versions, title FROM mods {}", wherestr).as_str(), | 167 | format!("SELECT id, versions, title FROM mods {wherestr}").as_str(), |
168 | )?; | 168 | )?; |
169 | let id_iter = stmt.query_map([], |row| { | 169 | let id_iter = stmt.query_map([], |row| { |
170 | Ok(vec![ | 170 | Ok(vec![ |
@@ -179,7 +179,7 @@ pub fn mods_get_versions( | |||
179 | versionmaps.push(DBModlistVersions { | 179 | versionmaps.push(DBModlistVersions { |
180 | mod_id: String::from(&version[0]), | 180 | mod_id: String::from(&version[0]), |
181 | versions: String::from(&version[1]), | 181 | versions: String::from(&version[1]), |
182 | }) | 182 | }); |
183 | } | 183 | } |
184 | 184 | ||
185 | match versionmaps.is_empty() { | 185 | match versionmaps.is_empty() { |
@@ -208,8 +208,7 @@ pub fn userlist_insert( | |||
208 | 208 | ||
209 | connection.execute( | 209 | connection.execute( |
210 | format!( | 210 | format!( |
211 | "INSERT INTO {} VALUES (?1, ?2, ?3, ?4, 'NONE', ?5)", | 211 | "INSERT INTO {list_id} VALUES (?1, ?2, ?3, ?4, 'NONE', ?5)" |
212 | list_id | ||
213 | ) | 212 | ) |
214 | .as_str(), | 213 | .as_str(), |
215 | [ | 214 | [ |
@@ -230,17 +229,17 @@ pub fn userlist_get_all_ids(config: &Cfg, list_id: &str) -> MLE<Vec<String>> { | |||
230 | 229 | ||
231 | let mut mod_ids: Vec<String> = Vec::new(); | 230 | let mut mod_ids: Vec<String> = Vec::new(); |
232 | let mut stmt = connection | 231 | let mut stmt = connection |
233 | .prepare(format!("SELECT mod_id FROM {}", list_id).as_str())?; | 232 | .prepare(format!("SELECT mod_id FROM {list_id}").as_str())?; |
234 | let id_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; | 233 | let id_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; |
235 | 234 | ||
236 | for id in id_iter { | 235 | for id in id_iter { |
237 | mod_ids.push(id?) | 236 | mod_ids.push(id?); |
238 | } | 237 | } |
239 | 238 | ||
240 | match mod_ids.is_empty() { | 239 | match mod_ids.is_empty() { |
241 | true => Err(MLError::new( | 240 | true => Err(MLError::new( |
242 | ErrorType::DBError, | 241 | ErrorType::DBError, |
243 | &format!("NO_MODS_USERLIST{}", list_id), | 242 | &format!("NO_MODS_USERLIST{list_id}"), |
244 | )), | 243 | )), |
245 | false => Ok(mod_ids), | 244 | false => Ok(mod_ids), |
246 | } | 245 | } |
@@ -251,7 +250,7 @@ pub fn userlist_remove(config: &Cfg, list_id: &str, mod_id: &str) -> MLE<()> { | |||
251 | let connection = Connection::open(data)?; | 250 | let connection = Connection::open(data)?; |
252 | 251 | ||
253 | connection.execute( | 252 | connection.execute( |
254 | format!("DELETE FROM {} WHERE mod_id = ?", list_id).as_str(), | 253 | format!("DELETE FROM {list_id} WHERE mod_id = ?").as_str(), |
255 | [mod_id], | 254 | [mod_id], |
256 | )?; | 255 | )?; |
257 | Ok(()) | 256 | Ok(()) |
@@ -268,8 +267,7 @@ pub fn userlist_get_applicable_versions( | |||
268 | let mut version: String = String::new(); | 267 | let mut version: String = String::new(); |
269 | let mut stmt = connection.prepare( | 268 | let mut stmt = connection.prepare( |
270 | format!( | 269 | format!( |
271 | "SELECT applicable_versions FROM {} WHERE mod_id = ?", | 270 | "SELECT applicable_versions FROM {list_id} WHERE mod_id = ?" |
272 | list_id | ||
273 | ) | 271 | ) |
274 | .as_str(), | 272 | .as_str(), |
275 | )?; | 273 | )?; |
@@ -295,7 +293,7 @@ pub fn userlist_get_all_applicable_versions_with_mods( | |||
295 | 293 | ||
296 | let mut versions: Vec<(String, String)> = Vec::new(); | 294 | let mut versions: Vec<(String, String)> = Vec::new(); |
297 | let mut stmt = connection.prepare( | 295 | let mut stmt = connection.prepare( |
298 | format!("SELECT mod_id, applicable_versions FROM {}", list_id).as_str(), | 296 | format!("SELECT mod_id, applicable_versions FROM {list_id}").as_str(), |
299 | )?; | 297 | )?; |
300 | let id_iter = stmt.query_map([], |row| { | 298 | let id_iter = stmt.query_map([], |row| { |
301 | Ok(vec![ | 299 | Ok(vec![ |
@@ -306,7 +304,7 @@ pub fn userlist_get_all_applicable_versions_with_mods( | |||
306 | 304 | ||
307 | for ver in id_iter { | 305 | for ver in id_iter { |
308 | let out = ver?; | 306 | let out = ver?; |
309 | versions.push((out[0].to_owned(), out[1].to_owned())); | 307 | versions.push((out[0].clone(), out[1].clone())); |
310 | } | 308 | } |
311 | 309 | ||
312 | if versions.is_empty() { | 310 | if versions.is_empty() { |
@@ -326,7 +324,7 @@ pub fn userlist_get_current_version( | |||
326 | 324 | ||
327 | let mut version: String = String::new(); | 325 | let mut version: String = String::new(); |
328 | let mut stmt = connection.prepare( | 326 | let mut stmt = connection.prepare( |
329 | format!("SELECT current_version FROM {} WHERE mod_id = ?", list_id) | 327 | format!("SELECT current_version FROM {list_id} WHERE mod_id = ?") |
330 | .as_str(), | 328 | .as_str(), |
331 | )?; | 329 | )?; |
332 | let ver_iter = | 330 | let ver_iter = |
@@ -351,7 +349,7 @@ pub fn userlist_get_all_current_version_ids( | |||
351 | 349 | ||
352 | let mut versions: Vec<String> = Vec::new(); | 350 | let mut versions: Vec<String> = Vec::new(); |
353 | let mut stmt = connection | 351 | let mut stmt = connection |
354 | .prepare(format!("SELECT current_version FROM {}", list_id).as_str())?; | 352 | .prepare(format!("SELECT current_version FROM {list_id}").as_str())?; |
355 | let id_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; | 353 | let id_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; |
356 | 354 | ||
357 | for id in id_iter { | 355 | for id in id_iter { |
@@ -374,7 +372,7 @@ pub fn userlist_get_all_current_versions_with_mods( | |||
374 | 372 | ||
375 | let mut versions: Vec<(String, String)> = Vec::new(); | 373 | let mut versions: Vec<(String, String)> = Vec::new(); |
376 | let mut stmt = connection.prepare( | 374 | let mut stmt = connection.prepare( |
377 | format!("SELECT mod_id, current_version FROM {}", list_id).as_str(), | 375 | format!("SELECT mod_id, current_version FROM {list_id}").as_str(), |
378 | )?; | 376 | )?; |
379 | let id_iter = stmt.query_map([], |row| { | 377 | let id_iter = stmt.query_map([], |row| { |
380 | Ok(vec![ | 378 | Ok(vec![ |
@@ -385,7 +383,7 @@ pub fn userlist_get_all_current_versions_with_mods( | |||
385 | 383 | ||
386 | for ver in id_iter { | 384 | for ver in id_iter { |
387 | let out = ver?; | 385 | let out = ver?; |
388 | versions.push((out[0].to_owned(), out[1].to_owned())); | 386 | versions.push((out[0].clone(), out[1].clone())); |
389 | } | 387 | } |
390 | 388 | ||
391 | if versions.is_empty() { | 389 | if versions.is_empty() { |
@@ -408,7 +406,7 @@ pub fn userlist_get_set_version( | |||
408 | 406 | ||
409 | let mut set_version: bool = false; | 407 | let mut set_version: bool = false; |
410 | let mut stmt = connection.prepare( | 408 | let mut stmt = connection.prepare( |
411 | format!("SELECT set_version FROM {} WHERE mod_id = ?", list_id) | 409 | format!("SELECT set_version FROM {list_id} WHERE mod_id = ?") |
412 | .as_str(), | 410 | .as_str(), |
413 | )?; | 411 | )?; |
414 | let ver_iter = | 412 | let ver_iter = |
@@ -432,7 +430,7 @@ pub fn userlist_change_versions( | |||
432 | let data = format!("{}/data.db", config.data); | 430 | let data = format!("{}/data.db", config.data); |
433 | let connection = Connection::open(data)?; | 431 | let connection = Connection::open(data)?; |
434 | 432 | ||
435 | connection.execute(format!("UPDATE {} SET current_version = ?1, applicable_versions = ?2, current_download = ?3 WHERE mod_id = ?4", list_id).as_str(), [current_version, versions, link, mod_id])?; | 433 | connection.execute(format!("UPDATE {list_id} SET current_version = ?1, applicable_versions = ?2, current_download = ?3 WHERE mod_id = ?4").as_str(), [current_version, versions, link, mod_id])?; |
436 | Ok(()) | 434 | Ok(()) |
437 | } | 435 | } |
438 | 436 | ||
@@ -453,14 +451,13 @@ pub fn userlist_add_disabled_versions( | |||
453 | let disabled_versions = match currently_disabled_versions == "NONE" { | 451 | let disabled_versions = match currently_disabled_versions == "NONE" { |
454 | true => disabled_version, | 452 | true => disabled_version, |
455 | false => { | 453 | false => { |
456 | format!("{}|{}", currently_disabled_versions, disabled_version) | 454 | format!("{currently_disabled_versions}|{disabled_version}") |
457 | } | 455 | } |
458 | }; | 456 | }; |
459 | 457 | ||
460 | connection.execute( | 458 | connection.execute( |
461 | format!( | 459 | format!( |
462 | "UPDATE {} SET disabled_versions = ?1 WHERE mod_id = ?2", | 460 | "UPDATE {list_id} SET disabled_versions = ?1 WHERE mod_id = ?2" |
463 | list_id | ||
464 | ) | 461 | ) |
465 | .as_str(), | 462 | .as_str(), |
466 | [disabled_versions, mod_id], | 463 | [disabled_versions, mod_id], |
@@ -478,7 +475,7 @@ pub fn userlist_get_disabled_versions( | |||
478 | 475 | ||
479 | let mut version: String = String::new(); | 476 | let mut version: String = String::new(); |
480 | let mut stmt = connection.prepare( | 477 | let mut stmt = connection.prepare( |
481 | format!("SELECT disabled_versions FROM {} WHERE mod_id = ?", list_id) | 478 | format!("SELECT disabled_versions FROM {list_id} WHERE mod_id = ?") |
482 | .as_str(), | 479 | .as_str(), |
483 | )?; | 480 | )?; |
484 | let ver_iter = | 481 | let ver_iter = |
@@ -503,13 +500,13 @@ pub fn userlist_get_all_downloads( | |||
503 | 500 | ||
504 | let mut links: Vec<String> = Vec::new(); | 501 | let mut links: Vec<String> = Vec::new(); |
505 | let mut stmt = connection.prepare( | 502 | let mut stmt = connection.prepare( |
506 | format!("SELECT current_download FROM {}", list_id).as_str(), | 503 | format!("SELECT current_download FROM {list_id}").as_str(), |
507 | )?; | 504 | )?; |
508 | let link_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; | 505 | let link_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; |
509 | 506 | ||
510 | for link in link_iter { | 507 | for link in link_iter { |
511 | let l = link?; | 508 | let l = link?; |
512 | links.push(l) | 509 | links.push(l); |
513 | } | 510 | } |
514 | 511 | ||
515 | if links.is_empty() { | 512 | if links.is_empty() { |
@@ -538,7 +535,7 @@ pub fn lists_insert( | |||
538 | "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", | 535 | "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", |
539 | [id, mc_version, &mod_loader.to_string(), download_folder], | 536 | [id, mc_version, &mod_loader.to_string(), download_folder], |
540 | )?; | 537 | )?; |
541 | connection.execute(format!("CREATE TABLE {}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT, 'disabled_versions' TEXT DEFAULT 'NONE', 'set_version' INTEGER, CONSTRAINT {}_PK PRIMARY KEY (mod_id) )", id, id).as_str(), [])?; | 538 | connection.execute(format!("CREATE TABLE {id}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT, 'disabled_versions' TEXT DEFAULT 'NONE', 'set_version' INTEGER, CONSTRAINT {id}_PK PRIMARY KEY (mod_id) )").as_str(), [])?; |
542 | 539 | ||
543 | Ok(()) | 540 | Ok(()) |
544 | } | 541 | } |
@@ -548,7 +545,7 @@ pub fn lists_remove(config: &Cfg, id: &str) -> MLE<()> { | |||
548 | let connection = Connection::open(data)?; | 545 | let connection = Connection::open(data)?; |
549 | 546 | ||
550 | connection.execute("DELETE FROM lists WHERE id = ?", [&id])?; | 547 | connection.execute("DELETE FROM lists WHERE id = ?", [&id])?; |
551 | connection.execute(format!("DROP TABLE {}", id).as_str(), [])?; | 548 | connection.execute(format!("DROP TABLE {id}").as_str(), [])?; |
552 | Ok(()) | 549 | Ok(()) |
553 | } | 550 | } |
554 | 551 | ||
@@ -611,7 +608,7 @@ pub fn lists_get_all_ids(config: &Cfg) -> MLE<Vec<String>> { | |||
611 | let id_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; | 608 | let id_iter = stmt.query_map([], |row| row.get::<usize, String>(0))?; |
612 | 609 | ||
613 | for id in id_iter { | 610 | for id in id_iter { |
614 | list_ids.push(id?) | 611 | list_ids.push(id?); |
615 | } | 612 | } |
616 | 613 | ||
617 | match list_ids.is_empty() { | 614 | match list_ids.is_empty() { |
@@ -664,8 +661,7 @@ pub fn s_userlist_update_download( | |||
664 | 661 | ||
665 | connection.execute( | 662 | connection.execute( |
666 | format!( | 663 | format!( |
667 | "UPDATE {} SET current_download = ?1 WHERE mod_id = ?2", | 664 | "UPDATE {list_id} SET current_download = ?1 WHERE mod_id = ?2" |
668 | list_id | ||
669 | ) | 665 | ) |
670 | .as_str(), | 666 | .as_str(), |
671 | [link, mod_id], | 667 | [link, mod_id], |
@@ -734,7 +730,7 @@ pub fn s_insert_column( | |||
734 | let data = format!("{}/data.db", config.data); | 730 | let data = format!("{}/data.db", config.data); |
735 | let connection = Connection::open(data)?; | 731 | let connection = Connection::open(data)?; |
736 | 732 | ||
737 | let mut sql = format!("ALTER TABLE {} ADD '{}' {}", table, column, c_type); | 733 | let mut sql = format!("ALTER TABLE {table} ADD '{column}' {c_type}"); |
738 | 734 | ||
739 | if default.is_some() { | 735 | if default.is_some() { |
740 | sql = format!("{} DEFAULT {}", sql, default.unwrap()); | 736 | sql = format!("{} DEFAULT {}", sql, default.unwrap()); |
diff --git a/src/error.rs b/src/error.rs index a2b37a8..b4cc444 100644 --- a/src/error.rs +++ b/src/error.rs | |||
@@ -118,7 +118,7 @@ impl From<serde_json::error::Error> for MLError { | |||
118 | } | 118 | } |
119 | 119 | ||
120 | impl MLError { | 120 | impl MLError { |
121 | pub fn new(etype: ErrorType, message: &str) -> Self { | 121 | #[must_use] pub fn new(etype: ErrorType, message: &str) -> Self { |
122 | Self { | 122 | Self { |
123 | etype, | 123 | etype, |
124 | message: String::from(message), | 124 | message: String::from(message), |
diff --git a/src/files.rs b/src/files.rs index 3a16c62..bf5a0a0 100644 --- a/src/files.rs +++ b/src/files.rs | |||
@@ -55,7 +55,7 @@ pub async fn download_versions( | |||
55 | } | 55 | } |
56 | 56 | ||
57 | while js.join_next().await.is_some() { | 57 | while js.join_next().await.is_some() { |
58 | all.inc(1) | 58 | all.inc(1); |
59 | } | 59 | } |
60 | 60 | ||
61 | all.finish_with_message(format!("✓Downloading {}", list.id)); | 61 | all.finish_with_message(format!("✓Downloading {}", list.id)); |
@@ -128,7 +128,7 @@ async fn download_file( | |||
128 | name: &str, | 128 | name: &str, |
129 | progress: &ProgressBar, | 129 | progress: &ProgressBar, |
130 | ) -> MLE<()> { | 130 | ) -> MLE<()> { |
131 | let dl_path_file = format!("{}/{}", path, name); | 131 | let dl_path_file = format!("{path}/{name}"); |
132 | let res = Client::new().get(url).send().await?; | 132 | let res = Client::new().get(url).send().await?; |
133 | 133 | ||
134 | let size = res.content_length().expect("Couldn't get content length"); | 134 | let size = res.content_length().expect("Couldn't get content length"); |
@@ -169,7 +169,7 @@ pub fn disable_version( | |||
169 | mod_id: String, | 169 | mod_id: String, |
170 | ) -> MLE<()> { | 170 | ) -> MLE<()> { |
171 | let file = get_file_path(¤t_list, String::from(&versionid))?; | 171 | let file = get_file_path(¤t_list, String::from(&versionid))?; |
172 | let disabled = format!("{}.disabled", file); | 172 | let disabled = format!("{file}.disabled"); |
173 | 173 | ||
174 | rename(file, disabled)?; | 174 | rename(file, disabled)?; |
175 | 175 | ||
@@ -103,7 +103,7 @@ pub fn load_game_versions(path: &str) -> MLE<Vec<GameVersion>> { | |||
103 | } | 103 | } |
104 | 104 | ||
105 | impl VersionLevel { | 105 | impl VersionLevel { |
106 | pub fn from(str: &str) -> Self { | 106 | #[must_use] pub fn from(str: &str) -> Self { |
107 | match str { | 107 | match str { |
108 | "release" => VersionLevel::Release, | 108 | "release" => VersionLevel::Release, |
109 | "snapshot" => VersionLevel::Snapshot, | 109 | "snapshot" => VersionLevel::Snapshot, |
@@ -116,7 +116,7 @@ impl VersionLevel { | |||
116 | versions_path: &str, | 116 | versions_path: &str, |
117 | force_update: bool, | 117 | force_update: bool, |
118 | ) -> MLE<String> { | 118 | ) -> MLE<String> { |
119 | let path = format!("{}/versions.json", versions_path); | 119 | let path = format!("{versions_path}/versions.json"); |
120 | check_game_versions(&path, force_update).await?; | 120 | check_game_versions(&path, force_update).await?; |
121 | let mut versions = load_game_versions(&path)?.into_iter(); | 121 | let mut versions = load_game_versions(&path)?.into_iter(); |
122 | 122 | ||
diff --git a/src/main.rs b/src/main.rs index 5d60a17..21f2a30 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -28,7 +28,7 @@ enum Commands { | |||
28 | #[command(subcommand)] | 28 | #[command(subcommand)] |
29 | command: ListCommands, | 29 | command: ListCommands, |
30 | 30 | ||
31 | /// Force GameVersion update | 31 | /// Force `GameVersion` update |
32 | #[arg(long)] | 32 | #[arg(long)] |
33 | force_gameupdate: bool, | 33 | force_gameupdate: bool, |
34 | }, | 34 | }, |
@@ -262,7 +262,7 @@ async fn main() { | |||
262 | Some(l) => lists_get(&config, &l).unwrap(), | 262 | Some(l) => lists_get(&config, &l).unwrap(), |
263 | None => get_current_list(&config).unwrap(), | 263 | None => get_current_list(&config).unwrap(), |
264 | }; | 264 | }; |
265 | liststack.push(current) | 265 | liststack.push(current); |
266 | } | 266 | } |
267 | 267 | ||
268 | update(&config, liststack, clean, download, remove).await | 268 | update(&config, liststack, clean, download, remove).await |
@@ -284,7 +284,7 @@ async fn main() { | |||
284 | Some(l) => lists_get(&config, &l).unwrap(), | 284 | Some(l) => lists_get(&config, &l).unwrap(), |
285 | None => get_current_list(&config).unwrap(), | 285 | None => get_current_list(&config).unwrap(), |
286 | }; | 286 | }; |
287 | liststack.push(current) | 287 | liststack.push(current); |
288 | } | 288 | } |
289 | 289 | ||
290 | download(&config, liststack, clean, remove).await | 290 | download(&config, liststack, clean, remove).await |