orinium_browser/platform/io/
mod.rs1use anyhow::{Context, Result};
4use std::fs;
5use std::path::PathBuf;
6
7#[allow(dead_code)]
8pub fn load_local_file(path: &str) -> Result<Vec<u8>> {
9 fs::read(path).with_context(|| format!("Failed to read file: {path}"))
10}
11
12pub fn load_resource(rel_path: &str) -> Result<Vec<u8>> {
18 let mut candidates: Vec<PathBuf> = Vec::new();
19
20 candidates.push(PathBuf::from("resource").join(rel_path));
22
23 if let Ok(exe) = std::env::current_exe()
25 && let Some(dir) = exe.parent()
26 {
27 candidates.push(dir.join("resource").join(rel_path));
28 }
29
30 if let Ok(cd) = std::env::current_dir() {
32 candidates.push(cd.join("resource").join(rel_path));
33 }
34
35 for cand in candidates {
36 if cand.is_file() {
37 return fs::read(&cand).with_context(|| format!("Failed to read resource {:?}", cand));
38 }
39 }
40
41 anyhow::bail!("Resource not found: {}", rel_path)
42}