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

Commit

Permalink
add "remove if not exist in config"
Browse files Browse the repository at this point in the history
  • Loading branch information
TOwInOK committed May 1, 2024
1 parent 203d4b2 commit 187a1ed
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
Binary file added paper.jar
Binary file not shown.
4 changes: 0 additions & 4 deletions settings.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
[core]
Provider = "paper"
Version = "1.20.6"
ForceUpdate = true

[plugins.simple-voice-chat]
force_update = false
[plugins.chunky]
force_update = false
14 changes: 14 additions & 0 deletions src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
use self::core::CoreMeta;
use self::ext::ExtensionMeta;
use crate::errors::error::Result;
use crate::settings::Settings;
use crate::{
settings::core::Core,
tr::{load::Load, save::Save},
Expand Down Expand Up @@ -46,6 +47,19 @@ impl Lock {
self.core = CoreMeta::default();
Ok(())
}
pub fn remove_nonexistent(&mut self, settings: &Settings) -> Result<()> {
let plugin_keys: Vec<String> = self.plugins().0.keys().cloned().collect();
// TODO: let mods_keys
if let Some(e) = settings.plugins() {
for key in plugin_keys {
if !e.items().contains_key(&key) {
self.remove_plugin(key.as_str())?;
}
}
}
// TODO: add remover for mods
Ok(())
}
}

#[derive(Default, Serialize, Deserialize)]
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ async fn main() -> Result<()> {
let settings = Settings::load().await?;
// let a = Additions::new(Some("GitHub.link".to_string()), Some("GitHub.key".to_string()));
// settings.set_additions(Some(a));
lock.lock().await.remove_nonexistent(&settings)?;
if let Some(plugins) = settings.plugins() {
plugins
.download_all(settings.core().version(), &lock, &mpb)
Expand Down
1 change: 0 additions & 1 deletion src/settings/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use serde::{Deserialize, Serialize};
use tokio::sync::Mutex;

use crate::errors::error::Result;
use crate::lock::core::CoreMeta;
use crate::lock::Lock;
use crate::models::cores::folia::Folia;
use crate::models::cores::paper::Paper;
Expand Down
14 changes: 11 additions & 3 deletions src/settings/extensions/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ use crate::tr::{download::Download, save::Save};

use super::plugin::Plugin;

const PATH: &'static str = "./plugins/";

#[derive(Deserialize, Serialize, Debug, Default, PartialEq)]
pub struct Plugins(HashMap<String, Plugin>);

Expand Down Expand Up @@ -59,12 +61,18 @@ impl Plugins {
let lock = Arc::clone(lock);
let mpb = Arc::clone(mpb);
handler_list.push(tokio::spawn(async move {
// lock bar & lock
let mut lock = lock.lock().await;
let mpb = mpb.lock().await;
// get file
let file = Plugin::get_file(name.to_owned(), link, hash, &mpb).await?;
let mut lock = lock.lock().await;
//delete prevision item
lock.remove_plugin(&name)?;
// save on disk
Plugin::save_bytes(file, name.as_str()).await?;
//save in lock
lock.plugins_mut().insert(name.to_string(), {
ExtensionMeta::new(build, format!("./plugins/{}.jar", name))
ExtensionMeta::new(build, format!("{}{}.jar", PATH, name))
});
lock.save().await
}));
Expand All @@ -76,5 +84,5 @@ impl Plugins {

impl Download for Plugin {}
impl Save for Plugin {
const PATH: &'static str = "./plugins/";
const PATH: &'static str = PATH;
}

0 comments on commit 187a1ed

Please sign in to comment.