Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Очеловечил правописание
Browse files Browse the repository at this point in the history
  • Loading branch information
TOwInOK committed Mar 3, 2024
1 parent 71821d2 commit ef23f11
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 42 deletions.
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"rust-analyzer.showUnlinkedFileNotification": false,
"cSpell.words": [
"парсинга",
"Datapack",
"Datapacks",
"modrinth",
"mojang",
"Purpur",
"tempfile"
"reqwest",
"tempfile",
"thiserror"
],
"cSpell.language": "en,ru"
}
24 changes: 12 additions & 12 deletions src/config/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand All @@ -65,39 +65,39 @@ impl ChooseHash {
async fn calculate_hash(self, mut reader: impl tokio::io::AsyncRead + Unpin) -> Result<Self, CompareHashError> {
match self {
ChooseHash::SHA1(_) => {
let mut hasher = <Sha1 as Digest1>::new();
let mut hashed = <Sha1 as Digest1>::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 = <Sha256 as Digest256>::new();
let mut hashed = <Sha256 as Digest256>::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 = <Md5 as md5::Digest>::new();
let mut hashed = <Md5 as md5::Digest>::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)))
},
}
Expand Down
9 changes: 4 additions & 5 deletions src/config/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use thiserror::Error;
#[derive(Error, Debug)]
pub enum DownloadErrors {
#[error("Загрузка прекращенна потому что: {0}")]
#[error("Загрузка прекращена потому что: {0}")]
DownloadCorrupt(String),
}

Expand Down Expand Up @@ -56,14 +56,13 @@ impl From<reqwest::Error> 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),
}

Expand Down
12 changes: 5 additions & 7 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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`]
Expand All @@ -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!(),
Expand Down
2 changes: 1 addition & 1 deletion src/config/models/vanilla.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, ConfigErrors> {
const LINK: &str = "https://launchermeta.mojang.com/mc/game/version_manifest.json";

Expand Down
32 changes: 16 additions & 16 deletions src/config/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ pub struct Plugin {
}

impl Plugin {
fn new(
modrinth: Option<Vec<String>>,
spigot: Option<Vec<String>>,
paper: Option<Vec<String>>,
frozen: Option<Vec<String>>,
) -> Self {
Self {
modrinth,
spigot,
paper,
frozen,
}
}
pub fn default() -> Self {
Plugin::new(None, None, None, None)
}
// fn new(
// modrinth: Option<Vec<String>>,
// spigot: Option<Vec<String>>,
// paper: Option<Vec<String>>,
// frozen: Option<Vec<String>>,
// ) -> Self {
// Self {
// modrinth,
// spigot,
// paper,
// frozen,
// }
// }
// pub fn default() -> Self {
// Plugin::new(None, None, None, None)
// }
}

0 comments on commit ef23f11

Please sign in to comment.