[patch] 修复CI/CD中的GBK编码问题
This commit is contained in:
@@ -43,47 +43,47 @@ class NSISInstaller:
|
||||
match = re.search(r'APP_VERSION\s*=\s*["\']([^"\']+)["\']', content)
|
||||
if match:
|
||||
version = match.group(1)
|
||||
print(f"📦 从 config.py 读取版本号: v{version}")
|
||||
print(f"Read version from config.py: v{version}")
|
||||
return version
|
||||
except Exception as e:
|
||||
print(f"⚠️ 读取版本号失败: {e},使用默认版本")
|
||||
print(f"WARNING: Failed to read version: {e}, using default version")
|
||||
|
||||
return "1.0.0"
|
||||
|
||||
def check_prerequisites(self):
|
||||
"""检查构建前提条件"""
|
||||
print("🔍 检查构建前提条件...")
|
||||
print("Checking build prerequisites...")
|
||||
|
||||
# 检查NSIS安装
|
||||
try:
|
||||
result = subprocess.run(['makensis', '/VERSION'],
|
||||
capture_output=True, text=True, check=True)
|
||||
nsis_version = result.stdout.strip()
|
||||
print(f"✅ NSIS 版本: {nsis_version}")
|
||||
print(f"NSIS version: {nsis_version}")
|
||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||
print("❌ 错误: 未找到NSIS或makensis命令")
|
||||
print(" 请从 https://nsis.sourceforge.io/Download 下载并安装NSIS")
|
||||
print(" 确保将NSIS添加到系统PATH环境变量")
|
||||
print("ERROR: NSIS or makensis command not found")
|
||||
print(" Please download and install NSIS from https://nsis.sourceforge.io/Download")
|
||||
print(" Make sure to add NSIS to system PATH")
|
||||
return False
|
||||
|
||||
# 检查dist目录
|
||||
if not self.dist_dir.exists():
|
||||
print(f"❌ 错误: 未找到构建输出目录 {self.dist_dir}")
|
||||
print(" 请先运行 build_production.py 构建应用程序")
|
||||
print(f"ERROR: Build output directory not found: {self.dist_dir}")
|
||||
print(" Please run build_production.py first")
|
||||
return False
|
||||
|
||||
# 检查主程序文件
|
||||
exe_path = self.dist_dir / self.exe_name
|
||||
if not exe_path.exists():
|
||||
print(f"❌ 错误: 未找到主程序文件 {exe_path}")
|
||||
print(f"ERROR: Main executable not found: {exe_path}")
|
||||
return False
|
||||
|
||||
print(f"✅ 找到主程序: {exe_path}")
|
||||
print(f"Found main executable: {exe_path}")
|
||||
return True
|
||||
|
||||
def prepare_assets(self):
|
||||
"""准备安装包资源文件"""
|
||||
print("📁 准备资源文件...")
|
||||
print("Preparing asset files...")
|
||||
|
||||
# 创建assets目录
|
||||
self.assets_dir.mkdir(exist_ok=True)
|
||||
@@ -107,14 +107,14 @@ class NSISInstaller:
|
||||
img = Image.open(icon_source)
|
||||
ico_path = self.assets_dir / "icon.ico"
|
||||
img.save(ico_path, format='ICO', sizes=[(16,16), (32,32), (48,48), (64,64)])
|
||||
print(f"✅ 转换主程序图标: {icon_source.name} -> icon.ico")
|
||||
print(f"Converted main icon: {icon_source.name} -> icon.ico")
|
||||
icon_found = True
|
||||
break
|
||||
except ImportError:
|
||||
print("⚠️ 未安装PIL库,跳过图标转换")
|
||||
print("WARNING: PIL library not installed, skipping icon conversion")
|
||||
break
|
||||
except Exception as e:
|
||||
print(f"⚠️ 主程序图标转换失败: {e}")
|
||||
print(f"WARNING: Main icon conversion failed: {e}")
|
||||
continue
|
||||
|
||||
# 转换卸载程序图标
|
||||
@@ -125,17 +125,17 @@ class NSISInstaller:
|
||||
img = Image.open(uninstall_icon_source)
|
||||
uninstall_ico_path = self.assets_dir / "uninstall_icon.ico"
|
||||
img.save(uninstall_ico_path, format='ICO', sizes=[(16,16), (32,32), (48,48), (64,64)])
|
||||
print(f"✅ 转换卸载程序图标: {uninstall_icon_source.name} -> uninstall_icon.ico")
|
||||
print(f"Converted uninstall icon: {uninstall_icon_source.name} -> uninstall_icon.ico")
|
||||
uninstall_icon_found = True
|
||||
except ImportError:
|
||||
print("⚠️ 未安装PIL库,跳过卸载图标转换")
|
||||
print("WARNING: PIL library not installed, skipping uninstall icon conversion")
|
||||
except Exception as e:
|
||||
print(f"⚠️ 卸载程序图标转换失败: {e}")
|
||||
print(f"WARNING: Uninstall icon conversion failed: {e}")
|
||||
else:
|
||||
print("⚠️ 未找到卸载程序专用图标,将使用主程序图标")
|
||||
print("WARNING: Uninstall icon not found, will use main icon")
|
||||
|
||||
if not icon_found:
|
||||
print("⚠️ 未找到主程序图标文件,将使用默认图标")
|
||||
print("WARNING: Main icon not found, will use default icon")
|
||||
|
||||
return {
|
||||
'main_icon': icon_found,
|
||||
@@ -144,13 +144,13 @@ class NSISInstaller:
|
||||
|
||||
def generate_nsis_script(self, icon_info):
|
||||
"""生成NSIS安装脚本"""
|
||||
print("📝 生成NSIS安装脚本...")
|
||||
print("Generating NSIS installer script...")
|
||||
|
||||
# 标准化安装包命名(不带时间戳,便于固定下载地址)
|
||||
installer_name = f"{self.app_name_en}_Setup_v{self.app_version}.exe"
|
||||
# 示例: ShuiDi_AI_Assistant_Setup_v1.4.12.exe
|
||||
|
||||
print(f"📦 安装包名称: {installer_name}")
|
||||
print(f"Installer name: {installer_name}")
|
||||
|
||||
nsis_content = f'''# 水滴AI客服智能助手 NSIS 安装脚本
|
||||
# 自动生成于 {datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
|
||||
@@ -262,7 +262,7 @@ SectionEnd
|
||||
with open(self.nsis_script, 'w', encoding='utf-8-sig') as f:
|
||||
f.write(nsis_content)
|
||||
|
||||
print(f"✅ NSIS脚本已生成: {self.nsis_script}")
|
||||
print(f"NSIS script generated: {self.nsis_script}")
|
||||
return installer_name
|
||||
|
||||
def create_license_file(self):
|
||||
@@ -287,11 +287,11 @@ SectionEnd
|
||||
with open(license_file, 'w', encoding='utf-8-sig') as f:
|
||||
f.write(license_content)
|
||||
|
||||
print(f"✅ 许可证文件已创建: {license_file}")
|
||||
print(f"License file created: {license_file}")
|
||||
|
||||
def build_installer(self):
|
||||
"""构建安装包"""
|
||||
print("🚀 开始构建NSIS安装包...")
|
||||
print("Building NSIS installer...")
|
||||
|
||||
# 创建输出目录
|
||||
self.output_dir.mkdir(exist_ok=True)
|
||||
@@ -302,22 +302,22 @@ SectionEnd
|
||||
result = subprocess.run(cmd, cwd=str(self.script_dir),
|
||||
capture_output=True, text=True, check=True)
|
||||
|
||||
print("✅ NSIS编译成功")
|
||||
print("NSIS compilation successful")
|
||||
if result.stdout:
|
||||
print("NSIS输出:")
|
||||
print("NSIS output:")
|
||||
print(result.stdout)
|
||||
|
||||
return True
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print("❌ NSIS编译失败")
|
||||
print(f"错误信息: {e.stderr}")
|
||||
print("ERROR: NSIS compilation failed")
|
||||
print(f"Error message: {e.stderr}")
|
||||
return False
|
||||
|
||||
def run(self):
|
||||
"""执行完整的构建流程"""
|
||||
print("=" * 60)
|
||||
print(f"🔧 {self.app_name} 安装包构建工具")
|
||||
print(f"Installer Build Tool for {self.app_name}")
|
||||
print("=" * 60)
|
||||
|
||||
try:
|
||||
@@ -343,18 +343,18 @@ SectionEnd
|
||||
if installer_path.exists():
|
||||
installer_size = installer_path.stat().st_size / (1024 * 1024)
|
||||
print("\n" + "=" * 60)
|
||||
print("🎉 安装包构建成功!")
|
||||
print(f"📁 安装包位置: {installer_path}")
|
||||
print(f"📏 文件大小: {installer_size:.1f} MB")
|
||||
print("🚀 可以直接分发给用户使用")
|
||||
print("Installer build completed successfully!")
|
||||
print(f"Installer location: {installer_path}")
|
||||
print(f"File size: {installer_size:.1f} MB")
|
||||
print("Ready to distribute to users")
|
||||
print("=" * 60)
|
||||
return True
|
||||
else:
|
||||
print("❌ 安装包文件未找到")
|
||||
print("ERROR: Installer file not found")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 构建过程出错: {e}")
|
||||
print(f"ERROR: Build process error: {e}")
|
||||
return False
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user