11# Auto-elevate to admin rights if not already running as admin
22if (-NOT ([Security.Principal.WindowsPrincipal ][Security.Principal.WindowsIdentity ]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole ] " Administrator" )) {
33 Write-Host " Requesting administrator privileges..."
4- Start-Process powershell.exe " -NoProfile -ExecutionPolicy Bypass -File `" $PSCommandPath `" " - Verb RunAs
4+ $arguments = " -NoProfile -ExecutionPolicy Bypass -File `" $PSCommandPath `" -ExecutionFromElevated"
5+ Start-Process powershell.exe - ArgumentList $arguments - Verb RunAs
56 Exit
67}
78
@@ -30,7 +31,7 @@ $EN_MESSAGES = @(
3031 " Adding to PATH..." ,
3132 " Cleaning up..." ,
3233 " Installation completed successfully!" ,
33- " You can now use 'cursor-id-modifier' from any terminal (you may need to restart your terminal first) " ,
34+ " You can now use 'cursor-id-modifier' directly " ,
3435 " Checking for running Cursor instances..." ,
3536 " Found running Cursor processes. Attempting to close them..." ,
3637 " Successfully closed all Cursor instances" ,
@@ -53,7 +54,7 @@ $CN_MESSAGES = @(
5354 " 正在添加到PATH..." ,
5455 " 正在清理..." ,
5556 " 安装成功完成!" ,
56- " 现在可以在任何终端中使用 'cursor-id-modifier' 了(可能需要重启终端) " ,
57+ " 现在可以直接使用 'cursor-id-modifier' 了" ,
5758 " 正在检查运行中的Cursor进程..." ,
5859 " 发现正在运行的Cursor进程,尝试关闭..." ,
5960 " 成功关闭所有Cursor实例" ,
@@ -133,6 +134,94 @@ function Get-LatestVersion {
133134 return $release.tag_name
134135}
135136
137+ # 在文件开头添加日志函数
138+ function Write-Log {
139+ param (
140+ [string ]$Message ,
141+ [string ]$Level = " INFO"
142+ )
143+ $timestamp = Get-Date - Format " yyyy-MM-dd HH:mm:ss"
144+ $logMessage = " [$timestamp ] [$Level ] $Message "
145+ $logFile = " $env: TEMP \cursor-id-modifier-install.log"
146+ Add-Content - Path $logFile - Value $logMessage
147+
148+ # 同时输出到控制台
149+ switch ($Level ) {
150+ " ERROR" { Write-Error $Message }
151+ " WARNING" { Write-Warning $Message }
152+ " SUCCESS" { Write-Success $Message }
153+ default { Write-Status $Message }
154+ }
155+ }
156+
157+ # 添加安装前检查函数
158+ function Test-Prerequisites {
159+ Write-Log " Checking prerequisites..." " INFO"
160+
161+ # 检查PowerShell版本
162+ if ($PSVersionTable.PSVersion.Major -lt 5 ) {
163+ Write-Log " PowerShell 5.0 or higher is required" " ERROR"
164+ return $false
165+ }
166+
167+ # 检查网络连接
168+ try {
169+ $testConnection = Test-Connection - ComputerName " github.com" - Count 1 - Quiet
170+ if (-not $testConnection ) {
171+ Write-Log " No internet connection available" " ERROR"
172+ return $false
173+ }
174+ } catch {
175+ Write-Log " Failed to check internet connection: $_ " " ERROR"
176+ return $false
177+ }
178+
179+ return $true
180+ }
181+
182+ # 添加文件验证函数
183+ function Test-FileHash {
184+ param (
185+ [string ]$FilePath ,
186+ [string ]$ExpectedHash
187+ )
188+
189+ $actualHash = Get-FileHash - Path $FilePath - Algorithm SHA256
190+ return $actualHash.Hash -eq $ExpectedHash
191+ }
192+
193+ # 修改下载函数,添加进度条
194+ function Download-File {
195+ param (
196+ [string ]$Url ,
197+ [string ]$OutFile
198+ )
199+
200+ try {
201+ $webClient = New-Object System.Net.WebClient
202+ $webClient.Headers.Add (" User-Agent" , " PowerShell Script" )
203+
204+ $webClient.DownloadFileAsync ($Url , $OutFile )
205+
206+ while ($webClient.IsBusy ) {
207+ Write-Progress - Activity " Downloading..." - Status " Progress:" - PercentComplete -1
208+ Start-Sleep - Milliseconds 100
209+ }
210+
211+ Write-Progress - Activity " Downloading..." - Completed
212+ return $true
213+ }
214+ catch {
215+ Write-Log " Download failed: $_ " " ERROR"
216+ return $false
217+ }
218+ finally {
219+ if ($webClient ) {
220+ $webClient.Dispose ()
221+ }
222+ }
223+ }
224+
136225# Main installation process / 主安装过程
137226Write-Status (Get-Message 0 )
138227
@@ -156,7 +245,8 @@ Write-Status "$(Get-Message 3) $version"
156245
157246# Set up paths / 设置路径
158247$installDir = " $env: ProgramFiles \cursor-id-modifier"
159- $binaryName = " cursor_id_modifier_${version} _windows_amd64.exe"
248+ $versionWithoutV = $version.TrimStart (' v' ) # 移除版本号前面的 'v' 字符
249+ $binaryName = " cursor_id_modifier_${versionWithoutV} _windows_amd64.exe"
160250$downloadUrl = " https://github.com/yuaotian/go-cursor-help/releases/download/$version /$binaryName "
161251$tempFile = " $env: TEMP \$binaryName "
162252
@@ -169,7 +259,9 @@ if (-not (Test-Path $installDir)) {
169259# Download binary / 下载二进制文件
170260Write-Status " $ ( Get-Message 5 ) $downloadUrl "
171261try {
172- Invoke-WebRequest - Uri $downloadUrl - OutFile $tempFile
262+ if (-not (Download- File - Url $downloadUrl - OutFile $tempFile )) {
263+ Write-Error " $ ( Get-Message 6 ) "
264+ }
173265} catch {
174266 Write-Error " $ ( Get-Message 6 ) $_ "
175267}
@@ -198,13 +290,6 @@ if ($userPath -notlike "*$installDir*") {
198290 )
199291}
200292
201- # Create shortcut in Start Menu / 在开始菜单创建快捷方式
202- $startMenuPath = " $env: ProgramData \Microsoft\Windows\Start Menu\Programs\cursor-id-modifier.lnk"
203- $shell = New-Object - ComObject WScript.Shell
204- $shortcut = $shell.CreateShortcut ($startMenuPath )
205- $shortcut.TargetPath = " $installDir \cursor-id-modifier.exe"
206- $shortcut.Save ()
207-
208293# Cleanup / 清理
209294Write-Status (Get-Message 11 )
210295if (Test-Path $tempFile ) {
@@ -213,4 +298,11 @@ if (Test-Path $tempFile) {
213298
214299Write-Success (Get-Message 12 )
215300Write-Success (Get-Message 13 )
216- Write-Host " "
301+ Write-Host " "
302+
303+ # 直接运行程序
304+ try {
305+ Start-Process " $installDir \cursor-id-modifier.exe" - NoNewWindow
306+ } catch {
307+ Write-Warning " Failed to start cursor-id-modifier: $_ "
308+ }
0 commit comments