Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ dist-ssr
src-tauri/resources/libonnxruntime.so
src-tauri/resources/libonnxruntime.dylib
src-tauri/resources/onnxruntime.dll
src-tauri/gen/
src-tauri/libs/
52 changes: 41 additions & 11 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
let out_dir = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR not set"));
let temp_filename = dest_path.file_name().unwrap();
let temp_path = out_dir.join(temp_filename);

Check warning on line 24 in src-tauri/build.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/RapidRAW/RapidRAW/src-tauri/build.rs
println!(
"cargo:warning=Downloading to temporary path: {:?}",
temp_path
temp_path
);
let mut response = reqwest::blocking::get(url)?;

Expand All @@ -43,10 +43,10 @@
match verify_sha256(&temp_path, expected_hash) {
Ok(true) => {
fs::copy(&temp_path, dest_path)?;
fs::remove_file(&temp_path)?;

Check warning on line 46 in src-tauri/build.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/RapidRAW/RapidRAW/src-tauri/build.rs
println!(
"cargo:warning=Successfully downloaded and verified {:?}.",
dest_path
dest_path
);
Ok(())
}
Expand All @@ -65,6 +65,8 @@
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();

let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());

let (download_filename, lib_name, expected_hash) =
match (target_os.as_str(), target_arch.as_str()) {
("windows", "x86_64") => (
Expand Down Expand Up @@ -97,12 +99,23 @@
"libonnxruntime.dylib",
"2b885992d3d6fa4130d39ec84a80d7504ff52750027c547bb22c86165f19406a",
),
("android", "aarch64") => (
"libonnxruntime-android-arm64-v8a.so",
"libonnxruntime.so",
"999ecfdb5b5a13e4097487773b6d71ce8a075408a237daab072e8f5e817bd78e",
),
_ => panic!("Unsupported target: {}-{}", target_os, target_arch),

Check warning on line 107 in src-tauri/build.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/RapidRAW/RapidRAW/src-tauri/build.rs
};

let resources_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("resources");
fs::create_dir_all(&resources_dir).unwrap();
let dest_path = resources_dir.join(lib_name);

let dest_dir = if target_os == "android" {
manifest_dir.join("libs").join("arm64-v8a")
} else {
manifest_dir.join("resources")
};

fs::create_dir_all(&dest_dir).unwrap();
let dest_path = dest_dir.join(lib_name);

let mut is_valid = false;
if dest_path.exists() {
Expand All @@ -113,29 +126,28 @@
);
is_valid = true;
}
Ok(false) => {

Check warning on line 129 in src-tauri/build.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/RapidRAW/RapidRAW/src-tauri/build.rs
println!(
"cargo:warning=File {:?} exists but has incorrect hash. Deleting and re-downloading.",
dest_path
dest_path
);
fs::remove_file(&dest_path).unwrap();
}
Err(e) => {

Check warning on line 136 in src-tauri/build.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/RapidRAW/RapidRAW/src-tauri/build.rs
println!(
"cargo:warning=Could not verify file {:?}: {}. Re-downloading.",
dest_path, e
dest_path, e
);
}
}
}

if !is_valid {

Check warning on line 145 in src-tauri/build.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/RapidRAW/RapidRAW/src-tauri/build.rs
println!(
"cargo:warning=Downloading ONNX Runtime library for {}-{}...",
target_os, target_arch
target_os, target_arch
);
let base_url =
"https://huggingface.co/CyberTimon/RapidRAW-Models/resolve/main/onnxruntimes-v1.22.0/";
let base_url = "https://huggingface.co/CyberTimon/RapidRAW-Models/resolve/main/onnxruntimes-v1.22.0/";
let download_url = format!("{}{}?download=true", base_url, download_filename);
println!("cargo:warning=URL: {}", download_url);

Expand All @@ -144,7 +156,25 @@
}
}

if target_os == "android" {
let jni_libs_dir = manifest_dir.join("gen/android/app/src/main/jniLibs/arm64-v8a");
fs::create_dir_all(&jni_libs_dir).unwrap();

Check warning on line 161 in src-tauri/build.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/RapidRAW/RapidRAW/src-tauri/build.rs
fs::copy(&dest_path, jni_libs_dir.join(lib_name)).unwrap();

println!(
"cargo:rustc-env=ORT_LIB_LOCATION={}",
dest_dir.display()
);
println!(
"cargo:rustc-env=ORT_STRATEGY=manual"
);
println!(
"cargo:rustc-link-search=native={}",
dest_dir.display()
);
}

println!("cargo:rerun-if-changed=build.rs");

Check warning on line 178 in src-tauri/build.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/RapidRAW/RapidRAW/src-tauri/build.rs
tauri_build::build()
}
}
97 changes: 75 additions & 22 deletions src-tauri/src/file_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
use rayon::ThreadPoolBuilder;
use rayon::prelude::*;
use regex::Regex;
use serde::{Deserialize, Serialize};

Check warning on line 22 in src-tauri/src/file_management.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/RapidRAW/RapidRAW/src-tauri/src/file_management.rs
use serde_json::Value;
use tauri::{AppHandle, Emitter, Manager};
use uuid::Uuid;
use walkdir::WalkDir;
#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
use trash;

use crate::AppState;
use crate::calculate_geometry_hash;
Expand Down Expand Up @@ -1587,14 +1589,22 @@

#[tauri::command]
pub fn delete_folder(path: String) -> Result<(), String> {
if let Err(trash_error) = trash::delete(&path) {
log::warn!(
"Failed to move folder to trash: {}. Falling back to permanent delete.",
trash_error
);
#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
{
if let Err(trash_error) = trash::delete(&path) {
log::warn!(
"Failed to move folder to trash: {}. Falling back to permanent delete.",
trash_error
);
fs::remove_dir_all(&path).map_err(|e| e.to_string())
} else {
Ok(())
}
}

#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
{
fs::remove_dir_all(&path).map_err(|e| e.to_string())
} else {
Ok(())
}
}

Expand Down Expand Up @@ -1791,6 +1801,7 @@
all_files_to_trash.extend(files_to_move);
}

#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
if !all_files_to_trash.is_empty()
&& let Err(trash_error) = trash::delete_all(&all_files_to_trash)
{
Expand All @@ -1807,6 +1818,14 @@
}
}

#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
for path in all_files_to_trash {
if path.is_file() {
fs::remove_file(&path)
.map_err(|e| format!("Failed to delete source file {}: {}", path.display(), e))?;
}
}

Ok(())
}

Expand Down Expand Up @@ -2658,6 +2677,7 @@
}

let final_paths_to_delete: Vec<PathBuf> = files_to_trash.into_iter().collect();
#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
if let Err(trash_error) = trash::delete_all(&final_paths_to_delete) {
log::warn!(
"Failed to move files to trash: {}. Falling back to permanent delete.",
Expand All @@ -2673,6 +2693,18 @@
}
}
}

#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
for path in final_paths_to_delete {
if path.is_file() {
fs::remove_file(&path)
.map_err(|e| format!("Failed to delete file {}: {}", path.display(), e))?;
} else if path.is_dir() {
fs::remove_dir_all(&path)
.map_err(|e| format!("Failed to delete directory {}: {}", path.display(), e))?;
}
}

Ok(())
}

Expand Down Expand Up @@ -2730,6 +2762,7 @@
}

let final_paths_to_delete: Vec<PathBuf> = files_to_trash.into_iter().collect();
#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
if let Err(trash_error) = trash::delete_all(&final_paths_to_delete) {
log::warn!(
"Failed to move files to trash: {}. Falling back to permanent delete.",
Expand All @@ -2742,6 +2775,15 @@
}
}
}

#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
for path in final_paths_to_delete {
if path.is_file() {
fs::remove_file(&path)
.map_err(|e| format!("Failed to delete file {}: {}", path.display(), e))?;
}
}

Ok(())
}

Expand Down Expand Up @@ -2888,23 +2930,34 @@
}

if settings.delete_after_import {
if let Err(trash_error) = trash::delete(&source_path) {
log::warn!(
"Failed to trash source file {}: {}. Deleting permanently.",
source_path.display(),
trash_error
);
fs::remove_file(&source_path).map_err(|e| e.to_string())?;
#[cfg(any(target_os = "windows", target_os = "macos", target_os = "linux"))]
{
if let Err(trash_error) = trash::delete(&source_path) {
log::warn!(
"Failed to trash source file {}: {}. Deleting permanently.",
source_path.display(),
trash_error
);
fs::remove_file(&source_path).map_err(|e| e.to_string())?;
}
if source_sidecar.exists()
&& let Err(trash_error) = trash::delete(&source_sidecar)
{
log::warn!(
"Failed to trash source sidecar {}: {}. Deleting permanently.",
source_sidecar.display(),
trash_error
);
fs::remove_file(&source_sidecar).map_err(|e| e.to_string())?;
}

Check warning on line 2952 in src-tauri/src/file_management.rs

View workflow job for this annotation

GitHub Actions / cargo fmt

Diff in /home/runner/work/RapidRAW/RapidRAW/src-tauri/src/file_management.rs
}
if source_sidecar.exists()
&& let Err(trash_error) = trash::delete(&source_sidecar)

#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
{
log::warn!(
"Failed to trash source sidecar {}: {}. Deleting permanently.",
source_sidecar.display(),
trash_error
);
fs::remove_file(&source_sidecar).map_err(|e| e.to_string())?;
fs::remove_file(&source_path).map_err(|e| e.to_string())?;
if source_sidecar.exists() {
fs::remove_file(&source_sidecar).map_err(|e| e.to_string())?;
}
}
}

Expand Down
Loading
Loading