Remove pathdiff dependency and unused function

This commit is contained in:
Piotr Siuszko 2023-12-29 15:25:23 +01:00
parent 1d7e43fa5c
commit 6a19b0fbb0
2 changed files with 16 additions and 18 deletions

View File

@ -23,7 +23,6 @@ opt-level = 2
clap = { version = "4.4", features = ["derive"] }
flate2 = "1.0"
gltf = "1.4.0"
pathdiff = "0.2.1"
rayon = "1.8.0"
regex = "1.10.2"
tar = "0.4"

View File

@ -5,7 +5,7 @@ use rayon::prelude::*;
use std::borrow::Cow;
use std::fs::File;
use std::path::{Path, PathBuf};
use std::path::Path;
use std::process::Command;
use std::sync::mpsc::channel;
use std::sync::Arc;
@ -18,10 +18,6 @@ pub struct Unpacker {
pub assets: Vec<Asset>,
}
fn get_relative_path(path1: &Path, path2: &Path) -> Option<PathBuf> {
pathdiff::diff_paths(path1, path2)
}
impl Unpacker {
pub fn prepare_environment(&self) {
let archive_path = Path::new(&self.args.input);
@ -135,20 +131,23 @@ impl Unpacker {
let reader = io::BufReader::new(file);
let mut gltf = gltf::Gltf::from_reader(reader).unwrap();
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() {
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);
if !required_file.exists() {
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!(
"Image{:?}: {:?} to be replaced with: {}",
image.name, image.uri, &result
);
image.uri = Some(result);
}
}
gltf.document = Document::from_json(json.clone()).unwrap();
// Save the modified glTF