Auto plugin installer
This commit is contained in:
@@ -14,6 +14,7 @@ serde = { version = "1.0.219", features = ["serde_derive"] }
|
|||||||
serde_json = "1.0.143"
|
serde_json = "1.0.143"
|
||||||
sha1 = "0.10.6"
|
sha1 = "0.10.6"
|
||||||
ureq = "3.1.2"
|
ureq = "3.1.2"
|
||||||
|
zip = "7.0.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
|
|||||||
@@ -28,14 +28,14 @@ impl PluginLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load(&self, json_path: &Path) -> Plugin {
|
pub fn load(&self, path: &Path) -> Plugin {
|
||||||
let json_string = fs::read_to_string(json_path).unwrap();
|
let json_string = fs::read_to_string(path.join("plugin.json")).unwrap();
|
||||||
let plugin_json: PluginJson = serde_json::from_str(&json_string).unwrap();
|
let plugin_json: PluginJson = serde_json::from_str(&json_string).unwrap();
|
||||||
LOGGER.info(format!("Loading {}", plugin_json.id));
|
LOGGER.info(format!("Loading {}", plugin_json.id));
|
||||||
|
|
||||||
Command::new(plugin_json.file)
|
Command::new(plugin_json.file)
|
||||||
.args(plugin_json.args)
|
.args(plugin_json.args)
|
||||||
.current_dir("plugins")
|
.current_dir(path)
|
||||||
.spawn()
|
.spawn()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|||||||
+20
-4
@@ -1,14 +1,16 @@
|
|||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
fs,
|
fs::{self, File},
|
||||||
net::{TcpListener, TcpStream},
|
net::{TcpListener, TcpStream},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use zip::ZipArchive;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
logger,
|
logger,
|
||||||
plugin::{Plugin, loader::PluginLoader, types::LoaderMessage},
|
plugin::{self, Plugin, loader::PluginLoader, types::LoaderMessage},
|
||||||
types,
|
types,
|
||||||
utils::{self, client::Client},
|
utils::{self, client::Client},
|
||||||
};
|
};
|
||||||
@@ -78,8 +80,22 @@ impl Server {
|
|||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
|
|
||||||
if path.extension().and_then(|s| s.to_str()) == Some("json") {
|
let p = if path.extension().and_then(|s| s.to_str()) == Some("vxp") {
|
||||||
let mut p = plugin_loader.load(&path);
|
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();
|
let s = self.clone();
|
||||||
self.plugins.lock().unwrap().push(p.clone());
|
self.plugins.lock().unwrap().push(p.clone());
|
||||||
std::thread::spawn(move || p.run(&s));
|
std::thread::spawn(move || p.run(&s));
|
||||||
|
|||||||
Reference in New Issue
Block a user