2025-08-19 14:33:59 +08:00
|
|
|
import { errorMessage, successMessage } from '@/public/generalTools'
|
|
|
|
|
import { app } from 'electron'
|
|
|
|
|
import path from 'path'
|
|
|
|
|
import os from 'os'
|
|
|
|
|
import { CheckFileOrDirExist } from '@/define/Tools/file'
|
|
|
|
|
import fs from 'fs'
|
|
|
|
|
import { ValidateJson } from '@/define/Tools/validate'
|
|
|
|
|
import { isEmpty } from 'lodash'
|
|
|
|
|
import { ErrorItem, SuccessItem } from '@/define/model/generalResponse'
|
2025-09-12 14:52:28 +08:00
|
|
|
import { t } from '@/i18n'
|
2025-08-19 14:33:59 +08:00
|
|
|
|
|
|
|
|
export class SettingService {
|
2025-09-12 14:52:28 +08:00
|
|
|
constructor() { }
|
2025-08-19 14:33:59 +08:00
|
|
|
|
|
|
|
|
/** 初始化数据库服务 */
|
2025-09-12 14:52:28 +08:00
|
|
|
async InitService() { }
|
2025-08-19 14:33:59 +08:00
|
|
|
|
|
|
|
|
//#region 剪映设置
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取默认的剪映草稿地址
|
|
|
|
|
*/
|
|
|
|
|
async GetDefaultJianyingDraftPath(): Promise<SuccessItem | ErrorItem> {
|
|
|
|
|
console.log('123')
|
|
|
|
|
try {
|
|
|
|
|
let appDataPath = app.getPath('appData')
|
|
|
|
|
if (process.platform === 'win32') {
|
|
|
|
|
const homeDir = os.homedir()
|
|
|
|
|
appDataPath = path.join(homeDir, 'AppData', 'Local')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let defaultJianyingDraftPath = path.resolve(
|
|
|
|
|
appDataPath,
|
|
|
|
|
'JianyingPro/User Data/Projects/com.lveditor.draft'
|
|
|
|
|
)
|
|
|
|
|
let rootMetaInfoPath = path.resolve(defaultJianyingDraftPath, 'root_meta_info.json')
|
|
|
|
|
if (!(await CheckFileOrDirExist(rootMetaInfoPath))) {
|
2025-09-12 14:52:28 +08:00
|
|
|
throw new Error(t("未找到剪映相关数据,请手动填写或选择"))
|
2025-08-19 14:33:59 +08:00
|
|
|
}
|
|
|
|
|
// 读取文件内容,判断是否是剪映的草稿地址
|
|
|
|
|
let fileContent = await fs.promises.readFile(rootMetaInfoPath, 'utf-8')
|
|
|
|
|
if (!ValidateJson(fileContent)) {
|
2025-09-12 14:52:28 +08:00
|
|
|
throw new Error(t('剪映草稿地址数据错误,请手动填写或选择'))
|
2025-08-19 14:33:59 +08:00
|
|
|
}
|
|
|
|
|
let jsonContent = JSON.parse(fileContent)
|
|
|
|
|
let all_draft_store = jsonContent.all_draft_store
|
|
|
|
|
if (all_draft_store && all_draft_store.length > 0) {
|
|
|
|
|
let draft_store = all_draft_store[0]
|
|
|
|
|
let draft_root_path = draft_store.draft_root_path
|
|
|
|
|
if (draft_root_path && !isEmpty(draft_root_path)) {
|
|
|
|
|
return successMessage(
|
|
|
|
|
draft_root_path,
|
2025-09-12 14:52:28 +08:00
|
|
|
t('成功'),
|
2025-08-19 14:33:59 +08:00
|
|
|
'SettingService_GetDefaultJianyingDraftPath'
|
|
|
|
|
)
|
|
|
|
|
} else {
|
2025-09-12 14:52:28 +08:00
|
|
|
throw new Error(t('剪映草稿地址数据错误,请手动填写或选择'))
|
2025-08-19 14:33:59 +08:00
|
|
|
}
|
|
|
|
|
} else {
|
2025-09-12 14:52:28 +08:00
|
|
|
throw new Error(t('剪映草稿地址数据错误,请手动填写或选择'))
|
2025-08-19 14:33:59 +08:00
|
|
|
}
|
|
|
|
|
} catch (error: any) {
|
|
|
|
|
return errorMessage(
|
2025-09-12 14:52:28 +08:00
|
|
|
t("获取默认剪映草稿地址失败,{error}", {
|
|
|
|
|
error: error.message
|
|
|
|
|
}),
|
2025-08-19 14:33:59 +08:00
|
|
|
'SettingService_GetDefaultJianyingDraftPath'
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
|
}
|