findSoftware
根据软件名获取软件安装路径,支持多种查找策略。
前置依赖
依赖参数
| 参数名 | 类型 | 说明 |
|---|---|---|
systemInfo.userHome | string | 用户主目录路径 |
systemInfo.env | Record<string, string | undefined> | 环境变量对象 |
systemInfo.fileExists | (path: string) => boolean | 文件系统检查函数 |
systemInfo.platform | Platform | 当前运行平台 |
systemInfo.joinPath | (dir: string, file: string) => string | 路径拼接函数 |
函数签名
typescript
function findSoftwareByName(
softwareName: string,
systemInfo: SystemInfo
): SoftwareSearchResult
interface SystemInfo {
userHome: string
env: Record<string, string | undefined>
fileExists: (path: string) => boolean
platform: Platform
joinPath: (dir: string, file: string) => string
}
interface SoftwareSearchResult {
found: boolean
path?: string
}参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
softwareName | string | 是 | 软件名称(支持别名) |
systemInfo | SystemInfo | 是 | 系统信息对象 |
返回值
| 类型 | 说明 |
|---|---|
SoftwareSearchResult | 软件查找结果,包含是否找到和路径信息 |
工作原理
- 标准化软件名称:从
SOFTWARE_NAME_MAP中获取标准化的软件名称(支持别名) - 获取平台配置:从
SOFTWARE_CONFIGS中获取当前平台的配置信息 - 查找策略(按优先级):
- 专用环境变量:检查软件专用的环境变量(如
ANDROID_HOME) - PATH环境变量:遍历 PATH 环境变量中的所有目录,查找可执行文件
- 默认安装路径:检查平台配置中的默认安装路径和用户路径
- 专用环境变量:检查软件专用的环境变量(如
- 验证文件存在:使用
fileExists验证找到的路径是否真实存在 - 返回结果:如果找到,返回
{ found: true, path: '...' },否则返回{ found: false }
支持跨平台查找,自动处理路径展开(如 ~ 替换为用户主目录),适用于查找开发工具、SDK 等软件的安装路径。