diff options
author | FxQnLr <[email protected]> | 2023-04-27 10:08:20 +0200 |
---|---|---|
committer | FxQnLr <[email protected]> | 2023-04-27 10:08:20 +0200 |
commit | 4e6466af1329f7b9e341df2e76ab696d11f80c93 (patch) | |
tree | eef58fecfadad90386b38af581abab8cc3d3cfc0 /src | |
parent | f1912007484f077b5585a872ca732d087beefa9a (diff) | |
download | modlist-4e6466af1329f7b9e341df2e76ab696d11f80c93.tar modlist-4e6466af1329f7b9e341df2e76ab696d11f80c93.tar.gz modlist-4e6466af1329f7b9e341df2e76ab696d11f80c93.zip |
version bump, cargo fmt and cargo update
Diffstat (limited to 'src')
-rw-r--r-- | src/cache.rs | 5 | ||||
-rw-r--r-- | src/config.rs | 13 | ||||
-rw-r--r-- | src/db.rs | 1 | ||||
-rw-r--r-- | src/files.rs | 19 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 22 |
6 files changed, 37 insertions, 25 deletions
diff --git a/src/cache.rs b/src/cache.rs index 44029e0..11645d1 100644 --- a/src/cache.rs +++ b/src/cache.rs | |||
@@ -1,4 +1,7 @@ | |||
1 | use std::{collections::HashMap, fs::{read_dir, copy}}; | 1 | use std::{ |
2 | collections::HashMap, | ||
3 | fs::{copy, read_dir}, | ||
4 | }; | ||
2 | 5 | ||
3 | /// . | 6 | /// . |
4 | /// | 7 | /// |
diff --git a/src/config.rs b/src/config.rs index 817d22b..61db1c7 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -1,11 +1,12 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | fs::{File, create_dir_all}, | 2 | fs::{create_dir_all, File}, |
3 | io::{Read, Write}, path::Path, | 3 | io::{Read, Write}, |
4 | path::Path, | ||
4 | }; | 5 | }; |
5 | 6 | ||
6 | use serde::{Deserialize, Serialize}; | 7 | use serde::{Deserialize, Serialize}; |
7 | 8 | ||
8 | use crate::{error::MLE, db::db_setup}; | 9 | use crate::{db::db_setup, error::MLE}; |
9 | 10 | ||
10 | #[derive(Debug, Clone, Serialize, Deserialize)] | 11 | #[derive(Debug, Clone, Serialize, Deserialize)] |
11 | pub struct Cfg { | 12 | pub struct Cfg { |
@@ -23,7 +24,11 @@ impl Cfg { | |||
23 | pub fn init(path: Option<String>) -> MLE<Self> { | 24 | pub fn init(path: Option<String>) -> MLE<Self> { |
24 | let configfile = match path.clone() { | 25 | let configfile = match path.clone() { |
25 | Some(p) => String::from(p), | 26 | Some(p) => String::from(p), |
26 | None => dirs::config_dir().unwrap().join("modlist.toml").to_string_lossy().to_string(), | 27 | None => dirs::config_dir() |
28 | .unwrap() | ||
29 | .join("modlist.toml") | ||
30 | .to_string_lossy() | ||
31 | .to_string(), | ||
27 | }; | 32 | }; |
28 | 33 | ||
29 | let mut file = match File::open(&configfile) { | 34 | let mut file = match File::open(&configfile) { |
@@ -702,7 +702,6 @@ pub fn s_insert_column( | |||
702 | } | 702 | } |
703 | 703 | ||
704 | pub fn db_setup(path: &str) -> MLE<()> { | 704 | pub fn db_setup(path: &str) -> MLE<()> { |
705 | |||
706 | let connection = Connection::open(path)?; | 705 | let connection = Connection::open(path)?; |
707 | 706 | ||
708 | connection.execute_batch( | 707 | connection.execute_batch( |
diff --git a/src/files.rs b/src/files.rs index a73fc18..59fc7de 100644 --- a/src/files.rs +++ b/src/files.rs | |||
@@ -2,20 +2,20 @@ use futures_util::StreamExt; | |||
2 | use reqwest::Client; | 2 | use reqwest::Client; |
3 | use std::{ | 3 | use std::{ |
4 | collections::HashMap, | 4 | collections::HashMap, |
5 | fs::{read_dir, remove_file, rename, File, copy}, | 5 | fs::{copy, read_dir, remove_file, rename, File}, |
6 | io::Write, | 6 | io::Write, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | use crate::{ | 9 | use crate::{ |
10 | cache::{copy_cached_version, get_cached_versions}, | ||
10 | config::Cfg, | 11 | config::Cfg, |
11 | db::{mods_get_info, userlist_add_disabled_versions}, | 12 | db::{mods_get_info, userlist_add_disabled_versions}, |
12 | error::{ErrorType, MLError, MLE}, | 13 | error::{ErrorType, MLError, MLE}, |
13 | modrinth::Version, | 14 | modrinth::Version, |
14 | List, cache::{get_cached_versions, copy_cached_version}, | 15 | List, |
15 | }; | 16 | }; |
16 | 17 | ||
17 | pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>) -> MLE<String> { | 18 | pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>) -> MLE<String> { |
18 | |||
19 | let mut cached = get_cached_versions(&config.cache); | 19 | let mut cached = get_cached_versions(&config.cache); |
20 | 20 | ||
21 | println!("{:#?}", cached); | 21 | println!("{:#?}", cached); |
@@ -30,7 +30,10 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>) | |||
30 | //Check cache if already downloaded | 30 | //Check cache if already downloaded |
31 | let c = cached.remove(&ver.id); | 31 | let c = cached.remove(&ver.id); |
32 | if c.is_some() { | 32 | if c.is_some() { |
33 | print!("\t└({})Get version {} from cache", project_info.title, ver.id); | 33 | print!( |
34 | "\t└({})Get version {} from cache", | ||
35 | project_info.title, ver.id | ||
36 | ); | ||
34 | //Force flush of stdout, else print! doesn't print instantly | 37 | //Force flush of stdout, else print! doesn't print instantly |
35 | std::io::stdout().flush()?; | 38 | std::io::stdout().flush()?; |
36 | copy_cached_version(&c.unwrap(), &dl_path); | 39 | copy_cached_version(&c.unwrap(), &dl_path); |
@@ -52,7 +55,12 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>) | |||
52 | ver.id, | 55 | ver.id, |
53 | extension | 56 | extension |
54 | ); | 57 | ); |
55 | download_file(primary_file.url, list.clone().download_folder, filename.clone()).await?; | 58 | download_file( |
59 | primary_file.url, | ||
60 | list.clone().download_folder, | ||
61 | filename.clone(), | ||
62 | ) | ||
63 | .await?; | ||
56 | println!(" ✓"); | 64 | println!(" ✓"); |
57 | //Copy file to cache | 65 | //Copy file to cache |
58 | print!("\t └Copy to cache"); | 66 | print!("\t └Copy to cache"); |
@@ -64,7 +72,6 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec<Version>) | |||
64 | copy(dl_path_file, cache_path)?; | 72 | copy(dl_path_file, cache_path)?; |
65 | println!(" ✓"); | 73 | println!(" ✓"); |
66 | } | 74 | } |
67 | |||
68 | } | 75 | } |
69 | 76 | ||
70 | Ok(dl_path) | 77 | Ok(dl_path) |
@@ -1,10 +1,10 @@ | |||
1 | pub mod apis; | 1 | pub mod apis; |
2 | pub mod cache; | ||
2 | pub mod commands; | 3 | pub mod commands; |
3 | pub mod config; | 4 | pub mod config; |
4 | pub mod db; | 5 | pub mod db; |
5 | pub mod error; | 6 | pub mod error; |
6 | pub mod files; | 7 | pub mod files; |
7 | pub mod cache; | ||
8 | 8 | ||
9 | use std::fmt::Display; | 9 | use std::fmt::Display; |
10 | 10 | ||
diff --git a/src/main.rs b/src/main.rs index 30c4001..0ecb850 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -2,8 +2,8 @@ use clap::{Parser, Subcommand}; | |||
2 | use modlist::{ | 2 | use modlist::{ |
3 | config::Cfg, | 3 | config::Cfg, |
4 | db::{config_get_current_list, lists_get, lists_get_all_ids}, | 4 | db::{config_get_current_list, lists_get, lists_get_all_ids}, |
5 | download, export, get_current_list, import, list_add, list_change, list_remove, | 5 | download, export, get_current_list, import, list_add, list_change, list_remove, list_version, |
6 | list_version, mod_add, mod_remove, update, IDSelector, List, Modloader, | 6 | mod_add, mod_remove, update, IDSelector, List, Modloader, |
7 | }; | 7 | }; |
8 | 8 | ||
9 | //TODO implement remote sql db | 9 | //TODO implement remote sql db |
@@ -14,7 +14,7 @@ use modlist::{ | |||
14 | struct Cli { | 14 | struct Cli { |
15 | #[command(subcommand)] | 15 | #[command(subcommand)] |
16 | command: Commands, | 16 | command: Commands, |
17 | 17 | ||
18 | /// config file path | 18 | /// config file path |
19 | #[arg(short, long)] | 19 | #[arg(short, long)] |
20 | config: Option<String>, | 20 | config: Option<String>, |
@@ -146,7 +146,7 @@ enum ListCommands { | |||
146 | #[tokio::main] | 146 | #[tokio::main] |
147 | async fn main() { | 147 | async fn main() { |
148 | let cli = Cli::parse(); | 148 | let cli = Cli::parse(); |
149 | 149 | ||
150 | let config = Cfg::init(cli.config).unwrap(); | 150 | let config = Cfg::init(cli.config).unwrap(); |
151 | println!("{:?}", config); | 151 | println!("{:?}", config); |
152 | 152 | ||
@@ -253,14 +253,12 @@ async fn main() { | |||
253 | Commands::Import { file, download } => { | 253 | Commands::Import { file, download } => { |
254 | let filestr: String = match file { | 254 | let filestr: String = match file { |
255 | Some(args) => args, | 255 | Some(args) => args, |
256 | None => | 256 | None => dirs::home_dir() |
257 | dirs::home_dir() | 257 | .unwrap() |
258 | .unwrap() | 258 | .join("mlexport.toml") |
259 | .join("mlexport.toml") | 259 | .into_os_string() |
260 | .into_os_string() | 260 | .into_string() |
261 | .into_string() | 261 | .unwrap(), |
262 | .unwrap() | ||
263 | , | ||
264 | }; | 262 | }; |
265 | 263 | ||
266 | import(config, filestr, download).await | 264 | import(config, filestr, download).await |