- 主进程新增 CrashReporter 捕获崩溃信息,提升诊断能力 - 优化 ipcMain 游戏扫描进度事件,加入节流防止 IPC 风暴 - 扫描平台分工重构,支持并发执行,添加执行日志和错误捕获 - 完善扫描结果去重逻辑,优先基于标准化安装目录合并游戏条目 - 增加未捕获异常、渲染进程退出和子进程退出日志,提升稳定性监控 - 更新日志模块,错误级日志立即同步落盘,降低闪退日志丢失风险 - 延长日志落盘监听事件,兼容多种退出信号安全清理日志 - 主进程窗口配置修改,始终保留调试工具,提高开发调试便捷性 - 优化扫描服务代码注释和参数说明,提升可维护性和易读性
84 lines
2.8 KiB
TypeScript
84 lines
2.8 KiB
TypeScript
import fs from 'fs-extra'
|
|
import os from 'os'
|
|
import path from 'path'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import { collectExePaths, pickRelatedExecutables } from '../../electron/services/scanners/utils'
|
|
|
|
const tempRoots: string[] = []
|
|
|
|
afterEach(async () => {
|
|
for (const root of tempRoots) {
|
|
await fs.remove(root)
|
|
}
|
|
tempRoots.length = 0
|
|
})
|
|
|
|
describe('scanner utils', () => {
|
|
it('keeps root executable scanning when directory entry count is very large', async () => {
|
|
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'lagzero-scanner-utils-'))
|
|
tempRoots.push(tempRoot)
|
|
|
|
const gameRoot = path.join(tempRoot, 'BigGame')
|
|
await fs.ensureDir(gameRoot)
|
|
|
|
const chunks = 32
|
|
const totalFiles = 3001
|
|
const perChunk = Math.ceil(totalFiles / chunks)
|
|
|
|
for (let c = 0; c < chunks; c += 1) {
|
|
const writes: Promise<void>[] = []
|
|
const start = c * perChunk
|
|
const end = Math.min(totalFiles, (c + 1) * perChunk)
|
|
for (let i = start; i < end; i += 1) {
|
|
writes.push(fs.writeFile(path.join(gameRoot, `dummy_${i}.tmp`), ''))
|
|
}
|
|
await Promise.all(writes)
|
|
}
|
|
|
|
const gameExe = path.join(gameRoot, 'BigGame.exe')
|
|
await fs.writeFile(gameExe, '')
|
|
|
|
const exes = await collectExePaths(gameRoot, 1)
|
|
const names = exes.map((e) => path.basename(e).toLowerCase())
|
|
|
|
expect(names).toContain('biggame.exe')
|
|
})
|
|
|
|
it('respects maxDepth boundary without scanning one level deeper', async () => {
|
|
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'lagzero-scanner-depth-'))
|
|
tempRoots.push(tempRoot)
|
|
|
|
const gameRoot = path.join(tempRoot, 'DepthGame')
|
|
const depth2Dir = path.join(gameRoot, 'Binaries')
|
|
const depth3Dir = path.join(depth2Dir, 'Win64')
|
|
|
|
await fs.ensureDir(depth3Dir)
|
|
await fs.writeFile(path.join(depth2Dir, 'DepthGame.exe'), '')
|
|
await fs.writeFile(path.join(depth3Dir, 'DepthGame-Win64.exe'), '')
|
|
|
|
const exes = await collectExePaths(gameRoot, 2)
|
|
const names = exes.map((e) => path.basename(e).toLowerCase())
|
|
|
|
expect(names).toContain('depthgame.exe')
|
|
expect(names).not.toContain('depthgame-win64.exe')
|
|
})
|
|
|
|
it('filters obvious archive helper executables from selected process names', async () => {
|
|
const tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), 'lagzero-scanner-pick-'))
|
|
tempRoots.push(tempRoot)
|
|
|
|
const gameRoot = path.join(tempRoot, 'Cyberpunk 2077')
|
|
await fs.ensureDir(gameRoot)
|
|
|
|
await fs.writeFile(path.join(gameRoot, 'Cyberpunk2077.exe'), '')
|
|
await fs.writeFile(path.join(gameRoot, 'REDprelauncher.exe'), '')
|
|
await fs.writeFile(path.join(gameRoot, '7za.exe'), '')
|
|
|
|
const exes = await pickRelatedExecutables(gameRoot, 'Cyberpunk 2077')
|
|
const names = exes.map((e) => path.basename(e).toLowerCase())
|
|
|
|
expect(names).toContain('cyberpunk2077.exe')
|
|
expect(names).not.toContain('7za.exe')
|
|
})
|
|
})
|