test update ps1

This commit is contained in:
yeongpin 2025-01-15 11:16:02 +08:00
parent ffd7b839e7
commit a7e927a557
2 changed files with 33 additions and 125 deletions

View File

@ -37,6 +37,13 @@ This is a tool to automatically register (except for Google verification code),
## 🔄 更新日志
<details open>
<summary>v1.0.6</summary>
1. Add Quit Cursor Option | 增加退出Cursor選項
2. Add Recaptcha Path Patch | 增加Recaptcha路徑修復
3. Fix Admin Permission | 修復管理員權限問題
</details>
<details>
<summary>v1.0.5 - HotFix</summary>
1. Fix: Mac Browser Control | 修復Mac瀏覽器控制問題

View File

@ -1,8 +1,3 @@
# 檢查是否是通過權限提升啟動的
param(
[switch]$Elevated
)
# 設置顏色主題
$Theme = @{
Primary = 'Cyan'
@ -22,19 +17,6 @@ $Logo = @"
"@
# 進度條函數
function Write-ProgressBar {
param (
[int]$Percent,
[string]$Activity
)
$width = $Host.UI.RawUI.WindowSize.Width - 20
$completed = [math]::Floor($width * ($Percent / 100))
$remaining = $width - $completed
$progressBar = "[" + ("" * $completed) + ("-" * $remaining) + "]"
Write-Host "`r$Activity $progressBar $Percent%" -NoNewline
}
# 美化輸出函數
function Write-Styled {
param (
@ -43,14 +25,14 @@ function Write-Styled {
[string]$Prefix = "",
[switch]$NoNewline
)
$emoji = switch ($Color) {
$Theme.Success { "" }
$Theme.Error { "" }
$Theme.Warning { "⚠️" }
default { "" }
$symbol = switch ($Color) {
$Theme.Success { "[OK]" }
$Theme.Error { "[X]" }
$Theme.Warning { "[!]" }
default { "[*]" }
}
$output = if ($Prefix) { "$emoji $Prefix :: $Message" } else { "$emoji $Message" }
$output = if ($Prefix) { "$symbol $Prefix :: $Message" } else { "$symbol $Message" }
if ($NoNewline) {
Write-Host $output -ForegroundColor $Color -NoNewline
} else {
@ -58,61 +40,6 @@ function Write-Styled {
}
}
# 檢查管理員權限
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
if (-NOT $isAdmin) {
Write-Styled "需要管理員權限來安裝" -Color $Theme.Warning -Prefix "權限"
Write-Styled "正在請求管理員權限..." -Color $Theme.Primary -Prefix "提升"
# 顯示操作選項
Write-Host "`n選擇操作:" -ForegroundColor $Theme.Primary
Write-Host "1. 請求管理員權限" -ForegroundColor $Theme.Info
Write-Host "2. 退出程序" -ForegroundColor $Theme.Info
$choice = Read-Host "`n請輸入選項 (1-2)"
if ($choice -ne "1") {
Write-Styled "安裝已取消" -Color $Theme.Warning -Prefix "取消"
Write-Host "`n按任意鍵退出..." -ForegroundColor $Theme.Info
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
exit
}
$pwshPath = if (Get-Command "pwsh" -ErrorAction SilentlyContinue) {
(Get-Command "pwsh").Source
} elseif (Test-Path "$env:ProgramFiles\PowerShell\7\pwsh.exe") {
"$env:ProgramFiles\PowerShell\7\pwsh.exe"
} else {
"powershell.exe"
}
try {
$arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`" -Elevated -WindowStyle Normal"
Start-Process -FilePath $pwshPath -Verb RunAs -ArgumentList $arguments
Write-Host "`n請在新開啟的管理員權限視窗中繼續操作..." -ForegroundColor $Theme.Primary
# 等待用戶確認
Write-Host "`n按任意鍵退出此窗口..." -ForegroundColor $Theme.Info
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
exit
}
catch {
Write-Styled "無法獲取管理員權限" -Color $Theme.Error -Prefix "錯誤"
Write-Styled "請以管理員身份運行 PowerShell 後重試" -Color $Theme.Warning -Prefix "提示"
Write-Styled "您可以:" -Color $Theme.Info
Write-Host "1. 右鍵點擊 PowerShell選擇「以系統管理員身分執行」" -ForegroundColor $Theme.Info
Write-Host "2. 然後重新運行此安裝程序" -ForegroundColor $Theme.Info
Write-Host "`n按任意鍵退出..." -ForegroundColor $Theme.Info
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
exit 1
}
}
# 如果是提升權限後的窗口,等待一下確保窗口可見
if ($Elevated) {
Start-Sleep -Seconds 1
}
# 獲取版本號函數
function Get-LatestVersion {
try {
@ -122,8 +49,8 @@ function Get-LatestVersion {
Assets = $latestRelease.assets
}
} catch {
Write-Styled $_.Exception.Message -Color $Theme.Error -Prefix "錯誤"
throw "無法獲取最新版本信息"
Write-Styled $_.Exception.Message -Color $Theme.Error -Prefix "Error"
throw "Cannot get latest version"
}
}
@ -137,72 +64,47 @@ Write-Host "Created by YeongPin`n" -ForegroundColor $Theme.Info
# 設置 TLS 1.2
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# 創建臨時目錄
$TmpDir = Join-Path $env:TEMP ([System.Guid]::NewGuid().ToString())
New-Item -ItemType Directory -Path $TmpDir -Force | Out-Null
# 清理函數
function Cleanup {
if (Test-Path $TmpDir) {
Remove-Item -Recurse -Force $TmpDir -ErrorAction SilentlyContinue
}
}
# 主安裝函數
function Install-CursorFreeVIP {
Write-Styled "開始安裝 Cursor Free VIP" -Color $Theme.Primary -Prefix "安裝"
# 設置安裝目錄
$InstallDir = "$env:ProgramFiles\CursorFreeVIP"
if (!(Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
Write-Styled "Start downloading Cursor Free VIP" -Color $Theme.Primary -Prefix "Download"
try {
# 獲取最新版本
Write-Styled "正在檢查最新版本..." -Color $Theme.Primary -Prefix "更新"
Write-Styled "Checking latest version..." -Color $Theme.Primary -Prefix "Update"
$releaseInfo = Get-LatestVersion
$version = $releaseInfo.Version
Write-Styled "找到最新版本: $version" -Color $Theme.Success -Prefix "版本"
Write-Styled "Found latest version: $version" -Color $Theme.Success -Prefix "Version"
# 查找對應的資源
$asset = $releaseInfo.Assets | Where-Object { $_.name -eq "CursorFreeVIP_${version}_windows.exe" }
if (!$asset) {
Write-Styled "找不到檔案: CursorFreeVIP_${version}_windows.exe" -Color $Theme.Error -Prefix "錯誤"
Write-Styled "可用的檔案:" -Color $Theme.Warning -Prefix "資訊"
Write-Styled "File not found: CursorFreeVIP_${version}_windows.exe" -Color $Theme.Error -Prefix "Error"
Write-Styled "Available files:" -Color $Theme.Warning -Prefix "Info"
$releaseInfo.Assets | ForEach-Object {
Write-Styled "- $($_.name)" -Color $Theme.Info
}
throw "找不到對應的安裝檔案"
throw "Cannot find target file"
}
# 下載
Write-Styled "正在下載..." -Color $Theme.Primary -Prefix "下載"
# 下載到Downloads文件夾
$DownloadsPath = [Environment]::GetFolderPath("UserProfile") + "\Downloads"
$downloadPath = Join-Path $DownloadsPath "CursorFreeVIP.exe"
Write-Styled "Downloading to Downloads folder..." -Color $Theme.Primary -Prefix "Download"
$webClient = New-Object System.Net.WebClient
$webClient.Headers.Add("User-Agent", "PowerShell Script")
$downloadPath = Join-Path $TmpDir "CursorFreeVIP.exe"
$webClient.DownloadFile($asset.browser_download_url, $downloadPath)
# 安裝
Write-Styled "正在安裝到系統..." -Color $Theme.Primary -Prefix "安裝"
Copy-Item -Path $downloadPath -Destination "$InstallDir\CursorFreeVIP.exe" -Force
# 添加到 PATH
$currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine")
if ($currentPath -notlike "*$InstallDir*") {
[Environment]::SetEnvironmentVariable("Path", "$currentPath;$InstallDir", "Machine")
}
Write-Styled "安裝完成!" -Color $Theme.Success -Prefix "完成"
Write-Styled "正在啟動程序..." -Color $Theme.Primary -Prefix "啟動"
Write-Styled "Download completed!" -Color $Theme.Success -Prefix "Complete"
Write-Styled "File location: $downloadPath" -Color $Theme.Info -Prefix "Location"
Write-Styled "Starting program..." -Color $Theme.Primary -Prefix "Launch"
# 運行程序
Start-Process "$InstallDir\CursorFreeVIP.exe"
Start-Process $downloadPath
}
catch {
Write-Styled $_.Exception.Message -Color $Theme.Error -Prefix "錯誤"
Write-Styled $_.Exception.Message -Color $Theme.Error -Prefix "Error"
throw
}
}
@ -212,11 +114,10 @@ try {
Install-CursorFreeVIP
}
catch {
Write-Styled "安裝失敗" -Color $Theme.Error -Prefix "錯誤"
Write-Styled "Download failed" -Color $Theme.Error -Prefix "Error"
Write-Styled $_.Exception.Message -Color $Theme.Error
}
finally {
Cleanup
Write-Host "`n按任意鍵退出..." -ForegroundColor $Theme.Info
Write-Host "`nPress any key to exit..." -ForegroundColor $Theme.Info
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
}