@ -1,7 +1,8 @@
# Auto-elevate to admin rights if not already running as admin
# Auto-elevate to admin rights if not already running as admin
if ( -NOT ( [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity] :: GetCurrent ( ) ) . IsInRole ( [Security.Principal.WindowsBuiltInRole] " Administrator " ) ) {
if ( -NOT ( [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity] :: GetCurrent ( ) ) . IsInRole ( [Security.Principal.WindowsBuiltInRole] " Administrator " ) ) {
Write-Host " Requesting administrator privileges... "
Write-Host " Requesting administrator privileges... "
Start-Process powershell . exe " -NoProfile -ExecutionPolicy Bypass -File `" $ PSCommandPath `" " -Verb RunAs
$arguments = " -NoProfile -ExecutionPolicy Bypass -File `" $ PSCommandPath `" -ExecutionFromElevated "
Start-Process powershell . exe -ArgumentList $arguments -Verb RunAs
Exit
Exit
}
}
@ -30,7 +31,7 @@ $EN_MESSAGES = @(
" Adding to PATH... " ,
" Adding to PATH... " ,
" Cleaning up... " ,
" Cleaning up... " ,
" Installation completed successfully! " ,
" Installation completed successfully! " ,
" You can now use 'cursor-id-modifier' from any terminal (you may need to restart your terminal first) " ,
" You can now use 'cursor-id-modifier' directly " ,
" Checking for running Cursor instances... " ,
" Checking for running Cursor instances... " ,
" Found running Cursor processes. Attempting to close them... " ,
" Found running Cursor processes. Attempting to close them... " ,
" Successfully closed all Cursor instances " ,
" Successfully closed all Cursor instances " ,
@ -53,7 +54,7 @@ $CN_MESSAGES = @(
" 正在添加到PATH... " ,
" 正在添加到PATH... " ,
" 正在清理... " ,
" 正在清理... " ,
" 安装成功完成! " ,
" 安装成功完成! " ,
" 现在可以在任何终端中使用 'cursor-id-modifier' 了(可能需要重启终端) " ,
" 现在可以直接使用 'cursor-id-modifier' 了 " ,
" 正在检查运行中的Cursor进程... " ,
" 正在检查运行中的Cursor进程... " ,
" 发现正在运行的Cursor进程,尝试关闭... " ,
" 发现正在运行的Cursor进程,尝试关闭... " ,
" 成功关闭所有Cursor实例 " ,
" 成功关闭所有Cursor实例 " ,
@ -133,6 +134,94 @@ function Get-LatestVersion {
return $release . tag_name
return $release . tag_name
}
}
# 在文件开头添加日志函数
function Write-Log {
param (
[string] $Message ,
[string] $Level = " INFO "
)
$timestamp = Get-Date -Format " yyyy-MM-dd HH:mm:ss "
$logMessage = " [ $ timestamp] [ $ Level] $ Message "
$logFile = " $ env:TEMP\cursor-id-modifier-install.log "
Add-Content -Path $logFile -Value $logMessage
# 同时输出到控制台
switch ( $Level ) {
" ERROR " { Write-Error $Message }
" WARNING " { Write-Warning $Message }
" SUCCESS " { Write-Success $Message }
default { Write-Status $Message }
}
}
# 添加安装前检查函数
function Test-Prerequisites {
Write-Log " Checking prerequisites... " " INFO "
# 检查PowerShell版本
if ( $PSVersionTable . PSVersion . Major -lt 5 ) {
Write-Log " PowerShell 5.0 or higher is required " " ERROR "
return $false
}
# 检查网络连接
try {
$testConnection = Test-Connection -ComputerName " github.com " -Count 1 -Quiet
if ( -not $testConnection ) {
Write-Log " No internet connection available " " ERROR "
return $false
}
} catch {
Write-Log " Failed to check internet connection: $ _ " " ERROR "
return $false
}
return $true
}
# 添加文件验证函数
function Test-FileHash {
param (
[string] $FilePath ,
[string] $ExpectedHash
)
$actualHash = Get-FileHash -Path $FilePath -Algorithm SHA256
return $actualHash . Hash -eq $ExpectedHash
}
# 修改下载函数,添加进度条
function Download -File {
param (
[string] $Url ,
[string] $OutFile
)
try {
$webClient = New-Object System . Net . WebClient
$webClient . Headers . Add ( " User-Agent " , " PowerShell Script " )
$webClient . DownloadFileAsync ( $Url , $OutFile )
while ( $webClient . IsBusy ) {
Write-Progress -Activity " Downloading... " -Status " Progress: " -PercentComplete - 1
Start-Sleep -Milliseconds 100
}
Write-Progress -Activity " Downloading... " -Completed
return $true
}
catch {
Write-Log " Download failed: $ _ " " ERROR "
return $false
}
finally {
if ( $webClient ) {
$webClient . Dispose ( )
}
}
}
# Main installation process / 主安装过程
# Main installation process / 主安装过程
Write-Status ( Get-Message 0 )
Write-Status ( Get-Message 0 )
@ -156,7 +245,8 @@ Write-Status "$(Get-Message 3) $version"
# Set up paths / 设置路径
# Set up paths / 设置路径
$installDir = " $ env:ProgramFiles\cursor-id-modifier "
$installDir = " $ env:ProgramFiles\cursor-id-modifier "
$binaryName = " cursor_id_modifier_ $ {version}_windows_amd64.exe "
$versionWithoutV = $version . TrimStart ( 'v' ) # 移除版本号前面的 'v' 字符
$binaryName = " cursor_id_modifier_ $ {versionWithoutV}_windows_amd64.exe "
$downloadUrl = " https://github.com/yuaotian/go-cursor-help/releases/download/ $ version/ $ binaryName "
$downloadUrl = " https://github.com/yuaotian/go-cursor-help/releases/download/ $ version/ $ binaryName "
$tempFile = " $ env:TEMP\ $ binaryName "
$tempFile = " $ env:TEMP\ $ binaryName "
@ -169,7 +259,9 @@ if (-not (Test-Path $installDir)) {
# Download binary / 下载二进制文件
# Download binary / 下载二进制文件
Write-Status " $( Get-Message 5 ) $ downloadUrl "
Write-Status " $( Get-Message 5 ) $ downloadUrl "
try {
try {
Invoke-WebRequest -Uri $downloadUrl -OutFile $tempFile
if ( -not ( Download -File -Url $downloadUrl -OutFile $tempFile ) ) {
Write-Error " $( Get-Message 6 ) "
}
} catch {
} catch {
Write-Error " $( Get-Message 6 ) $ _ "
Write-Error " $( Get-Message 6 ) $ _ "
}
}
@ -198,13 +290,6 @@ if ($userPath -notlike "*$installDir*") {
)
)
}
}
# Create shortcut in Start Menu / 在开始菜单创建快捷方式
$startMenuPath = " $ env:ProgramData\Microsoft\Windows\Start Menu\Programs\cursor-id-modifier.lnk "
$shell = New-Object -ComObject WScript . Shell
$shortcut = $shell . CreateShortcut ( $startMenuPath )
$shortcut . TargetPath = " $ installDir\cursor-id-modifier.exe "
$shortcut . Save ( )
# Cleanup / 清理
# Cleanup / 清理
Write-Status ( Get-Message 11 )
Write-Status ( Get-Message 11 )
if ( Test-Path $tempFile ) {
if ( Test-Path $tempFile ) {
@ -214,3 +299,10 @@ if (Test-Path $tempFile) {
Write-Success ( Get-Message 12 )
Write-Success ( Get-Message 12 )
Write-Success ( Get-Message 13 )
Write-Success ( Get-Message 13 )
Write-Host " "
Write-Host " "
# 直接运行程序
try {
Start-Process " $ installDir\cursor-id-modifier.exe " -NoNewWindow
} catch {
Write-Warning " Failed to start cursor-id-modifier: $ _ "
}