1- # Alist Manager Script for Windows
2- # Version: 3.57.0(仅首次安装后随机密码)
1+ param ($Action , $InstallPath )
32
43# -----------------------------
54# 自动检测 PowerShell 版本并设置输出编码
65$psVersion = $PSVersionTable.PSVersion.Major
6+
7+ # UTF-8 编码对象(无 BOM)
8+ $global :Utf8NoBom = New-Object System.Text.UTF8Encoding($false )
9+
710if ($psVersion -ge 7 ) {
811 chcp 65001 > $null
9- [Console ]::OutputEncoding = [ System.Text.Encoding ]::UTF8
12+ [Console ]::OutputEncoding = $ global :Utf8NoBom
1013 $EncName = " UTF-8"
1114} else {
1215 chcp 936 > $null
@@ -16,7 +19,6 @@ if ($psVersion -ge 7) {
1619Write-Host " 当前终端编码: $EncName " - ForegroundColor Yellow
1720# -----------------------------
1821
19- param ($Action , $InstallPath )
2022if (-not $Action ) { $Action = " menu" }
2123if (-not $InstallPath ) { $InstallPath = " C:\alist" }
2224
@@ -34,12 +36,22 @@ function Write-Info($msg, $color="White") {
3436 $validColors = @ (" Black" , " DarkBlue" , " DarkGreen" , " DarkCyan" , " DarkRed" ,
3537 " DarkMagenta" , " DarkYellow" , " Gray" , " DarkGray" , " Blue" ,
3638 " Green" , " Cyan" , " Red" , " Magenta" , " Yellow" , " White" )
39+
40+ # 转码输出,避免乱码
41+ $outMsg = [System.Text.Encoding ]::Default .GetString(
42+ [System.Text.Encoding ]::Convert(
43+ [System.Text.Encoding ]::UTF8,
44+ [Console ]::OutputEncoding,
45+ [System.Text.Encoding ]::UTF8.GetBytes($msg )
46+ )
47+ )
48+
3749 if ($validColors -contains $color ) {
3850 [Console ]::ForegroundColor = $color
39- [Console ]::WriteLine($msg )
51+ [Console ]::WriteLine($outMsg )
4052 [Console ]::ResetColor()
4153 } else {
42- [Console ]::WriteLine($msg )
54+ [Console ]::WriteLine($outMsg )
4355 }
4456}
4557
@@ -64,8 +76,6 @@ function Get-LatestVersion {
6476 }
6577}
6678
67- # -----------------------------
68- # 获取真实物理网卡 IPv4
6979function Get-LocalIP {
7080 $realNICs = Get-NetIPAddress - AddressFamily IPv4 | Where-Object {
7181 $_.IPAddress -ne " 127.0.0.1" -and
@@ -80,7 +90,6 @@ function Get-LocalIP {
8090 return $ip
8191}
8292
83- # -----------------------------
8493function Install-NSSM {
8594 if (-Not (Test-Path $nssmPath )) {
8695 $tmpZip = " $env: TEMP \nssm.zip"
@@ -123,7 +132,6 @@ function Install-Alist {
123132 $version = Get-LatestVersion
124133 Write-Info " 最新版本: $version " $Green
125134
126- # 官方镜像下载 URL(根据 CPU 架构)
127135 $filename = " alist-$version -windows-$arch .zip"
128136 $officialUrl = " https://alistgo.com/download/Alist/v$version /$filename "
129137 $tmpZip = " $env: TEMP \alist.zip"
@@ -132,7 +140,6 @@ function Install-Alist {
132140
133141 if (-not $success ) {
134142 Write-Info " 官方镜像下载失败!" $Yellow
135- # 提示用户选择 GitHub 下载
136143 Write-Info " 是否使用 GitHub 源下载?" $Green
137144 Write-Info " 1. 使用 GitHub 默认地址" $Green
138145 Write-Info " 2. 使用 GitHub 代理" $Green
@@ -157,13 +164,11 @@ function Install-Alist {
157164 }
158165 }
159166
160- # 解压
161167 Expand-Archive - Path $tmpZip - DestinationPath $InstallPath - Force
162168 Remove-Item $tmpZip - Force
163169 Write-Info " Alist 已安装到 $InstallPath " $Green
164170}
165171
166- # -----------------------------
167172function Invoke-AlistAdminRandom {
168173 if (-Not (Test-Path " $InstallPath \alist.exe" )) {
169174 throw " 未找到 $InstallPath \alist.exe,请先安装 Alist。"
@@ -185,7 +190,6 @@ function Invoke-AlistAdminRandom {
185190 return @ { Username = $username ; Password = $password ; Raw = $output }
186191}
187192
188- # -----------------------------
189193function Service-InstallAndStart {
190194 if (-Not (Test-Path " $InstallPath \alist.exe" )) {
191195 Write-Info " 请先安装 Alist 再注册服务" $Red
@@ -232,7 +236,6 @@ function Service-Remove {
232236}
233237function Service-Status { Install-NSSM ; & $nssmPath status $ServiceName }
234238
235- # -----------------------------
236239function Show-Menu {
237240 while ($true ) {
238241 Clear-Host
@@ -267,7 +270,6 @@ function Show-Menu {
267270 }
268271}
269272
270- # -----------------------------
271273switch ($Action ) {
272274 " install" { Install-Alist }
273275 " update" { Install-Alist }
0 commit comments