summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-05-25 21:06:40 +0200
committerfxqnlr <[email protected]>2023-05-25 21:06:40 +0200
commit7f1a262999d7a8b7f12a97daf4b6722638dc62a1 (patch)
treec030a952891fba2f64427adad1113efc567ae54d /src/lib.rs
parent48393b209396db9ddd44251b2bb445d3ad7533fb (diff)
downloadmodlist-7f1a262999d7a8b7f12a97daf4b6722638dc62a1.tar
modlist-7f1a262999d7a8b7f12a97daf4b6722638dc62a1.tar.gz
modlist-7f1a262999d7a8b7f12a97daf4b6722638dc62a1.zip
more progress instead of print, more references
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 69cc650..a7a34ac 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -12,8 +12,13 @@ pub use apis::*;
12use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; 12use apis::modrinth::{get_game_versions, GameVersion, GameVersionType};
13pub use commands::*; 13pub use commands::*;
14use error::{ErrorType, MLError, MLE}; 14use error::{ErrorType, MLError, MLE};
15use indicatif::{ProgressStyle, ProgressBar};
15use serde::{Deserialize, Serialize}; 16use serde::{Deserialize, Serialize};
16 17
18pub static STYLE_BAR_POS: &str = "{spinner:.green}{wide_msg}{pos}/{len} [{bar:.green/lime}]";
19pub static STYLE_BAR_BYTE: &str = "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]";
20pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}";
21pub static STYLE_MESSAGE: &str = "{wide_msg}";
17pub static PROGRESS_CHARS: &str = "#>-"; 22pub 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
61pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { 66pub 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