️ 增加目录存在判断

This commit is contained in:
BTMuli
2023-12-12 13:53:32 +08:00
parent 57e055ebe8
commit 888f1f2bdd
2 changed files with 17 additions and 3 deletions

View File

@@ -47,7 +47,7 @@
</div>
</template>
<script lang="ts" setup>
import { dialog, path } from "@tauri-apps/api";
import { dialog, fs, path } from "@tauri-apps/api";
import { computed, onMounted, ref, watch } from "vue";
import showConfirm from "../../components/func/confirm";
@@ -352,6 +352,9 @@ async function backupGacha(): Promise<void> {
}
loadingTitle.value = "正在备份祈愿数据";
loading.value = true;
if (!(await fs.exists("userData", { dir: fs.BaseDirectory.AppLocalData }))) {
await fs.createDir("userData", { dir: fs.BaseDirectory.AppLocalData, recursive: true });
}
await backupUigfData(uidCur.value, gachaListCur.value);
loading.value = false;
showSnackbar({

View File

@@ -149,7 +149,7 @@
<script lang="ts" setup>
import { app, fs, invoke, os } from "@tauri-apps/api";
import { exit } from "@tauri-apps/api/process";
import { relaunch } from "@tauri-apps/api/types/process";
import { computed, onMounted, ref } from "vue";
import showConfirm from "../../components/func/confirm";
@@ -378,6 +378,10 @@ async function confirmBackup(): Promise<void> {
}
loadingTitle.value = "正在备份数据...";
loading.value = true;
if (!(await fs.exists("userData", { dir: fs.BaseDirectory.AppLocalData }))) {
await fs.createDir("userData", { dir: fs.BaseDirectory.AppLocalData, recursive: true });
}
console.info("数据文件夹创建完成!");
loadingSub.value = "正在获取成就数据";
const achievements = await TGSqlite.getUIAF();
loadingSub.value = "正在备份成就数据";
@@ -410,6 +414,13 @@ async function confirmRestore(): Promise<void> {
}
loadingTitle.value = "正在恢复数据...";
loading.value = true;
if (!(await fs.exists("userData", { dir: fs.BaseDirectory.AppLocalData }))) {
showSnackbar({
color: "error",
text: "数据文件夹不存在!",
});
return;
}
const fail: string[] = [];
let res: boolean;
loadingSub.value = "正在恢复成就数据";
@@ -523,7 +534,7 @@ async function confirmDelCache(): Promise<void> {
});
await new Promise(() => {
setTimeout(async () => {
await exit();
await relaunch();
}, 1500);
});
}