Project: Support relative pathes #23
|
@ -3150,6 +3150,12 @@ version = "1.0.15"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||
|
||||
[[package]]
|
||||
name = "pathdiff"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.1"
|
||||
|
@ -4111,6 +4117,7 @@ dependencies = [
|
|||
name = "tim_tool"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"pathdiff",
|
||||
"png",
|
||||
"rfd",
|
||||
"serde",
|
||||
|
|
|
@ -7,12 +7,13 @@ edition = "2021"
|
|||
panic = "abort"
|
||||
|
||||
[dependencies]
|
||||
pathdiff = "0.2.3"
|
||||
png = "0.17.16"
|
||||
rfd = "0.15.2"
|
||||
slint = "1.9.2"
|
||||
tiny-skia = "0.11.4"
|
||||
serde = {version = "1.0.140", features = ["derive"]}
|
||||
serde_json = "1.0"
|
||||
tiny-skia = "0.11.4"
|
||||
tool_helper = {path = "../tool_helper"}
|
||||
|
||||
[build-dependencies]
|
||||
|
|
|
@ -98,6 +98,7 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
|||
|
||||
let tim_info = tim_manager.lock().expect("VRAM already locked").clone_added_tims();
|
||||
let vram_info = main_tab.clone_vram_info();
|
||||
let use_rel_path = main_window.get_project_widget_use_rel_paths();
|
||||
|
||||
if tim_info.len() != vram_info.len() {
|
||||
return Err(Error::from_str("TIM and VRAM info not in sync! Please close program"));
|
||||
|
@ -105,7 +106,12 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
|||
|
||||
let mut cur_job:Option<Job> = None;
|
||||
let mut cur_palette:Option<PaletteRect> = None;
|
||||
let mut project = Project::new(tim_info.into_iter().zip(vram_info.into_iter()).filter_map(|(tim, (file_name, vram))| {
|
||||
let mut map_result = Ok(());
|
||||
let mut project = Project::new(tim_info.into_iter().zip(vram_info.into_iter()).filter_map(|(tim, (name, vram))| {
|
||||
if map_result.is_err() {
|
||||
return None;
|
||||
}
|
||||
|
||||
if vram.is_palette {
|
||||
let cur_palette = std::mem::replace(&mut cur_palette, None);
|
||||
if let Some(mut cur_palette) = cur_palette {
|
||||
|
@ -125,11 +131,22 @@ pub(super) fn on_save_project_clicked(tim_manager: MutexTIMManager) -> impl FnMu
|
|||
if let Some((width, height)) = tim.get_palette_size() {
|
||||
cur_palette = Some(PaletteRect::new(0, 0, width, height));
|
||||
}
|
||||
cur_job = Some(Job::new(file_name, tim.get_path(), (vram.x as u16, vram.y as u16), Encoding::from_str(vram.encoding_str.as_str())));
|
||||
let file_path = if use_rel_path {
|
||||
match tim.get_path_rel_to(PathBuf::from(save_location.as_str())) {
|
||||
Ok(file_path) => file_path,
|
||||
Err(error) => {
|
||||
map_result = Err(error);
|
||||
PathBuf::new()
|
||||
}
|
||||
}
|
||||
} else {tim.get_path()};
|
||||
cur_job = Some(Job::new(name, file_path, (vram.x as u16, vram.y as u16), Encoding::from_str(vram.encoding_str.as_str())));
|
||||
}
|
||||
prev_job
|
||||
}
|
||||
}).collect());
|
||||
map_result?;
|
||||
|
||||
if let Some(cur_job) = cur_job {
|
||||
project.jobs.push(cur_job);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
pub mod types;
|
||||
|
||||
use pathdiff::diff_paths;
|
||||
use std::{fs::File, path::PathBuf};
|
||||
use slint::{Rgba8Pixel, SharedPixelBuffer};
|
||||
use tool_helper::Error;
|
||||
|
@ -132,6 +133,15 @@ impl TIMInfo {
|
|||
pub fn get_path(&self) -> std::path::PathBuf {
|
||||
self.path.clone()
|
||||
}
|
||||
|
||||
pub fn get_path_rel_to(&self, mut reference_path: std::path::PathBuf) -> Result<std::path::PathBuf, Error> {
|
||||
let file_path = self.path.clone();
|
||||
|
||||
reference_path.pop();
|
||||
diff_paths(&file_path, &reference_path).ok_or_else(|| {
|
||||
Error::from_text(format!("Can not create relative path from {} to {}", file_path.to_string_lossy().as_ref(), reference_path.to_string_lossy().as_ref()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
Loading…
Reference in New Issue