Skip to content

Commit

Permalink
fix: don't use current_exe impl from maa_cli
Browse files Browse the repository at this point in the history
The `maa_cli` mod is not available if `self` feature is disabled.
  • Loading branch information
wangl-cc committed Oct 13, 2023
1 parent 13de53b commit 154638d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 3 additions & 7 deletions maa-cli/src/installer/maa_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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| {
Expand All @@ -57,10 +57,6 @@ pub fn update(dirs: &Dirs) -> Result<()> {
Ok(())
}

pub fn current_exe() -> std::io::Result<PathBuf> {
std::env::current_exe()?.canonicalize()
}

fn get_metadata() -> Result<VersionJSON> {
let metadata_url = if let Some(url) = var_os("MAA_CLI_API") {
url.into_string().unwrap()
Expand Down
6 changes: 4 additions & 2 deletions maa-cli/src/installer/maa_core.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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,
Expand Down Expand Up @@ -293,6 +293,7 @@ pub fn find_lib_dir(dirs: &Dirs) -> Option<PathBuf> {
}

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());
Expand Down Expand Up @@ -320,6 +321,7 @@ pub fn find_resource(dirs: &Dirs) -> Option<PathBuf> {
}

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() {
Expand Down

0 comments on commit 154638d

Please sign in to comment.