mirror of
https://github.com/YILS-LIN/short-video-factory.git
synced 2025-11-25 03:15:03 +08:00
30 lines
738 B
TypeScript
30 lines
738 B
TypeScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
import { app } from 'electron'
|
|
|
|
// import packageJson from '~/package.json'
|
|
|
|
/**
|
|
* 生成有序的唯一文件名,用于处理文件已存在的情况
|
|
*/
|
|
export function generateUniqueFileName(filePath: string): string {
|
|
const dir = path.dirname(filePath)
|
|
const ext = path.extname(filePath)
|
|
const baseName = path.basename(filePath, ext)
|
|
let counter = 1
|
|
let newPath = filePath
|
|
|
|
while (fs.existsSync(newPath)) {
|
|
newPath = path.join(dir, `${baseName}(${counter})${ext}`)
|
|
counter++
|
|
}
|
|
return newPath
|
|
}
|
|
|
|
/**
|
|
* 获取软件的临时文件存储路径
|
|
*/
|
|
export function getAppTempPath() {
|
|
return path.join(app.getPath('temp'), app.name).replace(/\\/g, '/')
|
|
}
|