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 20, 2024
1 parent 27a7dad commit 293b196
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 151 deletions.
54 changes: 54 additions & 0 deletions Sample of config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#Sample of config

#freez - добавлять ли на проверку/скачивание если object присутствует.

# Секция ядра
[core]
# Выбери один из вариантов: vanila, spigot, bucket, paper, purpur
provider = "paper"
# Версия сервера (например, "1.14.4" или специальный код)
version = "1.14.4"
# Замораживать ли объекты при наличии в системе
freeze = false
force_update = false

# Update - не требуется при загрузке, он нужен только когда freez = true, чтобы обновить на туже версию, либо принудительно обновить на самую последнюю, даже когда обновления нет.
# Секция плагинов
[plugins]
# Пример 1 - строчка
vc1 = {version = "ail5iPUK", chanel = "stable", freez = true, update = false}

# Пример 2 - строчка
cooler1 = {source = "Spigot", version = "ail5iPUK", chanel = "Beta", freez = false, update = false}

# Пример 3 - строчка
best_plugin_without_any_param1 = {}

# Пример 1 - секция
[plugins.simple_voice_chat2]
version = "ail5iPUK"
chanel = "Stable"
freez = false
update = false

# Пример 2 - секция
[plugins.cooler2]
source = "Spigot"
version = "ail5iPUK"
chanel = "Beta"
freez = false
update = true

# Пример 3 - секция
[plugins.best_plugin_without_any_param2]
#Дефолт:
#source = Modrith
#version = "Latest"
#chanel = "Stable"
#freez = false
#update = false

# Секция дополнений
[additions]
configPluguinsFrom = "[email protected]:TOwInOK/test.git"
key = "SUPEREKLy"
75 changes: 52 additions & 23 deletions config.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,54 @@
#Example of config file

[version]
#which version you want? [Vanil;a, Buckit, Spigot, Paper, Purpur]
core = "Vanilla"
#First: any version if they have.
#Second: lock version. (stop update)
version = ["1.8.9", false]
#Example: version = ["1.20.1", false]
#We are loading version 1.20.1 with the tag FFFw2f
#Because the flag is "false", we no longer update this version to newer versions of same verion.
#Sample of config

#freez - добавлять ли на проверку/скачивание если object присутствует.

# Секция ядра
[core]
# Выбери один из вариантов: vanila, spigot, bucket, paper, purpur
provider = "Paper"
# Версия сервера (например, "1.14.4" или специальный код)
version = "1.14.4"
# Замораживать ли объекты при наличии в системе
freeze = false
force_update = false

# Update - не требуется при загрузке, он нужен только когда freez = true, чтобы обновить на туже версию, либо принудительно обновить на самую последнюю, даже когда обновления нет.
# Секция плагинов
[plugins]
#load plugins from Modrinth
modrinth = [
"Chunky",
"Simple Voice Chat",
]
#load plugins from SpigotMC
spigot = []
#load plugins from PaperMC
paper = []

#list for lock of update | plugins
frozen = []
# Пример 1 - строчка
vc1 = {version = "ail5iPUK", chanel = "stable", freez = true, update = false}

# Пример 2 - строчка
cooler1 = {source = "Spigot", version = "ail5iPUK", chanel = "Beta", freez = false, update = false}

# Пример 3 - строчка
best_plugin_without_any_param1 = {}

# Пример 1 - секция
[plugins.simple_voice_chat2]
version = "ail5iPUK"
chanel = "Stable"
freez = false
update = false

# Пример 2 - секция
[plugins.cooler2]
source = "Spigot"
version = "ail5iPUK"
chanel = "Beta"
freez = false
update = true

# Пример 3 - секция
[plugins.best_plugin_without_any_param2]
#Дефолт:
#source = Modrith
#version = "Latest"
#chanel = "Stable"
#freez = false
#update = false

# Секция дополнений
[additions]
configPluguinsFrom = "[email protected]:TOwInOK/test.git"
key = "SUPEREKLy"
15 changes: 15 additions & 0 deletions src/config/additions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug)]
pub struct Additions {
// git link
#[serde(rename = "configPluguinsFrom")]
config_plugins_from: String,
// git key
key: String,
}

impl Default for Additions {
fn default() -> Self {
Self { config_plugins_from: Default::default(), key: Default::default() }
}
}
41 changes: 41 additions & 0 deletions src/config/core/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::config::Versions;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug)]
pub struct Core {
// Ядро
#[serde(default)]
provider: Provider,
// Версия ядра
#[serde(default)]
version: Versions,
// Приостановить обновление
#[serde(default)]
freeze: bool,
// Нужно обновить
#[serde(default)]
force_update: bool,
}

impl Default for Core {
fn default() -> Self {
Self { provider: Default::default(), version: Default::default(), freeze: Default::default(), force_update: Default::default() }
}
}

#[derive(Deserialize, Serialize, Debug)]
enum Provider {
Vanilla,
Bucket,
Spigot,
Paper,
Purpur,
Fabric,
Forge,
NeoForge,
}

impl Default for Provider {
fn default() -> Self {
Self::Vanilla
}
}
14 changes: 0 additions & 14 deletions src/config/datapack.rs

This file was deleted.

106 changes: 54 additions & 52 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
mod datapack;
mod downloader;
mod errors;
mod models;
mod plugin;
mod version;
mod plugins;
mod versions;
mod core;
mod additions;

use datapack::*;
use downloader::Downloader;
use additions::Additions;
use std::collections::HashMap;
use core::Core;
use versions::Versions;
use errors::*;
use log::info;
use models::vanilla::Vanilla;
use plugin::Plugin;
use log::{info, warn};
use serde::{Deserialize, Serialize};
use tokio::fs;
use version::Versions;

///Struct to load config from toml file.
use plugins::Plugin;
/// Структура для инициализации конфигурации
///
#[derive(Deserialize, Serialize, Debug)]
pub struct Config {
version: Versions,
plugins: Option<Plugin>,
datapacks: Option<Datapack>,
/// Minecraft core
#[serde(default)]
core: Core,
/// Лист плагинов
/// [name]:[Plugin]
#[serde(default)]
plugins: HashMap<String, Plugin>,
/// Additions for git or keys
additions: Option<Additions>,
}

impl Config {
fn new(version: Versions, plugins: Option<Plugin>, datapacks: Option<Datapack>) -> Self {
Self {
version,
plugins,
datapacks,
}
impl Default for Config {
fn default() -> Self {
warn!("Не обнаружен конфигурационный файл!\nЗагрузка стандартной конфигурации!");
Self { core: Default::default(), plugins: Default::default(), additions: None }
}
}

pub fn default() -> Self {
Config::new(Versions::default(), None, None)
}

impl Config {
pub async fn load_config(path: String) -> Result<Config, ConfigErrors> {
info!("Загрузка конфигурационного файла...");
let toml = fs::read_to_string(&path).await?;
Expand All @@ -48,33 +50,33 @@ impl Config {
Ok(config)
}

pub async fn download_all(self) -> Result<(), DownloadErrors> {
//download core
self.choose_core().await?;
self.choose_plugin().await
}
// pub async fn download_all(self) -> Result<(), DownloadErrors> {
// //download core
// self.choose_core().await?;
// self.choose_plugin().await
// }

///Function download core by info in [`Config`]
async fn choose_core(&self) -> Result<(), DownloadErrors> {
match &self.version {
//Download vanilla
Versions::Vanilla(ver, freeze) => {
let (link, hash) = Vanilla::find(&**ver).await?;
Downloader::download_core(*freeze, link, hash).await
}
Versions::Purpur(_, _) => todo!(),
Versions::Paper(_, _) => todo!(),
Versions::Spigot(_, _) => todo!(),
Versions::Bucket(_, _) => todo!(),
}
}
async fn choose_plugin(&self) -> Result<(), DownloadErrors> {
if let Some(plugins) = &self.plugins {
// ///Function download core by info in [`Config`]
// async fn choose_core(&self) -> Result<(), DownloadErrors> {
// match &self.version {
// //Download vanilla
// Versions::Vanilla(ver, freeze) => {
// let (link, hash) = Vanilla::find(&**ver).await?;
// Downloader::download_core(*freeze, link, hash).await
// }
// Versions::Purpur(_, _) => todo!(),
// Versions::Paper(_, _) => todo!(),
// Versions::Spigot(_, _) => todo!(),
// Versions::Bucket(_, _) => todo!(),
// }
// }
// async fn choose_plugin(&self) -> Result<(), DownloadErrors> {
// if let Some(plugins) = &self.plugins {

todo!()
} else {
info!("Нет плагинов для скачивания");
Ok(())
}
}
// todo!()
// } else {
// info!("Нет плагинов для скачивания");
// Ok(())
// }
// }
}
33 changes: 0 additions & 33 deletions src/config/plugin.rs

This file was deleted.

Loading

0 comments on commit 293b196

Please sign in to comment.