diff --git a/Sample of config.toml b/Sample of config.toml new file mode 100644 index 0000000..fa48672 --- /dev/null +++ b/Sample of config.toml @@ -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 = "git@github.com:TOwInOK/test.git" + key = "SUPEREKLy" diff --git a/config.toml b/config.toml index 566dc40..8cf42d5 100644 --- a/config.toml +++ b/config.toml @@ -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 = [] \ No newline at end of file + # Пример 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 = "git@github.com:TOwInOK/test.git" +key = "SUPEREKLy" diff --git a/src/config/additions.rs b/src/config/additions.rs new file mode 100644 index 0000000..3ee18c7 --- /dev/null +++ b/src/config/additions.rs @@ -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() } + } +} \ No newline at end of file diff --git a/src/config/core/mod.rs b/src/config/core/mod.rs new file mode 100644 index 0000000..b6dbd40 --- /dev/null +++ b/src/config/core/mod.rs @@ -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 + } +} diff --git a/src/config/datapack.rs b/src/config/datapack.rs deleted file mode 100644 index 55febf6..0000000 --- a/src/config/datapack.rs +++ /dev/null @@ -1,14 +0,0 @@ -use serde::{Deserialize, Serialize}; - -///Lists of Datapacks -#[derive(Deserialize, Serialize, Debug)] -pub struct Datapack { - //list to download from https://modrinth.com/ - modrinth: Option>, - //list to download from https://www.spigotmc.org/ - spigot: Option>, - //list to download from https://hangar.papermc.io/ - paper: Option>, - //List of plugins to stop updating - frozen: Option>, -} \ No newline at end of file diff --git a/src/config/mod.rs b/src/config/mod.rs index d1172a1..d854177 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -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, - datapacks: Option, + /// Minecraft core + #[serde(default)] + core: Core, + /// Лист плагинов + /// [name]:[Plugin] + #[serde(default)] + plugins: HashMap, + /// Additions for git or keys + additions: Option, } -impl Config { - fn new(version: Versions, plugins: Option, datapacks: Option) -> 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 { info!("Загрузка конфигурационного файла..."); let toml = fs::read_to_string(&path).await?; @@ -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(()) + // } + // } } \ No newline at end of file diff --git a/src/config/plugin.rs b/src/config/plugin.rs deleted file mode 100644 index 2f7b453..0000000 --- a/src/config/plugin.rs +++ /dev/null @@ -1,33 +0,0 @@ -use serde::{Deserialize, Serialize}; - -///Lists of plugins -#[derive(Deserialize, Serialize, Debug)] -pub struct Plugin { - //list to download from https://modrinth.com/ - pub modrinth: Option>, - //list to download from https://www.spigotmc.org/ - pub spigot: Option>, - //list to download from https://hangar.papermc.io/ - pub paper: Option>, - //List of plugins to stop updating - pub frozen: Option>, -} - -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) - // } -} diff --git a/src/config/plugins/mod.rs b/src/config/plugins/mod.rs new file mode 100644 index 0000000..e5b5cb9 --- /dev/null +++ b/src/config/plugins/mod.rs @@ -0,0 +1,51 @@ +mod models; + +use serde::{Deserialize, Serialize}; +use crate::config::Versions; + +#[derive(Deserialize, Serialize, Debug)] +pub struct Plugin { + // Откуда качаем + #[serde(default)] + source: Sources, + // Версия + #[serde(default)] + version: Versions, + // Стабильная, Альфа, Бета + #[serde(default)] + channel: Channels, + // Приостановить обновление + #[serde(default)] + freeze: bool, + // Нужно обновить + #[serde(default)] + force_update: bool, +} + +#[derive(Deserialize, Serialize, Debug)] +enum Sources { + Bucket, + Spigot, + Hangar, + Modrinth, + CurseForge +} + +impl Default for Sources { + fn default() -> Self { + Self::Modrinth + } +} + +#[derive(Deserialize, Serialize, Debug)] +enum Channels { + Stable, + Beta, + Alpha, +} + +impl Default for Channels { + fn default() -> Self { + Self::Stable + } +} diff --git a/src/config/models/mod.rs b/src/config/plugins/models/mod.rs similarity index 100% rename from src/config/models/mod.rs rename to src/config/plugins/models/mod.rs diff --git a/src/config/models/modrinth.rs b/src/config/plugins/models/modrinth.rs similarity index 98% rename from src/config/models/modrinth.rs rename to src/config/plugins/models/modrinth.rs index 662587e..3579360 100644 --- a/src/config/models/modrinth.rs +++ b/src/config/plugins/models/modrinth.rs @@ -1,6 +1,5 @@ use std::collections::HashMap; -use md5::digest::typenum::Mod; use serde::Deserialize; use serde::Serialize; use serde_json::Value; diff --git a/src/config/models/vanilla.rs b/src/config/plugins/models/vanilla.rs similarity index 100% rename from src/config/models/vanilla.rs rename to src/config/plugins/models/vanilla.rs diff --git a/src/config/version.rs b/src/config/version.rs deleted file mode 100644 index e75e936..0000000 --- a/src/config/version.rs +++ /dev/null @@ -1,24 +0,0 @@ -use serde::{Deserialize, Serialize}; - -///Cores include version -///# Explanetion -/// -///#### Fist string is `version` -///version can be: `latest` and string-numbers like `"1.14.4"` -///#### Second value is `freez` -///when freez is true we don't update version like `"1.1.1" (#fdf2134)` to `"1.1.1" (#fdf2154)` -#[derive(Deserialize, Serialize, Debug)] -#[serde(tag = "core", content = "version")] -pub enum Versions { - Purpur(String, bool), - Paper(String, bool), - Spigot(String, bool), - Bucket(String, bool), - Vanilla(String, bool), -} - -impl Default for Versions { - fn default() -> Self { - Versions::Vanilla("latest".to_string(), false) - } -} diff --git a/src/config/versions.rs b/src/config/versions.rs new file mode 100644 index 0000000..c4e64cf --- /dev/null +++ b/src/config/versions.rs @@ -0,0 +1,14 @@ +use serde::{Deserialize, Serialize}; +#[derive(Deserialize, Serialize, Debug)] +#[serde(untagged)] +pub enum Versions { + #[serde(rename = "Version")] + Version(String), + Latest, +} + +impl Default for Versions { + fn default() -> Self { + Versions::Latest + } +} diff --git a/src/main.rs b/src/main.rs index fda5ba8..c9ae6ba 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,8 +15,8 @@ async fn main() { Config::default() }); log::debug!("{:#?}", config); - match config.download_all().await { - Ok(_) => todo!(), - Err(_) => todo!(), - } + // match config.download_all().await { + // Ok(_) => todo!(), + // Err(_) => todo!(), + // } }