[feat] check path and suffix

This commit is contained in:
Purp1e
2025-03-18 22:30:04 +08:00
parent 12e908f107
commit ae6b550019

View File

@@ -5,6 +5,17 @@ import { useSteamStore } from "@/store/steam"
import { open } from "@tauri-apps/plugin-dialog"
import { invoke } from "@tauri-apps/api/core"
/**
* 检查指定路径的有效性
* @param path - 需要检查的路径
* @param suffix - (可选) 路径需要匹配的后缀条件
* @returns Promise<boolean> 路径是否有效且满足后缀条件
*/
async function check_path(path: string, suffix?: string) {
if (suffix && !path.toLowerCase().startsWith(suffix)) return false
return await invoke<boolean>("check_path", { path: path })
}
export function Prepare() {
const steam = useSteamStore()
const router = useRouter()
@@ -15,13 +26,11 @@ export function Prepare() {
useEffect(() => {
const checkPaths = async () => {
if (
(await invoke("check_path", { path: steam.state.dir })) &&
(await invoke("check_path", { path: steam.state.csDir }))
) {
setInited(true)
}
const exist: boolean =
(await check_path(steam.state.dir, "steam.exe")) &&
(await check_path(steam.state.csDir, "cs2.exe"))
setInited(exist)
setLoading(false)
}
checkPaths()