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.
Реализован file watcher Исправлено узкое горлышко в скачивании плагинов
- Loading branch information
Showing
16 changed files
with
580 additions
and
95 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,3 @@ version = "1.20.6" | |
[plugins.chunky] | ||
[plugins.nbtapi] | ||
[plugins.chunkyborder] | ||
[plugins.lifestealz] |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Require | ||
# Require | ||
[core] # just core, nothing here to change :) | ||
provider = "paper" # [vanilla, paper, folia, purpur, fabric, waterfall, velocity] | ||
version = "1.20.6" # Or Latest (latest -> get error) | ||
|
@@ -23,4 +23,5 @@ force_update = false # false || true => false by default | |
# Optional | ||
[additions] | ||
source = "[email protected]:Username/Super-Config.git" # Optional, require for key | ||
key = "MySuperMegaKey" # Optional, don't work without link | ||
key = "MySuperMegaKey" # Optional, don't work without link | ||
duraction = 300 # Optional, value of duraction between manager checker iterations (in seconds) |
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 |
---|---|---|
@@ -1,74 +1,17 @@ | ||
pub mod errors; | ||
pub mod lock; | ||
pub mod mananger; | ||
pub mod models; | ||
pub mod query; | ||
pub mod settings; | ||
pub mod tr; | ||
|
||
use std::sync::Arc; | ||
|
||
use crate::errors::error::Result; | ||
use indicatif::{MultiProgress, ProgressBar}; | ||
use lock::Lock; | ||
use log::warn; | ||
use settings::Settings; | ||
use tokio::sync::Mutex; | ||
use tr::load::Load; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
pretty_env_logger::formatted_builder() | ||
.filter_level(log::LevelFilter::Info) | ||
.init(); | ||
// Init | ||
let (mpb, lock, settings) = init().await; | ||
// | ||
let pb = mpb.add(ProgressBar::new_spinner()); | ||
pb.finish_with_message("Init Minecraft Addon Controller"); | ||
// | ||
lock.lock().await.remove_nonexistent(&settings)?; | ||
'_c: { | ||
let lock = Arc::clone(&lock); | ||
let settings = Arc::clone(&settings); | ||
let mpb = Arc::clone(&mpb); | ||
download(settings, lock, mpb).await?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
async fn download( | ||
settings: Arc<Settings>, | ||
lock: Arc<Mutex<Lock>>, | ||
mpb: Arc<MultiProgress>, | ||
) -> Result<()> { | ||
'_core_scope: { | ||
let lock = Arc::clone(&lock); | ||
let mpb = Arc::clone(&mpb); | ||
settings.core().download(lock, mpb).await?; | ||
} | ||
'_plugins_scope: { | ||
let lock = Arc::clone(&lock); | ||
let mpb = Arc::clone(&mpb); | ||
if let Some(plugins) = settings.plugins() { | ||
plugins | ||
.download_all( | ||
settings.core().provider().as_str(), | ||
settings.core().version(), | ||
lock, | ||
mpb, | ||
) | ||
.await?; | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
async fn init() -> (Arc<MultiProgress>, Arc<Mutex<Lock>>, Arc<Settings>) { | ||
let mpb: Arc<MultiProgress> = Arc::new(MultiProgress::new()); | ||
let lock: Arc<Mutex<Lock>> = Arc::new(Mutex::new(Lock::load().await.unwrap_or({ | ||
warn!("Use default Lock"); | ||
Lock::default() | ||
}))); | ||
let settings: Arc<Settings> = Arc::new(Settings::load().await.unwrap()); | ||
(mpb, lock, settings) | ||
mananger::run().await | ||
} |
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,63 @@ | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
|
||
use indicatif::MultiProgress; | ||
use tokio::sync::{Mutex, RwLock}; | ||
use tokio::time::sleep; | ||
use tokio_util::sync::CancellationToken; | ||
|
||
use crate::errors::error::Result; | ||
use crate::settings::additions::Additions; | ||
use crate::{lock::Lock, settings::Settings}; | ||
|
||
pub async fn download( | ||
settings: Arc<RwLock<Settings>>, | ||
lock: Arc<Mutex<Lock>>, | ||
mpb: Arc<MultiProgress>, | ||
key: Arc<CancellationToken>, | ||
) -> Result<()> { | ||
let duraction = settings | ||
.read() | ||
.await | ||
.additions() | ||
.unwrap_or(&Additions::default()) | ||
.duraction() | ||
.unwrap_or(300f64); | ||
let cooldown = Duration::from_secs_f64(duraction); | ||
loop { | ||
'_core_scope: { | ||
let lock = Arc::clone(&lock); | ||
let settings = Arc::clone(&settings); | ||
let mpb = Arc::clone(&mpb); | ||
tokio::spawn(async move { | ||
let settings = settings.read().await; | ||
settings.core().download(lock, mpb).await | ||
}); | ||
} | ||
'_plugins_scope: { | ||
let lock = Arc::clone(&lock); | ||
let settings = Arc::clone(&settings); | ||
let mpb = Arc::clone(&mpb); | ||
|
||
tokio::spawn(async move { | ||
let settings = settings.read().await; | ||
if let Some(plugins) = settings.plugins() { | ||
plugins | ||
.download_all( | ||
settings.core().provider().as_str(), | ||
settings.core().version(), | ||
lock, | ||
mpb, | ||
) | ||
.await | ||
} else { | ||
Ok(()) | ||
} | ||
}); | ||
}; | ||
tokio::select! { | ||
_ = sleep(cooldown) => {}, | ||
_ = key.cancelled() => {break Ok(())}, | ||
} | ||
} | ||
} |
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,52 @@ | ||
use std::sync::Arc; | ||
|
||
use indicatif::MultiProgress; | ||
use tokio::sync::{mpsc::Receiver, Mutex, RwLock}; | ||
use tokio_util::sync::CancellationToken; | ||
|
||
use crate::errors::error::Result; | ||
use crate::mananger::download::download; | ||
use crate::mananger::messages::Messages; | ||
use crate::{lock::Lock, settings::Settings}; | ||
|
||
pub async fn manage( | ||
mut rx: Receiver<Messages>, | ||
lock: Arc<Mutex<Lock>>, | ||
settings: Arc<RwLock<Settings>>, | ||
mpb: Arc<MultiProgress>, | ||
) -> Result<()> { | ||
loop { | ||
let lock = Arc::clone(&lock); | ||
let settings = Arc::clone(&settings); | ||
let mpb = Arc::clone(&mpb); | ||
let key = Arc::new(CancellationToken::new()); | ||
tokio::select! { | ||
Some(e) = rx.recv() => match e { | ||
Messages::Restart(pb) => { | ||
pb.set_message("Рестарт!"); | ||
let key = Arc::clone(&key); | ||
pb.set_message("Стопаем текущюю задачу!"); | ||
key.cancel(); | ||
mpb.clear()?; | ||
if key.is_cancelled() { | ||
pb.set_message("Начинаем новую!"); | ||
tokio::spawn(download(settings.clone(), lock.clone(), mpb.clone(), key)); | ||
} else { | ||
pb.set_message("Ну... она стоит"); | ||
} | ||
pb.finish_and_clear(); | ||
} | ||
Messages::Stop(pb) => { | ||
pb.finish_with_message("Остановка!"); | ||
key.cancelled().await; | ||
} | ||
Messages::Start(pb) => { | ||
let key = Arc::clone(&key); | ||
pb.finish_with_message("Начинаем новую!"); | ||
tokio::spawn(download(settings.clone(), lock.clone(), mpb.clone(), key)); | ||
pb.finish_and_clear(); | ||
} | ||
}, | ||
} | ||
} | ||
} |
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,9 @@ | ||
use std::sync::Arc; | ||
|
||
use indicatif::ProgressBar; | ||
|
||
pub enum Messages { | ||
Restart(Arc<ProgressBar>), | ||
Stop(Arc<ProgressBar>), | ||
Start(Arc<ProgressBar>), | ||
} |
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,60 @@ | ||
mod download; | ||
mod manage; | ||
pub mod messages; | ||
mod watch_changer; | ||
|
||
use std::sync::Arc; | ||
|
||
use crate::errors::error::Result; | ||
use indicatif::{MultiProgress, ProgressBar}; | ||
use lock::Lock; | ||
use log::warn; | ||
use manage::manage; | ||
use settings::Settings; | ||
use tokio::{ | ||
sync::{mpsc, Mutex, RwLock}, | ||
try_join, | ||
}; | ||
use tr::load::Load; | ||
|
||
use crate::{lock, settings, tr}; | ||
|
||
use self::watch_changer::watch_changes; | ||
|
||
pub async fn run() -> Result<()> { | ||
let (mpb, lock, settings) = init().await?; | ||
// | ||
let pb = mpb.add(ProgressBar::new_spinner()); | ||
pb.finish_with_message("Init Minecraft Addon Controller"); | ||
// | ||
let (tx, rx) = mpsc::channel(20); | ||
|
||
let manage = { | ||
let settings_m = Arc::clone(&settings); | ||
let lock = Arc::clone(&lock); | ||
let mpb_m = Arc::clone(&mpb); | ||
manage(rx, lock, settings_m, mpb_m) | ||
}; | ||
let watch_changes = { | ||
let settings_w = Arc::clone(&settings); | ||
let lock = Arc::clone(&lock); | ||
let mpb_w = Arc::clone(&mpb); | ||
watch_changes(settings_w, lock, mpb_w, tx) | ||
}; | ||
|
||
let a = try_join!(manage, watch_changes); | ||
match a { | ||
Ok(_) => Ok(()), | ||
Err(e) => Err(e), | ||
} | ||
} | ||
|
||
async fn init() -> Result<(Arc<MultiProgress>, Arc<Mutex<Lock>>, Arc<RwLock<Settings>>)> { | ||
let mpb: Arc<MultiProgress> = Arc::new(MultiProgress::new()); | ||
let lock: Arc<Mutex<Lock>> = Arc::new(Mutex::new(Lock::load().await.unwrap_or({ | ||
warn!("Use default Lock"); | ||
Lock::default() | ||
}))); | ||
let settings = Arc::new(RwLock::new(Settings::load().await?)); | ||
Ok((mpb, lock, settings)) | ||
} |
Oops, something went wrong.