Auto plugin installer
This commit is contained in:
@@ -28,14 +28,14 @@ impl PluginLoader {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn load(&self, json_path: &Path) -> Plugin {
|
||||
let json_string = fs::read_to_string(json_path).unwrap();
|
||||
pub fn load(&self, path: &Path) -> Plugin {
|
||||
let json_string = fs::read_to_string(path.join("plugin.json")).unwrap();
|
||||
let plugin_json: PluginJson = serde_json::from_str(&json_string).unwrap();
|
||||
LOGGER.info(format!("Loading {}", plugin_json.id));
|
||||
|
||||
Command::new(plugin_json.file)
|
||||
.args(plugin_json.args)
|
||||
.current_dir("plugins")
|
||||
.current_dir(path)
|
||||
.spawn()
|
||||
.unwrap();
|
||||
|
||||
|
||||
+20
-4
@@ -1,14 +1,16 @@
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
fs,
|
||||
fs::{self, File},
|
||||
net::{TcpListener, TcpStream},
|
||||
path::{Path, PathBuf},
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use zip::ZipArchive;
|
||||
|
||||
use crate::{
|
||||
logger,
|
||||
plugin::{Plugin, loader::PluginLoader, types::LoaderMessage},
|
||||
plugin::{self, Plugin, loader::PluginLoader, types::LoaderMessage},
|
||||
types,
|
||||
utils::{self, client::Client},
|
||||
};
|
||||
@@ -78,8 +80,22 @@ impl Server {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
|
||||
if path.extension().and_then(|s| s.to_str()) == Some("json") {
|
||||
let mut p = plugin_loader.load(&path);
|
||||
let p = if path.extension().and_then(|s| s.to_str()) == Some("vxp") {
|
||||
plugin::loader::LOGGER.info(format!("Installing {:?}", path));
|
||||
let d = path.with_extension("");
|
||||
if !d.exists() {
|
||||
let file = File::open(&path)?;
|
||||
let mut archive = ZipArchive::new(file)?;
|
||||
archive.extract(&d)?;
|
||||
}
|
||||
|
||||
d
|
||||
} else {
|
||||
path
|
||||
};
|
||||
|
||||
if p.is_dir() {
|
||||
let mut p = plugin_loader.load(&p);
|
||||
let s = self.clone();
|
||||
self.plugins.lock().unwrap().push(p.clone());
|
||||
std::thread::spawn(move || p.run(&s));
|
||||
|
||||
Reference in New Issue
Block a user