Remove pathdiff dependency and unused function
This commit is contained in:
parent
1d7e43fa5c
commit
6a19b0fbb0
|
|
@ -23,7 +23,6 @@ opt-level = 2
|
||||||
clap = { version = "4.4", features = ["derive"] }
|
clap = { version = "4.4", features = ["derive"] }
|
||||||
flate2 = "1.0"
|
flate2 = "1.0"
|
||||||
gltf = "1.4.0"
|
gltf = "1.4.0"
|
||||||
pathdiff = "0.2.1"
|
|
||||||
rayon = "1.8.0"
|
rayon = "1.8.0"
|
||||||
regex = "1.10.2"
|
regex = "1.10.2"
|
||||||
tar = "0.4"
|
tar = "0.4"
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use rayon::prelude::*;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
@ -18,10 +18,6 @@ pub struct Unpacker {
|
||||||
pub assets: Vec<Asset>,
|
pub assets: Vec<Asset>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_relative_path(path1: &Path, path2: &Path) -> Option<PathBuf> {
|
|
||||||
pathdiff::diff_paths(path1, path2)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Unpacker {
|
impl Unpacker {
|
||||||
pub fn prepare_environment(&self) {
|
pub fn prepare_environment(&self) {
|
||||||
let archive_path = Path::new(&self.args.input);
|
let archive_path = Path::new(&self.args.input);
|
||||||
|
|
@ -135,20 +131,23 @@ impl Unpacker {
|
||||||
let reader = io::BufReader::new(file);
|
let reader = io::BufReader::new(file);
|
||||||
let mut gltf = gltf::Gltf::from_reader(reader).unwrap();
|
let mut gltf = gltf::Gltf::from_reader(reader).unwrap();
|
||||||
let mut json = gltf.document.into_json();
|
let mut json = gltf.document.into_json();
|
||||||
if let Some(rel_path) = get_relative_path(texture_asset, gltf_path) {
|
|
||||||
for image in json.images.iter_mut() {
|
for image in json.images.iter_mut() {
|
||||||
let result = rel_path.file_name().unwrap().to_str().unwrap().to_string();
|
let result = texture_asset.file_name().unwrap().to_str().unwrap().to_string();
|
||||||
let required_file = gltf_path.with_file_name(&result);
|
let required_file = gltf_path.with_file_name(&result);
|
||||||
if !required_file.exists() {
|
if !required_file.exists() {
|
||||||
fs::copy(texture_asset, gltf_path.with_file_name(&result)).unwrap();
|
fs::copy(texture_asset, gltf_path.with_file_name(&result)).unwrap();
|
||||||
}
|
}
|
||||||
|
if let Some(old_path) = &image.uri {
|
||||||
|
if old_path.eq(&result){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
println!(
|
println!(
|
||||||
"Image{:?}: {:?} to be replaced with: {}",
|
"Image{:?}: {:?} to be replaced with: {}",
|
||||||
image.name, image.uri, &result
|
image.name, image.uri, &result
|
||||||
);
|
);
|
||||||
image.uri = Some(result);
|
image.uri = Some(result);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
gltf.document = Document::from_json(json.clone()).unwrap();
|
gltf.document = Document::from_json(json.clone()).unwrap();
|
||||||
// Save the modified glTF
|
// Save the modified glTF
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue