change all cn to en to avoid annoying errors

This commit is contained in:
2026-05-20 20:43:42 -04:00
parent 39c0420835
commit 25301bd60e
5 changed files with 63 additions and 70 deletions

View File

@@ -3,36 +3,36 @@ param(
[string]$WorkDir = $null
)
# 1. 处理工作目录
# 1. Resolve work directory.
if ([string]::IsNullOrEmpty($WorkDir)) {
$WorkDir = $PSScriptRoot
} else {
# 如果 WorkDir 里包含变量(如 $env:APPDATA),展开它
# Expand variables in WorkDir, such as $env:APPDATA.
$WorkDir = $ExecutionContext.InvokeCommand.ExpandString($WorkDir)
}
# 确保目录存在,否则命令会报错
# Make sure the directory exists.
if (-not (Test-Path $WorkDir)) {
Write-Warning "`n[CMD] WARNING: The work dir does not exist, using ($WorkDir)"
$WorkDir = $PSScriptRoot
}
# 2. 处理命令中的环境变量
# 2. Expand variables in the command.
$ProjectRoot = Split-Path $PSScriptRoot -Parent
# === 替换 $PSScriptRoot 为实际的绝对路径 ===
# 注意:要处理反斜杠转义问题,直接用字符串替换最安全
# Replace $PSScriptRoot with the project root path.
# Direct string replacement is the safest option for backslashes.
if ($Command.Contains('$PSScriptRoot')) {
$Command = $Command.Replace('$PSScriptRoot', $ProjectRoot)
}
# 这一步很关键,让你可以写 "echo $env:USERNAME"
# This allows commands such as "echo $env:USERNAME".
$Command = $ExecutionContext.InvokeCommand.ExpandString($Command)
Write-Host "`n[CMD] Execute: $Command" -ForegroundColor Gray
# 3. 启动进程
# /c 表示执行完命令后关闭 cmd 窗口
# /s 开启参数的一般处理(忽略第一个和最后一个引号,为了兼容复杂引号情况)
# 3. Start cmd.exe.
# /c closes cmd after the command completes.
# /s enables cmd quote handling for complex command strings.
$processOptions = @{
FilePath = "cmd.exe"
ArgumentList = "/s", "/c", "`"$Command`""
@@ -45,10 +45,10 @@ $processOptions = @{
try {
$proc = Start-Process @processOptions
# 4. 检查退出代码 (ExitCode)
# 4. Check exit code.
if ($proc.ExitCode -ne 0) {
Write-Error "`n[CMD] Failed to execute, exit code: $($proc.ExitCode)"
}
} catch {
Write-Error "`n[CMD] Failed to start process: $_"
}
}

View File

@@ -7,35 +7,33 @@ param(
)
try {
# 1. 路径预处理:展开环境变量 (例如把 $env:APPDATA 变成 C:\Users\...\AppData\Roaming)
# 1. Expand variables in paths.
$ResolvedSource = $ExecutionContext.InvokeCommand.ExpandString($Source)
$ResolvedDest = $ExecutionContext.InvokeCommand.ExpandString($Destination)
# 2. 处理相对路径 (针对源文件)
# 如果源路径是相对路径 (./assets/...), 尝试将其转换为绝对路径
# 假设脚本是从项目根目录调用的
# 2. Resolve relative source paths from the project root.
if (-not (Test-Path $ResolvedSource) -and (Test-Path "$PWD\$ResolvedSource")) {
$ResolvedSource = Join-Path $PWD $ResolvedSource
}
# 3. 再次检查源文件是否存在
# 3. Make sure the source file exists.
if (-not (Test-Path $ResolvedSource -PathType Leaf)) {
Write-Warning "`n[FileCopy] [Skip] File not found: $ResolvedSource"
return # 退出脚本
return
}
# 4. 处理目标目录 (自动创建不存在的文件夹)
# 4. Create destination directory when needed.
$DestDir = Split-Path -Path $ResolvedDest -Parent
if (-not (Test-Path $DestDir)) {
Write-Host "`n[FileCopy] Create dir: $DestDir" -ForegroundColor DarkGray
New-Item -Path $DestDir -ItemType Directory -Force | Out-Null
}
# 5. 执行复制 (Force = 覆盖)
# 5. Copy file. Force overwrites existing files.
Copy-Item -Path $ResolvedSource -Destination $ResolvedDest -Force -ErrorAction Stop
Write-Host "`n[FileCopy] Success: $ResolvedDest" -ForegroundColor Green
} catch {
Write-Error "`n[FileCopy] Fail: $_"
}
}

View File

@@ -4,17 +4,15 @@ param(
)
try {
# 1. 路径预处理
# 展开环境变量 (虽然 .reg 路径通常是固定的,但支持一下没坏处)
# 1. Expand variables in the path.
$ResolvedPath = $ExecutionContext.InvokeCommand.ExpandString($Path)
# 2. 处理相对路径
# 如果路径是相对的 (./assets/...), 转换为绝对路径
# 2. Resolve relative paths from the project root.
if (-not (Test-Path $ResolvedPath) -and (Test-Path "$PWD\$ResolvedPath")) {
$ResolvedPath = Join-Path $PWD $ResolvedPath
}
# 3. 检查文件是否存在
# 3. Make sure the registry file exists.
if (-not (Test-Path $ResolvedPath)) {
Write-Warning "`n[RegImport] [Skip] Cannot find: $ResolvedPath"
return
@@ -22,8 +20,7 @@ try {
Write-Host "`n[RegImport] Importing: $(Split-Path $ResolvedPath -Leaf)" -ForegroundColor Gray
# 4. 调用 reg.exe 导入
# 使用 Start-Process 以获取退出代码
# 4. Import with reg.exe and capture the exit code.
$proc = Start-Process -FilePath "reg.exe" -ArgumentList "import", "`"$ResolvedPath`"" -Wait -PassThru -NoNewWindow
if ($proc.ExitCode -eq 0) {
@@ -34,4 +31,4 @@ try {
} catch {
Write-Error "`n[RegImport] Failed to start process: $_"
}
}