From 2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Fri, 26 May 2023 17:40:27 +0200 Subject: added full progress? cargo fmt --- src/lib.rs | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 7287660..8196f1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,20 +6,26 @@ pub mod db; pub mod error; pub mod files; -use std::{fmt::Display, fs::{File, remove_file, self}, io::{Write, Read}, time::Duration}; +use std::{ + fmt::Display, + fs::{self, remove_file, File}, + io::{Read, Write}, + time::Duration, +}; -pub use apis::*; use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; +pub use apis::*; pub use commands::*; use error::{ErrorType, MLError, MLE}; -use indicatif::{ProgressStyle, ProgressBar}; +use indicatif::{ProgressBar, ProgressStyle}; use serde::{Deserialize, Serialize}; -pub static STYLE_BAR_BYTE: &str = "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]"; +pub static STYLE_BAR_BYTE: &str = + "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]"; pub static STYLE_BAR_POS: &str = " {wide_msg}{pos}/{len} [{bar:.green/lime}]"; -pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}"; -pub static STYLE_OPERATION: &str = " {wide_msg}"; -pub static STYLE_MESSAGE: &str = "{wide_msg}"; +pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}"; +pub static STYLE_OPERATION: &str = " {wide_msg}"; +pub static STYLE_MESSAGE: &str = "{wide_msg}"; pub static PROGRESS_CHARS: &str = "#>-"; #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] @@ -59,7 +65,7 @@ pub enum VersionLevel { Release, #[serde(rename(serialize = "snapshot", deserialize = "snapshot"))] Snapshot, - Version(String) + Version(String), } /// Checks if update needed (time) @@ -70,7 +76,9 @@ pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { p.set_message("Update minecraft versions"); let creation_time = fs::metadata(path)?.created()?; - if !force && creation_time.elapsed().unwrap() < Duration::from_secs(60 * 60 * 24) { return Ok(()); } + if !force && creation_time.elapsed().unwrap() < Duration::from_secs(60 * 60 * 24) { + return Ok(()); + } let versions = get_game_versions().await; remove_file(path)?; @@ -91,7 +99,6 @@ pub fn load_game_versions(path: &str) -> MLE> { } impl VersionLevel { - pub fn from(str: &str) -> Self { match str { "release" => VersionLevel::Release, @@ -107,22 +114,29 @@ impl VersionLevel { match self { VersionLevel::Release => { - let release = versions.find(|ver| ver.version_type == GameVersionType::release).unwrap(); + let release = versions + .find(|ver| ver.version_type == GameVersionType::release) + .unwrap(); println!("{:?}", release); Ok(release.version) - }, + } VersionLevel::Snapshot => { - let snapshot = versions.find(|ver| ver.version_type == GameVersionType::snapshot).unwrap(); + let snapshot = versions + .find(|ver| ver.version_type == GameVersionType::snapshot) + .unwrap(); println!("{:?}", snapshot); Ok(snapshot.version) - }, + } VersionLevel::Version(v) => { if versions.any(|ver| ver.version == v) { Ok(v) } else { - Err(MLError::new(ErrorType::ConfigError, "unknown minecraft version")) + Err(MLError::new( + ErrorType::ConfigError, + "unknown minecraft version", + )) } - }, + } } } } -- cgit v1.2.3