change all cn to en to avoid annoying errors
This commit is contained in:
55
bin/main.ps1
55
bin/main.ps1
@@ -1,15 +1,15 @@
|
||||
# 设置严格模式,遇到错误停止,防止错误的命令雪崩
|
||||
# Stop on errors to avoid cascading failures.
|
||||
$ErrorActionPreference = "Stop"
|
||||
#Set-StrictMode -Version Latest
|
||||
|
||||
# === 1. 加载依赖库 ===
|
||||
# 确保 lib 目录存在
|
||||
# === 1. Check dependencies ===
|
||||
# Make sure the lib directory exists.
|
||||
if (-not (Test-Path "$PSScriptRoot\..\lib")) {
|
||||
Write-Error "Cannot find .\lib, some files missing."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# === 2. 读取配置 ===
|
||||
# === 2. Read configuration ===
|
||||
$jsonPath = "$PSScriptRoot\apps.json"
|
||||
if (-not (Test-Path $jsonPath)) {
|
||||
Write-Error "Cannot find: $jsonPath"
|
||||
@@ -17,7 +17,7 @@ if (-not (Test-Path $jsonPath)) {
|
||||
}
|
||||
|
||||
Write-Host "Reading configurations..." -ForegroundColor Cyan
|
||||
# 使用 UTF8 读取防止中文乱码
|
||||
# Read as UTF-8.
|
||||
$apps = Get-Content $jsonPath -Encoding UTF8 | ConvertFrom-Json
|
||||
$forcePostInstall = $false
|
||||
|
||||
@@ -44,14 +44,14 @@ function Unblock-WinGetCache {
|
||||
}
|
||||
}
|
||||
|
||||
# === 2.1 加载外部开关配置 (selection.ini) ===
|
||||
# 尝试查找根目录下的 selection.ini (位于 bin 的上一级)
|
||||
# === 2.1 Load selection.ini overrides ===
|
||||
# selection.ini is located in the project root, one level above bin.
|
||||
$selectionPath = Join-Path (Split-Path $PSScriptRoot -Parent) "selection.ini"
|
||||
|
||||
if (Test-Path $selectionPath) {
|
||||
Write-Host "Loading selection overrides from selection.ini..." -ForegroundColor Cyan
|
||||
try {
|
||||
# 创建哈希表分别存储 App 开关和全局选项
|
||||
# Store app switches and global options separately.
|
||||
$selectionConfig = @{}
|
||||
$optionsConfig = @{}
|
||||
$currentSection = ""
|
||||
@@ -71,7 +71,7 @@ if (Test-Path $selectionPath) {
|
||||
continue
|
||||
}
|
||||
|
||||
# 按第一个等号分割,限制分割次数为 2
|
||||
# Split on the first equals sign only.
|
||||
$parts = $line -split '=', 2
|
||||
if ($parts.Count -eq 2) {
|
||||
$key = $parts[0].Trim()
|
||||
@@ -89,10 +89,10 @@ if (Test-Path $selectionPath) {
|
||||
$forcePostInstall = $optionsConfig["ForcePostInstall"] -eq "1"
|
||||
}
|
||||
|
||||
# 应用配置
|
||||
# Apply app enabled overrides.
|
||||
foreach ($app in $apps) {
|
||||
if ($selectionConfig.ContainsKey($app.Name)) {
|
||||
# 转换为整数 1 或 0
|
||||
# Convert to integer 1 or 0.
|
||||
$app.Enabled = [int]$selectionConfig[$app.Name]
|
||||
}
|
||||
}
|
||||
@@ -101,16 +101,16 @@ if (Test-Path $selectionPath) {
|
||||
}
|
||||
}
|
||||
|
||||
# === 2.2 启用本地 Manifest 安装 ===
|
||||
# winget install --manifest 需要先启用 LocalManifestFiles,重复执行不会影响后续安装。
|
||||
# === 2.2 Enable local manifest installation ===
|
||||
# winget install --manifest requires LocalManifestFiles. Re-running this is harmless.
|
||||
Write-Host "Enabling winget local manifest support..." -ForegroundColor Cyan
|
||||
winget settings --enable LocalManifestFiles
|
||||
|
||||
# === 3. 主循环 ===
|
||||
# === 3. Main loop ===
|
||||
foreach ($app in $apps) {
|
||||
if ($app.Enabled -ne 1) {
|
||||
Write-Host "[Skipping] $($app.Name)" -ForegroundColor DarkGray
|
||||
continue # 立即结束本次循环,进入下一个软件
|
||||
continue # Skip this app.
|
||||
}
|
||||
|
||||
Write-Host "`n==========================================" -ForegroundColor Cyan
|
||||
@@ -118,10 +118,10 @@ foreach ($app in $apps) {
|
||||
Write-Host "=========================================="
|
||||
|
||||
if ($app.Id -eq "System.Config") {
|
||||
# 如果是纯配置项,直接打印跳过信息
|
||||
# This is a configuration-only item.
|
||||
Write-Host "[System Config] Skipping install..." -ForegroundColor Magenta
|
||||
} else {
|
||||
# --- 步骤 A: Winget 安装 ---
|
||||
# --- Step A: Winget install ---
|
||||
$manifestPath = $null
|
||||
$manifestTempDir = $null
|
||||
|
||||
@@ -173,8 +173,7 @@ foreach ($app in $apps) {
|
||||
# "--scope", "machine"
|
||||
)
|
||||
|
||||
# [版本检查逻辑]
|
||||
# 检查 Version 是否存在且不为空字符串
|
||||
# Add Version only when configured.
|
||||
if (-not [string]::IsNullOrWhiteSpace($app.Version)) {
|
||||
Write-Host "-> Version: $($app.Version)"
|
||||
$wingetArgs += "-v"
|
||||
@@ -186,7 +185,7 @@ foreach ($app in $apps) {
|
||||
|
||||
Write-Host "-> Installing via winget..."
|
||||
|
||||
# 执行安装
|
||||
# Run install command.
|
||||
try {
|
||||
& winget @wingetArgs
|
||||
$exitCode = $LASTEXITCODE
|
||||
@@ -204,7 +203,7 @@ foreach ($app in $apps) {
|
||||
}
|
||||
}
|
||||
|
||||
# 检查安装结果 (0=成功, -1978335189=已安装)
|
||||
# Check install result (0=success, -1978335189=already installed).
|
||||
if ($exitCode -eq 0) {
|
||||
Write-Host "[Success]" -ForegroundColor Green
|
||||
} elseif ($exitCode -eq -1978335189) {
|
||||
@@ -212,22 +211,22 @@ foreach ($app in $apps) {
|
||||
Write-Host "[Skip] Already installed, running PostInstall..." -ForegroundColor Yellow
|
||||
} else {
|
||||
Write-Host "[Skip] Already installed" -ForegroundColor Yellow
|
||||
continue # 已经安装的为了避免覆盖配置,也就不配置了
|
||||
continue # Skip PostInstall when already installed.
|
||||
}
|
||||
} else {
|
||||
Write-Error "[Fail] Error code: $exitCode"
|
||||
continue # 安装失败则跳过后续配置
|
||||
continue # Skip PostInstall on install failure.
|
||||
}
|
||||
}
|
||||
|
||||
# --- 步骤 B: PostInstall 配置 ---
|
||||
# --- Step B: PostInstall configuration ---
|
||||
if ($app.PostInstall -and $app.PostInstall.Count -gt 0) {
|
||||
Write-Host "`n-> Configuring..." -ForegroundColor Cyan
|
||||
|
||||
$stepIndex = 0
|
||||
foreach ($action in $app.PostInstall) {
|
||||
|
||||
# [间隔逻辑] 如果这不是第一步,先等待 2 秒
|
||||
# Wait between PostInstall steps.
|
||||
if ($stepIndex -gt 0) {
|
||||
Write-Host "(Waiting 2 seconds...)" -ForegroundColor DarkGray
|
||||
Start-Sleep -Seconds 2
|
||||
@@ -236,20 +235,20 @@ foreach ($app in $apps) {
|
||||
try {
|
||||
switch ($action.Type) {
|
||||
|
||||
# 1. 复制文件
|
||||
# 1. Copy file.
|
||||
"FileCopy" {
|
||||
& "$PSScriptRoot\..\lib\invoke-filecopy.ps1" `
|
||||
-Source $action.Source `
|
||||
-Destination $action.Destination
|
||||
}
|
||||
|
||||
# 2. 导入注册表
|
||||
# 2. Import registry file.
|
||||
"RegImport" {
|
||||
& "$PSScriptRoot\..\lib\invoke-regimport.ps1" `
|
||||
-Path $action.Path
|
||||
}
|
||||
|
||||
# 3. 执行 CMD
|
||||
# 3. Run command.
|
||||
"Command" {
|
||||
& "$PSScriptRoot\..\lib\invoke-cmdexec.ps1" `
|
||||
-Command $action.Command `
|
||||
|
||||
Reference in New Issue
Block a user