MCPcopy Index your code
hub / github.com/ZToolsCenter/ZTools / getUpdatePaths

Method getUpdatePaths

src/main/api/updater.ts:265–319  ·  view source on GitHub ↗

* 获取更新路径配置

(extractPath: string)

Source from the content-addressed store, hash-verified

263 * 获取更新路径配置
264 */
265 private async getUpdatePaths(extractPath: string): Promise<UpdatePaths> {
266 const isMac = process.platform === 'darwin'
267 const isWin = process.platform === 'win32'
268 const appPath = process.execPath
269
270 const asarSrc = path.join(extractPath, 'app.asar')
271 const unpackedSrc = path.join(extractPath, 'app.asar.unpacked')
272
273 let updaterPath = ''
274 let asarDst = ''
275 let unpackedDst = ''
276
277 if (isMac) {
278 const contentsDir = path.dirname(path.dirname(appPath))
279 const resourcesDir = path.join(contentsDir, 'Resources')
280
281 if (!app.isPackaged) {
282 const safeArch = process.arch === 'arm64' ? 'arm64' : 'amd64'
283 updaterPath = path.join(app.getAppPath(), `updater/mac-${safeArch}/ztools-updater`)
284 } else {
285 updaterPath = path.join(path.dirname(appPath), 'ztools-updater')
286 }
287
288 asarDst = path.join(resourcesDir, 'app.asar')
289 unpackedDst = path.join(resourcesDir, 'app.asar.unpacked')
290 } else if (isWin) {
291 const appDir = path.dirname(appPath)
292 const agentPath = path.join(appDir, 'ztools-agent.exe')
293 const oldUpdaterPath = path.join(appDir, 'ztools-updater.exe')
294
295 // 兼容旧版本:如果 ztools-agent.exe 不存在,尝试查找并重命名 ztools-updater.exe
296 try {
297 await fs.access(agentPath)
298 updaterPath = agentPath
299 } catch {
300 // ztools-agent.exe 不存在,尝试查找旧版本
301 try {
302 await fs.access(oldUpdaterPath)
303 // 找到旧版本,重命名为新版本
304 await fs.rename(oldUpdaterPath, agentPath)
305 console.log('[Updater] 已将 ztools-updater.exe 重命名为 ztools-agent.exe')
306 updaterPath = agentPath
307 } catch {
308 // 两个文件都不存在,使用默认路径(后续会报错)
309 updaterPath = agentPath
310 }
311 }
312
313 const resourcesDir = path.join(appDir, 'resources')
314 asarDst = path.join(resourcesDir, 'app.asar')
315 unpackedDst = path.join(resourcesDir, 'app.asar.unpacked')
316 }
317
318 return { updaterPath, asarSrc, asarDst, unpackedSrc, unpackedDst, appPath }
319 }
320
321 /**
322 * 启动 updater 并退出应用

Callers 2

startUpdateMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected