diff --git a/.vscode/settings.json b/.vscode/settings.json index 5890744..c19fee0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,11 +1,15 @@ { "rust-analyzer.showUnlinkedFileNotification": false, "cSpell.words": [ + "парсинга", "Datapack", "Datapacks", "modrinth", + "mojang", "Purpur", - "tempfile" + "reqwest", + "tempfile", + "thiserror" ], "cSpell.language": "en,ru" } \ No newline at end of file diff --git a/src/config/downloader.rs b/src/config/downloader.rs index 1c2e82a..670d4a0 100644 --- a/src/config/downloader.rs +++ b/src/config/downloader.rs @@ -11,9 +11,9 @@ use crate::config::DownloadErrors; use super::{CompareHashError, ConfigErrors}; -pub struct Dowloader(); +pub struct Downloader(); -impl Dowloader { +impl Downloader { ///Get all info about for download core //We need to get sha* or md5 for checking it @@ -54,7 +54,7 @@ impl Dowloader { } } -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Debug)] pub enum ChooseHash { SHA1(String), SHA256(String), @@ -65,39 +65,39 @@ impl ChooseHash { async fn calculate_hash(self, mut reader: impl tokio::io::AsyncRead + Unpin) -> Result { match self { ChooseHash::SHA1(_) => { - let mut hasher = ::new(); + let mut hashed = ::new(); let mut buffer = [0; 4096]; while let Ok(n) = reader.read(&mut buffer).await { if n == 0 { break; } - hasher.update(&buffer[..n]); + hashed.update(&buffer[..n]); } - let result = hasher.finalize(); + let result = hashed.finalize(); Ok(ChooseHash::SHA1(format!("{:x}", result))) }, ChooseHash::SHA256(_) => { - let mut hasher = ::new(); + let mut hashed = ::new(); let mut buffer = [0; 4096]; while let Ok(n) = reader.read(&mut buffer).await { if n == 0 { break; } - hasher.update(&buffer[..n]); + hashed.update(&buffer[..n]); } - let result = hasher.finalize(); + let result = hashed.finalize(); Ok(ChooseHash::SHA256(format!("{:x}", result))) }, ChooseHash::MD5(_) => { - let mut hasher = ::new(); + let mut hashed = ::new(); let mut buffer = [0; 4096]; while let Ok(n) = reader.read(&mut buffer).await { if n == 0 { break; } - hasher.update(&buffer[..n]); + hashed.update(&buffer[..n]); } - let result = hasher.finalize(); + let result = hashed.finalize(); Ok(ChooseHash::MD5(format!("{:x}", result))) }, } diff --git a/src/config/errors.rs b/src/config/errors.rs index 2ac7769..0e13bd5 100644 --- a/src/config/errors.rs +++ b/src/config/errors.rs @@ -1,7 +1,7 @@ use thiserror::Error; #[derive(Error, Debug)] pub enum DownloadErrors { - #[error("Загрузка прекращенна потому что: {0}")] + #[error("Загрузка прекращена потому что: {0}")] DownloadCorrupt(String), } @@ -56,14 +56,13 @@ impl From for DownloadErrors { - #[derive(Error, Debug)] pub enum CompareHashError { - #[error("Конвертация Sha1 прозведена не успешно : {0}")] + #[error("Конвертация Sha1 проведена не успешно : {0}")] SHA1(std::io::Error), - #[error("Конвертация Sha256 прозведена не успешно : {0}")] + #[error("Конвертация Sha256 проведена не успешно : {0}")] SHA256(std::io::Error), - #[error("Конвертация Md5 прозведена не успешно : {0}")] + #[error("Конвертация Md5 проведена не успешно : {0}")] MD5(std::io::Error), } diff --git a/src/config/mod.rs b/src/config/mod.rs index 0e972f7..896797e 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -6,11 +6,10 @@ mod version; mod downloader; -use downloader::Dowloader; -use std::env; +use downloader::Downloader; use datapack::*; use errors::*; -use log::{info, trace}; +use log::info; use models::vanilla::Vanilla; use plugin::Plugin; use serde::{Deserialize, Serialize}; @@ -45,15 +44,14 @@ impl Config { info!("Инициализация конфигурационного файла..."); let config: Config = toml::from_str(&toml)?; - info!("Конфигурация успешно инициализированна."); + info!("Конфигурация успешно инициализирована."); Ok(config) } pub async fn download_all(self) -> Result<(), DownloadErrors> { //download core - let file = self.choose_core().await; - todo!() + self.choose_core().await } ///Function download core by info in [`Config`] @@ -62,7 +60,7 @@ impl Config { //Download vanilla Versions::Vanilla(ver, freeze) => { let (link, hash) = Vanilla::find(&*ver).await?; - Dowloader::download_core(freeze, link, hash).await + Downloader::download_core(freeze, link, hash).await } Versions::Purpur(_, _) => todo!(), diff --git a/src/config/models/vanilla.rs b/src/config/models/vanilla.rs index 142a936..e98e9ec 100644 --- a/src/config/models/vanilla.rs +++ b/src/config/models/vanilla.rs @@ -89,7 +89,7 @@ impl Vanilla { Ok((download_section.downloads.server.url, ChooseHash::SHA1(download_section.downloads.server.sha1))) } - ///Return `url` for get a json which contain link to donwload + ///Return `url` for get a json which contain link to download pub async fn find_version(mut version: &str) -> Result { const LINK: &str = "https://launchermeta.mojang.com/mc/game/version_manifest.json"; diff --git a/src/config/plugin.rs b/src/config/plugin.rs index f99aea3..9fd86cd 100644 --- a/src/config/plugin.rs +++ b/src/config/plugin.rs @@ -14,20 +14,20 @@ pub struct Plugin { } impl Plugin { - fn new( - modrinth: Option>, - spigot: Option>, - paper: Option>, - frozen: Option>, - ) -> Self { - Self { - modrinth, - spigot, - paper, - frozen, - } - } - pub fn default() -> Self { - Plugin::new(None, None, None, None) - } + // fn new( + // modrinth: Option>, + // spigot: Option>, + // paper: Option>, + // frozen: Option>, + // ) -> Self { + // Self { + // modrinth, + // spigot, + // paper, + // frozen, + // } + // } + // pub fn default() -> Self { + // Plugin::new(None, None, None, None) + // } }