diff --git a/maa-cli/src/installer/maa_cli.rs b/maa-cli/src/installer/maa_cli.rs index 118b7b87..6a27fa3b 100644 --- a/maa-cli/src/installer/maa_cli.rs +++ b/maa-cli/src/installer/maa_cli.rs @@ -6,8 +6,8 @@ use super::{ use crate::dirs::{Dirs, Ensure}; use std::{ - env::{consts::EXE_SUFFIX, var_os}, - path::{Path, PathBuf}, + env::{consts::EXE_SUFFIX, current_exe, var_os}, + path::Path, }; use anyhow::{bail, Context, Result}; @@ -43,7 +43,7 @@ pub fn update(dirs: &Dirs) -> Result<()> { ); let bin_name = name(); - let bin_path = current_exe()?; + let bin_path = current_exe()?.canonicalize()?; let cache_dir = dirs.cache().ensure()?; asset.download(cache_dir)?.extract(|path| { @@ -57,10 +57,6 @@ pub fn update(dirs: &Dirs) -> Result<()> { Ok(()) } -pub fn current_exe() -> std::io::Result { - std::env::current_exe()?.canonicalize() -} - fn get_metadata() -> Result { let metadata_url = if let Some(url) = var_os("MAA_CLI_API") { url.into_string().unwrap() diff --git a/maa-cli/src/installer/maa_core.rs b/maa-cli/src/installer/maa_core.rs index c0307f49..2520630b 100644 --- a/maa-cli/src/installer/maa_core.rs +++ b/maa-cli/src/installer/maa_core.rs @@ -1,6 +1,6 @@ // This file is used to download and extract prebuilt packages of maa-core. -use super::{download::download_mirrors, extract::Archive, maa_cli::current_exe}; +use super::{download::download_mirrors, extract::Archive}; use crate::{ dirs::{Dirs, Ensure}, @@ -10,7 +10,7 @@ use crate::{ use std::{ env::{ consts::{DLL_PREFIX, DLL_SUFFIX}, - var_os, + current_exe, var_os, }, path::{Component, Path, PathBuf}, time::Duration, @@ -293,6 +293,7 @@ pub fn find_lib_dir(dirs: &Dirs) -> Option { } if let Ok(path) = current_exe() { + let path = path.canonicalize().unwrap(); let exe_dir = path.parent().unwrap(); if exe_dir.join(MAA_CORE_NAME).exists() { return Some(exe_dir.to_path_buf()); @@ -320,6 +321,7 @@ pub fn find_resource(dirs: &Dirs) -> Option { } if let Ok(path) = current_exe() { + let path = path.canonicalize().unwrap(); let exe_dir = path.parent().unwrap(); let resource_dir = exe_dir.join("resource"); if resource_dir.exists() {