diff options
author | fxqnlr <[email protected]> | 2023-05-26 17:40:27 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2023-05-26 17:40:27 +0200 |
commit | 2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0 (patch) | |
tree | cc8f3522670245775e4be7ac2a1e2ad4fd818c8f /src/lib.rs | |
parent | d8554e30029bf43dccce72e982784cd01857b0c4 (diff) | |
download | modlist-2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0.tar modlist-2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0.tar.gz modlist-2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0.zip |
added full progress? cargo fmt
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 46 |
1 files changed, 30 insertions, 16 deletions
@@ -6,20 +6,26 @@ pub mod db; | |||
6 | pub mod error; | 6 | pub mod error; |
7 | pub mod files; | 7 | pub mod files; |
8 | 8 | ||
9 | use std::{fmt::Display, fs::{File, remove_file, self}, io::{Write, Read}, time::Duration}; | 9 | use std::{ |
10 | fmt::Display, | ||
11 | fs::{self, remove_file, File}, | ||
12 | io::{Read, Write}, | ||
13 | time::Duration, | ||
14 | }; | ||
10 | 15 | ||
11 | pub use apis::*; | ||
12 | use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; | 16 | use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; |
17 | pub use apis::*; | ||
13 | pub use commands::*; | 18 | pub use commands::*; |
14 | use error::{ErrorType, MLError, MLE}; | 19 | use error::{ErrorType, MLError, MLE}; |
15 | use indicatif::{ProgressStyle, ProgressBar}; | 20 | use indicatif::{ProgressBar, ProgressStyle}; |
16 | use serde::{Deserialize, Serialize}; | 21 | use serde::{Deserialize, Serialize}; |
17 | 22 | ||
18 | pub static STYLE_BAR_BYTE: &str = "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]"; | 23 | pub static STYLE_BAR_BYTE: &str = |
24 | "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]"; | ||
19 | pub static STYLE_BAR_POS: &str = " {wide_msg}{pos}/{len} [{bar:.green/lime}]"; | 25 | pub static STYLE_BAR_POS: &str = " {wide_msg}{pos}/{len} [{bar:.green/lime}]"; |
20 | pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}"; | 26 | pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}"; |
21 | pub static STYLE_OPERATION: &str = " {wide_msg}"; | 27 | pub static STYLE_OPERATION: &str = " {wide_msg}"; |
22 | pub static STYLE_MESSAGE: &str = "{wide_msg}"; | 28 | pub static STYLE_MESSAGE: &str = "{wide_msg}"; |
23 | pub static PROGRESS_CHARS: &str = "#>-"; | 29 | pub static PROGRESS_CHARS: &str = "#>-"; |
24 | 30 | ||
25 | #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | 31 | #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] |
@@ -59,7 +65,7 @@ pub enum VersionLevel { | |||
59 | Release, | 65 | Release, |
60 | #[serde(rename(serialize = "snapshot", deserialize = "snapshot"))] | 66 | #[serde(rename(serialize = "snapshot", deserialize = "snapshot"))] |
61 | Snapshot, | 67 | Snapshot, |
62 | Version(String) | 68 | Version(String), |
63 | } | 69 | } |
64 | 70 | ||
65 | /// Checks if update needed (time) | 71 | /// Checks if update needed (time) |
@@ -70,7 +76,9 @@ pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { | |||
70 | p.set_message("Update minecraft versions"); | 76 | p.set_message("Update minecraft versions"); |
71 | 77 | ||
72 | let creation_time = fs::metadata(path)?.created()?; | 78 | let creation_time = fs::metadata(path)?.created()?; |
73 | if !force && creation_time.elapsed().unwrap() < Duration::from_secs(60 * 60 * 24) { return Ok(()); } | 79 | if !force && creation_time.elapsed().unwrap() < Duration::from_secs(60 * 60 * 24) { |
80 | return Ok(()); | ||
81 | } | ||
74 | 82 | ||
75 | let versions = get_game_versions().await; | 83 | let versions = get_game_versions().await; |
76 | remove_file(path)?; | 84 | remove_file(path)?; |
@@ -91,7 +99,6 @@ pub fn load_game_versions(path: &str) -> MLE<Vec<GameVersion>> { | |||
91 | } | 99 | } |
92 | 100 | ||
93 | impl VersionLevel { | 101 | impl VersionLevel { |
94 | |||
95 | pub fn from(str: &str) -> Self { | 102 | pub fn from(str: &str) -> Self { |
96 | match str { | 103 | match str { |
97 | "release" => VersionLevel::Release, | 104 | "release" => VersionLevel::Release, |
@@ -107,22 +114,29 @@ impl VersionLevel { | |||
107 | 114 | ||
108 | match self { | 115 | match self { |
109 | VersionLevel::Release => { | 116 | VersionLevel::Release => { |
110 | let release = versions.find(|ver| ver.version_type == GameVersionType::release).unwrap(); | 117 | let release = versions |
118 | .find(|ver| ver.version_type == GameVersionType::release) | ||
119 | .unwrap(); | ||
111 | println!("{:?}", release); | 120 | println!("{:?}", release); |
112 | Ok(release.version) | 121 | Ok(release.version) |
113 | }, | 122 | } |
114 | VersionLevel::Snapshot => { | 123 | VersionLevel::Snapshot => { |
115 | let snapshot = versions.find(|ver| ver.version_type == GameVersionType::snapshot).unwrap(); | 124 | let snapshot = versions |
125 | .find(|ver| ver.version_type == GameVersionType::snapshot) | ||
126 | .unwrap(); | ||
116 | println!("{:?}", snapshot); | 127 | println!("{:?}", snapshot); |
117 | Ok(snapshot.version) | 128 | Ok(snapshot.version) |
118 | }, | 129 | } |
119 | VersionLevel::Version(v) => { | 130 | VersionLevel::Version(v) => { |
120 | if versions.any(|ver| ver.version == v) { | 131 | if versions.any(|ver| ver.version == v) { |
121 | Ok(v) | 132 | Ok(v) |
122 | } else { | 133 | } else { |
123 | Err(MLError::new(ErrorType::ConfigError, "unknown minecraft version")) | 134 | Err(MLError::new( |
135 | ErrorType::ConfigError, | ||
136 | "unknown minecraft version", | ||
137 | )) | ||
124 | } | 138 | } |
125 | }, | 139 | } |
126 | } | 140 | } |
127 | } | 141 | } |
128 | } | 142 | } |