feat: commit code
This commit is contained in:
1 parent
77393b273e
commit
b3dcebcc50
2 files changed
+29
-11
No files matched your search
@@ -2,9 +2,11 @@ use std::{
|
|||||||
fs::{create_dir, create_dir_all, remove_dir_all},
|
fs::{create_dir, create_dir_all, remove_dir_all},
|
||||||
path::PathBuf, io::{Read, Write},
|
path::PathBuf, io::{Read, Write},
|
||||||
};
|
};
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
use mlua::UserData;
|
use mlua::UserData;
|
||||||
|
use flate2::read::GzDecoder;
|
||||||
|
use tar::Archive;
|
||||||
use crate::tools::extract_zip;
|
use crate::tools::extract_zip;
|
||||||
|
|
||||||
pub struct PluginFileSystem;
|
pub struct PluginFileSystem;
|
||||||
@@ -48,10 +50,30 @@ impl UserData for PluginFileSystem {
|
|||||||
let file = PathBuf::from(args.0);
|
let file = PathBuf::from(args.0);
|
||||||
let target = PathBuf::from(args.1);
|
let target = PathBuf::from(args.1);
|
||||||
let res = extract_zip(&file, &target);
|
let res = extract_zip(&file, &target);
|
||||||
if let Err(e) = res {
|
if let Err(_) = res {
|
||||||
return Err(mlua::Error::RuntimeError(e.to_string()));
|
return Ok(false);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(true)
|
||||||
|
});
|
||||||
|
methods.add_function("untar_gz_file", |_, args: (String, String)| {
|
||||||
|
|
||||||
|
let file = PathBuf::from(args.0);
|
||||||
|
let target = PathBuf::from(args.1);
|
||||||
|
|
||||||
|
let tar_gz = if let Ok(v) = File::open(file) {
|
||||||
|
v
|
||||||
|
} else {
|
||||||
|
return Ok(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
let tar = GzDecoder::new(tar_gz);
|
||||||
|
let mut archive = Archive::new(tar);
|
||||||
|
if archive.unpack(&target).is_err() {
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Ok(true)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-7
@@ -4,7 +4,7 @@ use std::{
|
|||||||
sync::Mutex,
|
sync::Mutex,
|
||||||
};
|
};
|
||||||
|
|
||||||
use mlua::{AsChunk, chunk, Lua, Table};
|
use mlua::{AsChunk, Lua, Table};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
@@ -136,10 +136,10 @@ impl PluginManager {
|
|||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// plugin init failed
|
// plugin init failed
|
||||||
|
log::warn!("Plugin init failed: {e}");
|
||||||
let _ = lua.load(mlua::chunk! {
|
let _ = lua.load(mlua::chunk! {
|
||||||
table.remove(manager, $idx)
|
table.remove(manager, $idx)
|
||||||
}).exec();
|
}).exec();
|
||||||
log::warn!("Plugin init failed: {e}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -289,8 +289,4 @@ impl PluginManager {
|
|||||||
|
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
}
|
||||||
pub fn plugin_status() {
|
|
||||||
let lua = LUA.lock().unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user