diff --git a/src/components/cstb/Prepare.tsx b/src/components/cstb/Prepare.tsx index 771c60e..5bcf0be 100644 --- a/src/components/cstb/Prepare.tsx +++ b/src/components/cstb/Prepare.tsx @@ -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 路径是否有效且满足后缀条件 + */ +async function check_path(path: string, suffix?: string) { + if (suffix && !path.toLowerCase().startsWith(suffix)) return false + return await invoke("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()