@@ -17,74 +17,7 @@ import { OPENCLAW_USER_DIR } from '../../shared/constants.js'
1717export function getInstallDir ( ) : string {
1818 if ( app . isPackaged ) {
1919 return path . dirname ( app . getPath ( 'exe' ) )
20- }
21- return process . cwd ( )
22- }
23-
24- /**
25- * 获取 OpenClaw 用户数据目录(%USERPROFILE%\.openclaw)
26- */
27- export function getUserDataDir ( ) : string {
28- return path . join ( os . homedir ( ) , OPENCLAW_USER_DIR )
29- }
30-
31- function resolveDevResourcePath ( resourceName : 'node' | 'openclaw' ) : string {
32- const installDir = getInstallDir ( )
33- const resourcesPath = path . join ( installDir , 'resources' , resourceName )
34- const resourceReady =
35- resourceName === 'node'
36- ? fs . existsSync ( path . join ( resourcesPath , 'node.exe' ) )
37- : fs . existsSync ( path . join ( resourcesPath , 'openclaw.mjs' ) )
38- if ( resourceReady ) {
39- return resourcesPath
40- }
41- return path . join ( installDir , 'build' , resourceName )
42- }
43-
44- export function getBundledOpenClawDir ( ) : string {
45- if ( app . isPackaged ) {
46- return path . join ( getInstallDir ( ) , 'resources' , 'openclaw' )
47- }
48- return resolveDevResourcePath ( 'openclaw' )
49- }
50-
51- /**
52- * 获取捆绑 Node.js 的 node.exe 路径
53- * 打包后:{installDir}/resources/node/node.exe
54- */
55- export function getBundledNodePath ( ) : string {
56- if ( app . isPackaged ) {
57- return path . join ( getInstallDir ( ) , 'resources' , 'node' , 'node.exe' )
58- }
59- return path . join ( resolveDevResourcePath ( 'node' ) , 'node.exe' )
60- }
61-
62- /**
63- * 获取捆绑 OpenClaw 的 openclaw.mjs 路径
64- * 打包后:{installDir}/resources/openclaw/openclaw.mjs
65- */
66- export function getBundledOpenClawPath ( ) : string {
67- return path . join ( getBundledOpenClawDir ( ) , 'openclaw.mjs' )
68- }
69- /**
70- * 路径工具 — 安装目录、用户数据目录、捆绑资源路径
71- * 与 constants.ts 配合使用
72- */
73-
74- import { app } from 'electron'
75- import path from 'path'
76- import os from 'os'
77- import fs from 'node:fs'
78- import { OPENCLAW_USER_DIR } from '../../shared/constants.js'
79-
80- /**
81- * 获取应用安装目录
82- * - 打包后:exe 所在目录
83- * - 开发时:项目根目录(process.cwd)
84- */
85- export function getInstallDir ( ) : string {
86- if ( app . isPackaged ) {
87- return path . dirname ( app . getPath ( 'exe' ) )
20+
8821 }
8922 return process . cwd ( )
9023}
0 commit comments