diff options
Diffstat (limited to 'src/data')
-rw-r--r-- | src/data/gameversion.rs | 33 | ||||
-rw-r--r-- | src/data/list.rs | 4 | ||||
-rw-r--r-- | src/data/modloader.rs | 14 | ||||
-rw-r--r-- | src/data/projectinfo.rs (renamed from src/data/project.rs) | 0 |
4 files changed, 20 insertions, 31 deletions
diff --git a/src/data/gameversion.rs b/src/data/gameversion.rs index 3868502..1bda755 100644 --- a/src/data/gameversion.rs +++ b/src/data/gameversion.rs | |||
@@ -5,11 +5,15 @@ use std::{ | |||
5 | }; | 5 | }; |
6 | 6 | ||
7 | use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; | 7 | use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; |
8 | use error::{EType, MLErr, MLE}; | 8 | use errors::MLE; |
9 | use indicatif::{ProgressBar, ProgressStyle}; | 9 | use indicatif::{ProgressBar, ProgressStyle}; |
10 | use serde::{Deserialize, Serialize}; | 10 | use serde::{Deserialize, Serialize}; |
11 | 11 | ||
12 | use crate::{apis, error, STYLE_MESSAGE}; | 12 | use crate::{ |
13 | apis, | ||
14 | errors::{self, Error}, | ||
15 | STYLE_MESSAGE, | ||
16 | }; | ||
13 | 17 | ||
14 | #[derive(Debug, Clone, Deserialize, Serialize)] | 18 | #[derive(Debug, Clone, Deserialize, Serialize)] |
15 | pub enum VersionLevel { | 19 | pub enum VersionLevel { |
@@ -25,15 +29,11 @@ pub enum VersionLevel { | |||
25 | /// # Errors | 29 | /// # Errors |
26 | pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { | 30 | pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { |
27 | let p = ProgressBar::new(1); | 31 | let p = ProgressBar::new(1); |
28 | p.set_style(ProgressStyle::with_template(STYLE_MESSAGE).map_err(|_| { | 32 | p.set_style(ProgressStyle::with_template(STYLE_MESSAGE)?); |
29 | MLErr::new(EType::LibIndicatif, "template error") | ||
30 | })?); | ||
31 | p.set_message("Update minecraft versions"); | 33 | p.set_message("Update minecraft versions"); |
32 | 34 | ||
33 | let creation_time = fs::metadata(path)?.created()?; | 35 | let creation_time = fs::metadata(path)?.created()?; |
34 | if !force | 36 | if !force && creation_time.elapsed()? < Duration::from_secs(60 * 60 * 24) { |
35 | && creation_time.elapsed().map_err(|_| MLErr::new(EType::LibIndicatif, "SystemTimeError"))? < Duration::from_secs(60 * 60 * 24) | ||
36 | { | ||
37 | return Ok(()); | 37 | return Ok(()); |
38 | } | 38 | } |
39 | 39 | ||
@@ -57,7 +57,7 @@ pub fn load_game_versions(path: &str) -> MLE<Vec<GameVersion>> { | |||
57 | } | 57 | } |
58 | 58 | ||
59 | impl VersionLevel { | 59 | impl VersionLevel { |
60 | pub fn from(str: &str) -> Self { | 60 | #[must_use] pub fn from(str: &str) -> Self { |
61 | match str { | 61 | match str { |
62 | "release" => VersionLevel::Release, | 62 | "release" => VersionLevel::Release, |
63 | "snapshot" => VersionLevel::Snapshot, | 63 | "snapshot" => VersionLevel::Snapshot, |
@@ -85,10 +85,7 @@ impl VersionLevel { | |||
85 | { | 85 | { |
86 | Ok(release.version) | 86 | Ok(release.version) |
87 | } else { | 87 | } else { |
88 | Err(MLErr::new( | 88 | Err(Error::MinecraftVersionNotFound) |
89 | EType::Other, | ||
90 | "no minecraft release version found", | ||
91 | )) | ||
92 | } | 89 | } |
93 | } | 90 | } |
94 | VersionLevel::Snapshot => { | 91 | VersionLevel::Snapshot => { |
@@ -97,20 +94,14 @@ impl VersionLevel { | |||
97 | { | 94 | { |
98 | Ok(snapshot.version) | 95 | Ok(snapshot.version) |
99 | } else { | 96 | } else { |
100 | Err(MLErr::new( | 97 | Err(Error::MinecraftVersionNotFound) |
101 | EType::Other, | ||
102 | "no minecraft snapshot version found", | ||
103 | )) | ||
104 | } | 98 | } |
105 | } | 99 | } |
106 | VersionLevel::Version(v) => { | 100 | VersionLevel::Version(v) => { |
107 | if versions.any(|ver| ver.version == v) { | 101 | if versions.any(|ver| ver.version == v) { |
108 | Ok(v) | 102 | Ok(v) |
109 | } else { | 103 | } else { |
110 | Err(MLErr::new( | 104 | Err(Error::MinecraftVersionNotFound) |
111 | EType::ConfigError, | ||
112 | "unknown minecraft version", | ||
113 | )) | ||
114 | } | 105 | } |
115 | } | 106 | } |
116 | } | 107 | } |
diff --git a/src/data/list.rs b/src/data/list.rs index 0045b7a..b886af1 100644 --- a/src/data/list.rs +++ b/src/data/list.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use crate::{config::Cfg, db::{config_get_current_list, lists_get}, error::MLE}; | 1 | use crate::{config::Cfg, db::{config_get_current_list, lists_get}, errors::MLE}; |
2 | 2 | ||
3 | use super::modloader::Modloader; | 3 | use super::modloader::Modloader; |
4 | 4 | ||
@@ -14,6 +14,6 @@ impl List { | |||
14 | /// # Errors | 14 | /// # Errors |
15 | pub fn get_current_list(config: &Cfg) -> MLE<List> { | 15 | pub fn get_current_list(config: &Cfg) -> MLE<List> { |
16 | let id = config_get_current_list(config)?; | 16 | let id = config_get_current_list(config)?; |
17 | lists_get(config, &id) | 17 | Ok(lists_get(config, &id)?) |
18 | } | 18 | } |
19 | } | 19 | } |
diff --git a/src/data/modloader.rs b/src/data/modloader.rs index 050213f..ef2611b 100644 --- a/src/data/modloader.rs +++ b/src/data/modloader.rs | |||
@@ -2,7 +2,7 @@ use std::fmt::Display; | |||
2 | 2 | ||
3 | use serde::{Deserialize, Serialize}; | 3 | use serde::{Deserialize, Serialize}; |
4 | 4 | ||
5 | use crate::error::{EType, MLErr, MLE}; | 5 | use crate::errors::ConversionError; |
6 | 6 | ||
7 | #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] | 7 | #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] |
8 | pub enum Modloader { | 8 | pub enum Modloader { |
@@ -14,16 +14,14 @@ pub enum Modloader { | |||
14 | Quilt, | 14 | Quilt, |
15 | } | 15 | } |
16 | 16 | ||
17 | impl Modloader { | 17 | impl TryFrom<&str> for Modloader { |
18 | /// # Errors | 18 | type Error = ConversionError; |
19 | pub fn from(string: &str) -> MLE<Modloader> { | 19 | fn try_from(value: &str) -> Result<Self, Self::Error> { |
20 | match string { | 20 | match value { |
21 | "forge" => Ok(Modloader::Forge), | 21 | "forge" => Ok(Modloader::Forge), |
22 | "fabric" => Ok(Modloader::Fabric), | 22 | "fabric" => Ok(Modloader::Fabric), |
23 | "quilt" => Ok(Modloader::Quilt), | 23 | "quilt" => Ok(Modloader::Quilt), |
24 | _ => { | 24 | _ => Err(ConversionError::Modloader(value.to_string())) |
25 | Err(MLErr::new(EType::ArgumentError, "UNKNOWN_MODLOADER")) | ||
26 | } | ||
27 | } | 25 | } |
28 | } | 26 | } |
29 | } | 27 | } |
diff --git a/src/data/project.rs b/src/data/projectinfo.rs index 9807867..9807867 100644 --- a/src/data/project.rs +++ b/src/data/projectinfo.rs | |||