[feat] check path and suffix
This commit is contained in:
@@ -5,6 +5,17 @@ import { useSteamStore } from "@/store/steam"
|
|||||||
import { open } from "@tauri-apps/plugin-dialog"
|
import { open } from "@tauri-apps/plugin-dialog"
|
||||||
import { invoke } from "@tauri-apps/api/core"
|
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() {
|
export function Prepare() {
|
||||||
const steam = useSteamStore()
|
const steam = useSteamStore()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -15,13 +26,11 @@ export function Prepare() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkPaths = async () => {
|
const checkPaths = async () => {
|
||||||
if (
|
const exist: boolean =
|
||||||
(await invoke("check_path", { path: steam.state.dir })) &&
|
(await check_path(steam.state.dir, "steam.exe")) &&
|
||||||
(await invoke("check_path", { path: steam.state.csDir }))
|
(await check_path(steam.state.csDir, "cs2.exe"))
|
||||||
) {
|
|
||||||
setInited(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
setInited(exist)
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
checkPaths()
|
checkPaths()
|
||||||
|
|||||||
Reference in New Issue
Block a user