[mio] 兼容padavan路由器找不到程序当前路径的问题

This commit is contained in:
lubeilin
2024-03-03 09:45:52 +08:00
parent 1eb2a0f5cf
commit 521280537a
3 changed files with 34 additions and 22 deletions
+15 -7
View File
@@ -18,13 +18,21 @@ mod console_out;
mod root_check;
pub fn app_home() -> io::Result<PathBuf> {
let path = std::env::current_exe()?
.parent()
.ok_or(io::Error::new(
io::ErrorKind::Other,
"current_exe parent error",
))?
.join("env");
let root_path = match std::env::current_exe() {
Ok(path) => {
if let Some(v) = path.as_path().parent() {
v.to_path_buf()
} else {
log::warn!("current_exe parent none:{:?}", path);
PathBuf::new()
}
}
Err(e) => {
log::warn!("current_exe err:{:?}", e);
PathBuf::new()
}
};
let path = root_path.join("env");
if !path.exists() {
std::fs::create_dir_all(&path)?;
}