From 6a19b0fbb091ed48bc1b8ff9539e6608af4d9f93 Mon Sep 17 00:00:00 2001 From: Piotr Siuszko Date: Fri, 29 Dec 2023 15:25:23 +0100 Subject: [PATCH] Remove pathdiff dependency and unused function --- Cargo.toml | 1 - src/unpacker.rs | 33 ++++++++++++++++----------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2812995..644380d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/unpacker.rs b/src/unpacker.rs index 6390b9d..b449ce7 100644 --- a/src/unpacker.rs +++ b/src/unpacker.rs @@ -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, } -fn get_relative_path(path1: &Path, path2: &Path) -> Option { - pathdiff::diff_paths(path1, path2) -} - impl Unpacker { pub fn prepare_environment(&self) { let archive_path = Path::new(&self.args.input); @@ -135,19 +131,22 @@ 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 required_file = gltf_path.with_file_name(&result); - if !required_file.exists() { - fs::copy(texture_asset, gltf_path.with_file_name(&result)).unwrap(); - } - println!( - "Image{:?}: {:?} to be replaced with: {}", - image.name, image.uri, &result - ); - image.uri = Some(result); + for image in json.images.iter_mut() { + 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();