Added Core Features chroium, config,console_ui,headless,webserver,states
This commit is contained in:
parent
4c6c6d572c
commit
c3c60efb81
13 changed files with 688 additions and 0 deletions
42
Core/chromium/utils.rs
Normal file
42
Core/chromium/utils.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
use std::{fs, io::{self}, path::{Path, PathBuf}};
|
||||
use zip::read::ZipArchive;
|
||||
|
||||
pub fn extract_zip(src: &Path, dest: &Path) -> io::Result<()> {
|
||||
let file = fs::File::open(src)?;
|
||||
let mut archive = ZipArchive::new(file)?;
|
||||
fs::create_dir_all(dest)?;
|
||||
|
||||
for i in 0..archive.len() {
|
||||
let mut entry = archive.by_index(i)?;
|
||||
let outpath = dest.join(sanitize_path(entry.name()));
|
||||
|
||||
if entry.is_dir() {
|
||||
fs::create_dir_all(&outpath)?;
|
||||
} else {
|
||||
if let Some(p) = outpath.parent() { fs::create_dir_all(p)?; }
|
||||
let mut outfile = fs::File::create(&outpath)?;
|
||||
io::copy(&mut entry, &mut outfile)?;
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
if let Some(mode) = entry.unix_mode() {
|
||||
fs::set_permissions(&outpath, fs::Permissions::from_mode(mode))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn sanitize_path(name: &str) -> PathBuf {
|
||||
let path = Path::new(name);
|
||||
let mut clean = PathBuf::new();
|
||||
for comp in path.components() {
|
||||
use std::path::Component::*;
|
||||
match comp {
|
||||
Normal(c) => clean.push(c),
|
||||
CurDir | ParentDir | RootDir | Prefix(_) => { /* skip */ }
|
||||
}
|
||||
}
|
||||
clean
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue