This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Сделана основа для скачивания файлов.
- Loading branch information
Showing
11 changed files
with
335 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"rust-analyzer.showUnlinkedFileNotification": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use serde::{Serialize, Deserialize}; | ||
|
||
///Lists of Datapacks | ||
#[derive(Deserialize, Serialize, Debug)] | ||
pub struct Datapack { | ||
//list to download from https://modrinth.com/ | ||
modrinth: Option<Vec<String>>, | ||
//list to download from https://www.spigotmc.org/ | ||
spigot: Option<Vec<String>>, | ||
//list to download from https://hangar.papermc.io/ | ||
paper: Option<Vec<String>>, | ||
//List of plugins to stop updating | ||
frozen: Option<Vec<String>>, | ||
} | ||
|
||
impl Datapack { | ||
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 { | ||
Datapack::new(None, None, None, None) | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use thiserror::Error; | ||
#[derive(Error, Debug)] | ||
pub enum DownloadErrors { | ||
#[error("Загрузка прекращенна потому что: {0}")] | ||
DownloadCorrapt(String), | ||
|
||
} | ||
|
||
|
||
#[derive(Error, Debug)] | ||
pub enum ConfigErrors { | ||
#[error("Загрузка файла не была успешна: {0}")] | ||
LoadCorrapt(String), | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
mod datapack; | ||
mod errors; | ||
mod plugin; | ||
mod version; | ||
mod model; | ||
|
||
|
||
use std::default; | ||
use log::{error, info}; | ||
use tokio::fs; | ||
use errors::*; | ||
use serde::{Serialize, Deserialize}; | ||
use version::Versions; | ||
use datapack::*; | ||
use plugin::Plugin; | ||
|
||
|
||
///Struct to load config from toml file. | ||
#[derive(Deserialize, Serialize, Debug)] | ||
pub struct Config { | ||
version: Versions, | ||
plugins: Option<Plugin>, | ||
datapacks: Option<Datapack>, | ||
} | ||
|
||
impl Config { | ||
fn new(version: Versions, plugins: Option<Plugin>, datapacks: Option<Datapack>) -> Self { | ||
Self { version, plugins, datapacks } | ||
} | ||
|
||
|
||
fn default() -> Self { | ||
Config::new(Versions::default(), None, None) | ||
} | ||
|
||
pub async fn load_config(path: String) -> Config { | ||
let toml = { | ||
info!("Загрузка конфигурационного файла..."); | ||
let result = fs::read_to_string(path).await; | ||
match result { | ||
Ok(content) => { | ||
info!("Файл успешно загружен."); | ||
content | ||
} | ||
Err(e) => { | ||
error!( | ||
"Ваш конфигурационный файл не был обнаружен, загружаю стандартные настройки.\nПричина ошибки: {e}" | ||
); | ||
return Config::default(); | ||
} | ||
} | ||
}; | ||
info!("Инициализация конфигурационного файла..."); | ||
let config: Config = match toml::from_str(&toml) { | ||
Ok(parsed_config) => { | ||
info!("Конфигурация успешно инициализированна."); | ||
parsed_config | ||
} | ||
Err(e) => { | ||
error!("Не удалось загрузить конфигурацию, загружаю стандартные настройки.\nПричина ошибки: {e}"); | ||
return Config::default(); | ||
} | ||
}; | ||
config | ||
} | ||
|
||
|
||
|
||
pub async fn download(config: Config) -> Result<(), DownloadErrors> { | ||
let file = config.download_core().await; | ||
todo!() | ||
} | ||
|
||
async fn download_plugins() -> Result<(), DownloadErrors> { | ||
todo!() | ||
} | ||
async fn download_mods() -> Result<(), DownloadErrors> { | ||
todo!() | ||
} | ||
async fn download_datapacks() -> Result<(), DownloadErrors> { | ||
todo!() | ||
} | ||
|
||
async fn download_core(self) -> Result<Option<()>, DownloadErrors> { | ||
match self.version { | ||
Versions::Purpur(ver, freez) => { | ||
if !freez { | ||
//We don't need to download | ||
return Ok(None) ; | ||
} | ||
//use if error | ||
Err(DownloadErrors::DownloadCorrapt("ff".to_string())) | ||
}, | ||
Versions::Paper(ver, freez) => todo!(), | ||
Versions::Spigot(ver, freez) => todo!(), | ||
Versions::Bucket(ver, freez) => todo!(), | ||
Versions::Vanila(ver, freez) => todo!(), | ||
} | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.