稳定测试版
This commit is contained in:
21
main/utils/paths.js
Normal file
21
main/utils/paths.js
Normal file
@@ -0,0 +1,21 @@
|
||||
// main/utils/paths.js
|
||||
const path = require('path')
|
||||
const { fileURLToPath } = require('node:url')
|
||||
const { app } = require('electron')
|
||||
|
||||
function normalizePath(targetPath, baseDir) {
|
||||
if (typeof targetPath !== 'string' || !targetPath.trim()) throw new Error('无效的路径参数')
|
||||
if (targetPath.startsWith('file://')) return fileURLToPath(new URL(targetPath))
|
||||
if (!path.isAbsolute(targetPath)) {
|
||||
const base = baseDir && typeof baseDir === 'string' ? baseDir : process.cwd()
|
||||
return path.resolve(base, targetPath)
|
||||
}
|
||||
return path.resolve(targetPath)
|
||||
}
|
||||
|
||||
function resolveResource(relPath) {
|
||||
const base = app.isPackaged ? process.resourcesPath : path.resolve(__dirname, '..')
|
||||
return path.join(base, relPath)
|
||||
}
|
||||
|
||||
module.exports = { normalizePath, resolveResource }
|
||||
Reference in New Issue
Block a user