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

Commit

Permalink
Gave up the idea of dependencies. #2
Browse files Browse the repository at this point in the history
Now the user decides whether to add them or not.
Now it is possible to download plugins.
In the future plugins will simply become dependencies with an affiliation type.

Отказался от идеи зависимостей.
Теперь пользователь решает, добавлять их или нет.
Теперь можно скачивать плагины.
В будущем плагины просто станут зависимостями с типом принадлежности.

Finalized the work for the cores. #3

Доделана работа для ядер.
  • Loading branch information
TOwInOK committed Mar 29, 2024
1 parent 5c3ce24 commit eb9b152
Show file tree
Hide file tree
Showing 19 changed files with 356 additions and 127 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/core
/core/*
/core/*
/plugins/
24 changes: 24 additions & 0 deletions config.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,27 @@
name = "Paper"
version = "1.20.4"
build = "462"

[[metaData]]

[metaData.Plugin]
name = "simple-voice-chat"
version = "latest"

[[metaData]]

[metaData.Plugin]
name = "chunky"
version = "latest"

[[metaData]]

[metaData.Plugin]
name = "terra"
version = "latest"

[[metaData]]

[metaData.Plugin]
name = "itemswapper"
version = "latest"
24 changes: 14 additions & 10 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
force_update = false

[plugins]
[plugins.simple_voice_chat2]
version = "ail5iPUK"
[plugins.simple-voice-chat]
[plugins.chunky]
[plugins.itemswapper]
[plugins.terra]
channel = "beta"
freeze = false
update = false
# version = "ail5iPUK"
# channel = "beta"
# freeze = false
# update = false

[plugins.cooler2]
source = "hangar"
version = "ail5iPUK"
channel = "beta"
freeze = false
update = true
# [plugins.cooler2]
# source = "hangar"
# version = "ail5iPUK"
# channel = "beta"
# freeze = false
# update = true

[additions]
configPluguinsFrom = "[email protected]:TOwInOK/test.git"
Expand Down
12 changes: 11 additions & 1 deletion src/config/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@ pub enum Sources {
#[serde(rename_all = "lowercase")]
pub enum Channels {
#[default]
Stable,
Release,
Beta,
Alpha,
}

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

impl Plugin {
pub async fn freeze(&self) -> bool {
info!("Check freeze and force_update");
Expand Down
17 changes: 17 additions & 0 deletions src/config/versions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::ops::Deref;

use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[derive(Debug, Default, PartialEq, Clone, Eq)]
pub enum Versions {
Expand All @@ -6,6 +8,21 @@ pub enum Versions {
Latest,
}

impl Versions {
pub async fn is_latest(&self) -> bool {
match self {
Versions::Version(_) => false,
Versions::Latest => true,
}
}
pub async fn get_version(&self) -> &str {
match self {
Versions::Version(e) => e.deref(),
Versions::Latest => "latest",
}
}
}

impl<'de> Deserialize<'de> for Versions {
fn deserialize<D>(deserializer: D) -> Result<Versions, D::Error>
where
Expand Down
112 changes: 112 additions & 0 deletions src/downloader/core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
use log::{debug, info};

use crate::config::core::{Core, Provider};
use crate::downloader::models::cores::folia::Folia;
use crate::downloader::models::cores::paper::Paper;
use crate::downloader::models::cores::purpur::Purpur;
use crate::downloader::models::cores::vanilla::Vanilla;
use crate::downloader::models::cores::velocity::Velocity;
use crate::downloader::models::cores::waterfall::Waterfall;
use crate::downloader::models::model::ModelCore;
use crate::errors::error::DownloadErrors;
use crate::lock::lock::{ExistState, Lock, Meta, MetaData};

use super::hash::ChooseHash;


pub trait CoreDownloader {
///Check core and add it into list for download.
async fn get_core_link(core: &mut Core) -> Result<(String, ChooseHash), DownloadErrors> {
info!("Start to match provider of core");
match core.provider {
Provider::Vanilla => Vanilla::get_link(core).await,
Provider::Paper => Paper::get_link(core).await,
Provider::Folia => Folia::get_link(core).await,
Provider::Purpur => Purpur::get_link(core).await,
Provider::Fabric => todo!(),
Provider::Forge => todo!(),
Provider::NeoForge => todo!(),
Provider::Waterfall => Waterfall::get_link(core).await,
Provider::Velocity => Velocity::get_link(core).await,
}
}

/// Make reqwest to check version and download core.
async fn core_reqwest(core: &mut Core, lock: &mut Lock) -> Result<(), DownloadErrors> {
//Find version to download
let (link, hash) = Self::get_core_link(core).await?;
let core_name = core.provider.get_name().await.as_str();
debug!("Find {} link: {}, hash: {}", core_name, &link, &hash);
info!("Start to download {}!", core_name);
//Need to update or download?
match lock
.exist(&Meta::Core(MetaData {
name: core_name.to_string(),
version: core.version,
build: core.build.into(),
dependencies: None,
}))
.await
{
ExistState::Exist => {
if core.freeze().await {
return Ok(());
}
Self::force_update(self, core_name, link, hash).await
}
ExistState::DifferentVersion | ExistState::DifferentBuild => {
if core.freeze().await {
return Ok(());
}
info!("Core have different or build version, Download!");
Self::download_core(core_name, link, hash).await
}
ExistState::None => {
info!("No one core find, Download!");
Self::download_core(core_name, link, hash).await
}
}
}

async fn force_update(
lock: &mut Lock,
core: &Core,
link: String,
hash: ChooseHash,
) -> Result<(), DownloadErrors> {
if core.force_update {
core.force_update = false;
info!("Force update core!");
return Self::download_core(core.provider.get_name(), link, hash).await;
}
info!("Core doesn't need to download");
Ok(())
}
/// download core
async fn download_core(
lock: &mut Lock,
name: &str,
link: String,
hash: ChooseHash,
) -> Result<(), DownloadErrors> {
//delete all cores from meta and dir
lock
.delete_core(&self.config.additions.path_to_core).await?;
//download
get_file(link, hash, &self.config.additions.path_to_core, name).await?;

//get meta data
let meta = Meta::Core(MetaData::new(
name.to_string(),
self.config.core.version.clone(),
self.config.core.build.clone().into(),
None,
));
//push to lock
self.lock.add(meta).await;
//save lock
self.lock.save(&self.config.additions.path_to_lock).await?;
Ok(())
}

}
Loading

0 comments on commit eb9b152

Please sign in to comment.