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

Commit

Permalink
Добавлено скачивание всех плагинов в Config
Browse files Browse the repository at this point in the history
Учитывается предварительная проверка на наличие в Lock
  • Loading branch information
TOwInOK committed Apr 29, 2024
1 parent 1aaee0f commit 0402710
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 50 deletions.
97 changes: 97 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
async-trait = "0.1.80"
bytes = "1.6.0"
md-5 = "0.10.6"
pretty_env_logger = "0.5.0"
reqwest = { version = "0.12.4", features = ["json"] }
serde = { version = "1.0.199", features = ["derive"] }
serde_json = "1.0.116"
Expand Down
Binary file added plugins/chunky.jar
Binary file not shown.
Binary file added plugins/simple-voice-chat.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ source = "modrinth"
channel = "release"
freeze = false
force_update = false

[additions]
config_plugins_from = "GitHub.link"
key = "GitHub.key"
17 changes: 10 additions & 7 deletions src/lock/ext.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
use serde::{Deserialize, Serialize};

use crate::settings::extensions::plugin::Plugin;

#[derive(Debug, PartialEq, Serialize, Deserialize, Default)]
pub struct ExtensionMeta {
version: Option<String>,
path: String,
}
impl ExtensionMeta {
fn from_plugin(value: Plugin, path: &str) -> Self {
Self {
version: value.version().cloned(),
path: path.to_owned(),
}
pub fn new(version: Option<String>, path: String) -> Self {
Self { version, path }
}

pub fn version(&self) -> Option<&String> {
self.version.as_ref()
}

pub fn path(&self) -> &str {
&self.path
}
}
18 changes: 17 additions & 1 deletion src/lock/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod core;
mod ext;
pub mod ext;

use serde::{Deserialize, Serialize};

Expand All @@ -21,6 +21,22 @@ impl Lock {
fn update_core(&mut self, core: Core) {
self.core = core.into();
}

pub fn core(&self) -> &CoreMeta {
&self.core
}

pub fn plugins(&self) -> &HashMap<String, ExtensionMeta> {
&self.plugins
}

pub fn core_mut(&mut self) -> &mut CoreMeta {
&mut self.core
}

pub fn plugins_mut(&mut self) -> &mut HashMap<String, ExtensionMeta> {
&mut self.plugins
}
}

impl Save for Lock {
Expand Down
40 changes: 21 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,33 @@ pub mod settings;
pub mod tr;

use crate::errors::error::Result;
use crate::lock::Lock;
use lock::Lock;
use settings::Settings;
use std::sync::Arc;
use tokio::sync::Mutex;
use tr::{load::Load, save::Save};

#[tokio::main]
async fn main() -> Result<()> {
// let lock = Lock::default();
pretty_env_logger::init();
// let mut query = Query::default();

// for (name, plugin) in settings.plugins().items().iter() {
// let game_version = settings.core().version();
// let a = plugin.get_link(name, game_version).await?;
// query.query_mut().insert(name.to_string(), a.into());
// }
// let settings = Arc::new(Mutex::new(Settings::default()));
// let lock = Arc::new(Mutex::new(Lock::default()));
// let plugins = Plugins::new(path, items);
// settings.get_mut().plugins_mut()
// lock.lock().await.save().await?;
// settings.lock().await.save().await?;

let load_settings = Settings::load().await?;
println!("{:#?}", load_settings);
load_settings.save().await?;
// let game_version = settings.core().version();
// let a = plugin.get_link(name, game_version).await?;
// query.query_mut().insert(name.to_string(), a.into());
// }
// let settings = Arc::new(Mutex::new(Settings::default()));
// let lock = Arc::new(Mutex::new(Lock::default()));
// let plugins = Plugins::new(path, items);
// settings.get_mut().plugins_mut()
// lock.lock().await.save().await?;
// settings.lock().await.save().await?;

let mut lock = Lock::load().await?;
let settings = Settings::load().await?;
// let a = Additions::new(Some("GitHub.link".to_string()), Some("GitHub.key".to_string()));
// settings.set_additions(Some(a));
if let Some(plugins) = settings.plugins() {
plugins.download_all(settings.core().version(), &mut lock).await?;
}
Ok(())
}
9 changes: 7 additions & 2 deletions src/settings/additions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use serde::{Deserialize, Serialize};


#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
pub struct Additions {
// git link
Expand All @@ -9,4 +8,10 @@ pub struct Additions {
// git key
#[serde(default)]
key: Option<String>,
}
}

impl Additions {
pub fn new(config_plugins_from: Option<String>, key: Option<String>) -> Self {
Self { config_plugins_from, key }
}
}
2 changes: 1 addition & 1 deletion src/settings/extensions/mods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ use serde::{Deserialize, Serialize};
use super::mode::Mode;

#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
pub struct Mods (HashMap<String, Mode>);
pub struct Mods(HashMap<String, Mode>);
12 changes: 12 additions & 0 deletions src/settings/extensions/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use serde::{Deserialize, Serialize};

use crate::errors::error::Result;
use crate::lock::ext::ExtensionMeta;
use crate::models::extensions::modrinth::ModrinthData;
use crate::tr::hash::ChooseHash;
use crate::tr::model::extension::ModelExtensions;
Expand Down Expand Up @@ -44,6 +45,7 @@ impl Plugin {
pub fn force_update(&self) -> bool {
self.force_update
}
/// Get link from models.
pub fn get_link<'a>(
&'a self,
name: &'a str,
Expand Down Expand Up @@ -78,3 +80,13 @@ pub enum Channels {
Beta,
Alpha,
}

impl Channels {
pub async fn get_str(&self) -> &'static str {
match self {
Channels::Release => "release",
Channels::Beta => "beta",
Channels::Alpha => "alpha",
}
}
}
Loading

0 comments on commit 0402710

Please sign in to comment.