C端打包修复不能在中文路径下启动的问题

This commit is contained in:
2026-04-02 20:51:19 +08:00
parent ad02fac4ff
commit 926b85bf8d
19 changed files with 474 additions and 373 deletions

View File

@@ -45,11 +45,11 @@ function getScriptsPath(scriptName) {
}
// 延迟加载 scripts
let MySQLServiceManager, JavaRunner, ConfigGenerator, PortChecker, StartupManager, LogWindowManager;
let MySQLProcessManager, JavaRunner, ConfigGenerator, PortChecker, StartupManager, LogWindowManager;
function loadScripts() {
if (!MySQLServiceManager) {
MySQLServiceManager = require(getScriptsPath('mysql-service-manager'));
if (!MySQLProcessManager) {
MySQLProcessManager = require(getScriptsPath('mysql-process-manager'));
JavaRunner = require(getScriptsPath('java-runner'));
ConfigGenerator = require(getScriptsPath('config-generator'));
PortChecker = require(getScriptsPath('port-checker'));
@@ -60,7 +60,7 @@ function loadScripts() {
class Lifecycle {
constructor() {
this.mysqlServiceManager = null;
this.mysqlProcessManager = null;
this.javaRunner = null;
this.startupManager = null;
this.logWindowManager = null;
@@ -94,26 +94,26 @@ class Lifecycle {
this.startupManager.updateProgress('init');
await this.sleep(500);
// 步骤2-4: 确保 MySQL 服务运行
// 步骤2-4: 确保 MySQL 进程运行
this.logWindowManager.addLog('system', '▶ 步骤4: 检查 MySQL 配置...');
logger.info('[lifecycle] MySQL config check - enable:', config.mysql?.enable, 'autoStart:', config.mysql?.autoStart);
if (config.mysql && config.mysql.enable && config.mysql.autoStart) {
this.startupManager.updateProgress('check-mysql-port');
this.logWindowManager.addLog('system', '▶ 步骤5: 启动 MySQL 服务管理器...');
this.logWindowManager.addLog('system', '▶ 步骤5: 启动 MySQL 进程管理器...');
this.mysqlServiceManager = new MySQLServiceManager(this.logWindowManager);
this.logWindowManager.addLog('system', '正在检查 MySQL 服务状态...');
this.mysqlProcessManager = new MySQLProcessManager(this.logWindowManager);
this.logWindowManager.addLog('system', '正在检查 MySQL 进程状态...');
try {
// 使用服务管理器确保MySQL服务运行
this.logWindowManager.addLog('system', '▶ 步骤6: 确保 MySQL 服务运行中...');
this.mysqlPort = await this.mysqlServiceManager.ensureServiceRunning(
// 使用进程管理器确保 MySQL 进程运行
this.logWindowManager.addLog('system', '▶ 步骤6: 确保 MySQL 进程运行中...');
this.mysqlPort = await this.mysqlProcessManager.ensureServiceRunning(
PortChecker.findAvailablePort.bind(PortChecker),
PortChecker.waitForPort.bind(PortChecker)
);
logger.info(`[lifecycle] MySQL service running on port: ${this.mysqlPort}`);
logger.info(`[lifecycle] MySQL process running on port: ${this.mysqlPort}`);
this.logWindowManager.addLog('success', `✓ MySQL 服务已就绪,端口: ${this.mysqlPort}`);
this.startupManager.updateProgress('wait-mysql', { mysqlPort: this.mysqlPort });
await this.sleep(500);
@@ -201,7 +201,7 @@ class Lifecycle {
dataPath: dataPath
});
await this.startSpringBoot(configPath);
await this.startSpringBoot(configPath, dataPath);
// 步骤8: 等待 Spring Boot 就绪
this.logWindowManager.addLog('system', '▶ 步骤11: 等待 Spring Boot 就绪最多60秒...');
@@ -376,14 +376,14 @@ class Lifecycle {
}
// 停止 MySQL 进程(进程模式)
if (this.mysqlServiceManager) {
if (this.mysqlProcessManager) {
try {
logger.info('[lifecycle] Stopping MySQL process...');
if (this.logWindowManager && this.logWindowManager.logWindow && !this.logWindowManager.logWindow.isDestroyed()) {
this.logWindowManager.addLog('system', '正在停止 MySQL...');
}
await this.mysqlServiceManager.stopMySQLProcess();
await this.mysqlProcessManager.stopMySQLProcess();
logger.info('[lifecycle] MySQL process stopped');
if (this.logWindowManager && this.logWindowManager.logWindow && !this.logWindowManager.logWindow.isDestroyed()) {
@@ -419,7 +419,7 @@ class Lifecycle {
/**
* 启动 Spring Boot 应用
*/
async startSpringBoot(configPath) {
async startSpringBoot(configPath, dataPath) {
try {
logger.info('[lifecycle] Starting Spring Boot application...');
this.logWindowManager.addLog('java', '正在启动 Spring Boot 应用...');
@@ -434,12 +434,6 @@ class Lifecycle {
? path.join(__dirname, '..', 'build', 'extraResources', 'java', 'entrance.jar')
: path.join(process.resourcesPath, 'extraResources', 'java', 'entrance.jar');
// 获取日志路径(与 config-generator.js 中的 dataPath 保持一致)
const isDev2 = !process.resourcesPath;
const baseDir = isDev2
? path.join(__dirname, '..', '..')
: path.dirname(process.resourcesPath);
const dataPath = path.join(baseDir, 'NPQS9100_Data');
const logPath = path.join(dataPath, 'logs');
const javaProcess = this.javaRunner.runSpringBoot(jarPath, configPath, {