diff --git a/core/Cargo.toml b/core/Cargo.toml index 1d4b53c..74afae0 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bp3d-os" -version = "2.1.0" +version = "2.2.0" authors = ["Yuri Edward "] edition = "2021" description = "Operating System tools designed for BlockProject3D" diff --git a/core/src/assets/mod.rs b/core/src/assets/mod.rs index 63cc96f..8184df1 100644 --- a/core/src/assets/mod.rs +++ b/core/src/assets/mod.rs @@ -1,4 +1,4 @@ -// Copyright (c) 2023, BlockProject 3D +// Copyright (c) 2025, BlockProject 3D // // All rights reserved. // @@ -71,9 +71,44 @@ use windows::{get_exe_path, get_resources_dir}; pub fn get_app_bundled_asset(file_name: &str) -> Option { let res = get_resources_dir() .map(|v| v.join(file_name)) - .or_else(|| get_exe_path().map(|v| v.join("Assets").join(file_name))); + .or_else(|| get_exe_path().map(|v| v.join("..").join("Assets").join(file_name))); if res.as_ref().map(|v| !v.exists()).unwrap_or(false) { - return None; + let res = get_exe_path().map(|v| v.join("Assets").join(file_name)); + if res.as_ref().map(|v| !v.exists()).unwrap_or(false) { + return None; + } + return res; } res } + +/// Returns the path to the executable. This is useful for loading assets in CLI based applications. +/// +/// # Platform specific behavior +/// +/// On supported platforms this returns the path to the current executing program. +/// Supported platforms are: +/// - Any Linux/Unix with a procfs, +/// - macOS, +/// - iOS +/// +/// Returns None if there is a system issue, ex: the system didn't return a proper path to the current +/// executing application. This should rarely occur. +pub fn get_executable_path() -> Option { + get_exe_path() +} + +#[cfg(test)] +mod tests { + use crate::assets::{get_app_bundled_asset, get_executable_path}; + + #[test] + fn test() { + assert!(get_executable_path().is_some()); + } + + #[test] + fn test2() { + assert!(get_app_bundled_asset("file.txt").is_none()); + } +} diff --git a/core/src/lib.rs b/core/src/lib.rs index 7c94c41..cd1ada2 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -28,7 +28,7 @@ //! Operating System tools and extensions designed for BlockProject3D. -#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] #![warn(missing_docs)] #[cfg(feature = "dirs")] diff --git a/module_test/test_mod/Cargo.toml b/module_test/test_mod/Cargo.toml index 22ad4bd..aba9413 100644 --- a/module_test/test_mod/Cargo.toml +++ b/module_test/test_mod/Cargo.toml @@ -11,5 +11,5 @@ crate-type = ["rlib", "cdylib"] bp3d-os-build = { version = "1.1.0", path = "../../build" } [dependencies] -bp3d-os = { version = "2.1.0", path = "../../core", features = ["module"] } +bp3d-os = { version = "2.2.0", path = "../../core", features = ["module"] } bp3d-debug = "1.0.0" diff --git a/module_test/testbin/Cargo.toml b/module_test/testbin/Cargo.toml index a27e040..96ffc46 100644 --- a/module_test/testbin/Cargo.toml +++ b/module_test/testbin/Cargo.toml @@ -5,4 +5,4 @@ edition = "2024" publish = false [dependencies] -bp3d-os = { version = "2.1.0", path = "../../core", features = ["module"] } +bp3d-os = { version = "2.2.0", path = "../../core", features = ["module"] } diff --git a/shelltestbin/Cargo.toml b/shelltestbin/Cargo.toml index 3ad165e..883808e 100644 --- a/shelltestbin/Cargo.toml +++ b/shelltestbin/Cargo.toml @@ -5,4 +5,4 @@ edition = "2024" publish = false [dependencies] -bp3d-os = { version = "2.0.0", path = "../core", features = ["shell"] } +bp3d-os = { version = "2.2.0", path = "../core", features = ["shell"] }