diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -12,8 +12,13 @@ pub use apis::*; | |||
12 | use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; | 12 | use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; |
13 | pub use commands::*; | 13 | pub use commands::*; |
14 | use error::{ErrorType, MLError, MLE}; | 14 | use error::{ErrorType, MLError, MLE}; |
15 | use indicatif::{ProgressStyle, ProgressBar}; | ||
15 | use serde::{Deserialize, Serialize}; | 16 | use serde::{Deserialize, Serialize}; |
16 | 17 | ||
18 | pub static STYLE_BAR_POS: &str = "{spinner:.green}{wide_msg}{pos}/{len} [{bar:.green/lime}]"; | ||
19 | pub static STYLE_BAR_BYTE: &str = "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]"; | ||
20 | pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}"; | ||
21 | pub static STYLE_MESSAGE: &str = "{wide_msg}"; | ||
17 | pub static PROGRESS_CHARS: &str = "#>-"; | 22 | pub static PROGRESS_CHARS: &str = "#>-"; |
18 | 23 | ||
19 | #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | 24 | #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] |
@@ -59,15 +64,19 @@ pub enum VersionLevel { | |||
59 | /// Checks if update needed (time) | 64 | /// Checks if update needed (time) |
60 | /// if yes: get versions, update | 65 | /// if yes: get versions, update |
61 | pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { | 66 | pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { |
67 | let p = ProgressBar::new(1); | ||
68 | p.set_style(ProgressStyle::with_template(STYLE_MESSAGE).unwrap()); | ||
69 | p.set_message("Update minecraft versions"); | ||
70 | |||
62 | let creation_time = fs::metadata(path)?.created()?; | 71 | let creation_time = fs::metadata(path)?.created()?; |
63 | if !force && creation_time.elapsed().unwrap() < Duration::from_secs(60 * 60 * 24) { return Ok(()); } | 72 | if !force && creation_time.elapsed().unwrap() < Duration::from_secs(60 * 60 * 24) { return Ok(()); } |
64 | print!("Update minecraft versions"); | ||
65 | std::io::stdout().flush()?; | 73 | std::io::stdout().flush()?; |
66 | let versions = get_game_versions().await; | 74 | let versions = get_game_versions().await; |
67 | remove_file(path)?; | 75 | remove_file(path)?; |
68 | let mut file = File::create(path)?; | 76 | let mut file = File::create(path)?; |
69 | file.write_all(serde_json::to_string_pretty(&versions)?.as_bytes())?; | 77 | file.write_all(serde_json::to_string_pretty(&versions)?.as_bytes())?; |
70 | println!(" ✓"); | 78 | |
79 | p.finish_with_message("Updated minecraft versions"); | ||
71 | Ok(()) | 80 | Ok(()) |
72 | } | 81 | } |
73 | 82 | ||