Compare commits

..

8 Commits

Author SHA1 Message Date
yeongpin
3543615a69 fix: Improve Windows Language Detection and Platform Compatibility
- Correct Windows language detection method in Translator class
- Update platform system check for Windows-specific imports
- Refactor language detection to use platform-specific checks
- Ensure more robust cross-platform language detection logic
2025-02-25 12:16:55 +08:00
yeongpin
24b0a5c09e refactor: Streamline System Language Detection Logic
- Consolidate language detection methods into a single unified approach
- Improve cross-platform language detection for Windows and Unix-like systems
- Simplify error handling and add more robust language code mapping
- Remove platform-specific detection methods in favor of a more generic approach
- Enhance language fallback mechanism with better default handling
2025-02-25 12:14:54 +08:00
yeongpin
5bbba05f69 feat: Improve System Language Detection in Translator Class
- Refactor language detection method with separate methods for Windows, macOS, and Linux
- Add more robust language detection for different platforms
- Improve error handling and fallback mechanisms
- Ensure consistent language code formatting (zh_CN, zh_TW)
- Update Windows language detection using windll with additional error checks
2025-02-25 12:09:13 +08:00
yeongpin
72c95e4b4f refactor: Simplify OS Detection and Download Process
- Streamline OS detection logic by removing detailed architecture checks
- Reduce complexity in download URL generation
- Remove verbose download verification steps
- Simplify error handling during binary download
2025-02-25 12:00:59 +08:00
yeongpin
8afd5df4ea fix: Correct Syntax Error in Installation Script Conditional Logic
- Fix incorrect brace placement in install_cursor_free_vip function
- Remove unnecessary closing brace that was causing syntax error
- Ensure proper flow control in installation script
2025-02-25 11:55:38 +08:00
yeongpin
a7a97b5621 feat: Enhance OS Detection and Download Resilience in Installation Script
- Add Windows system detection
- Implement fallback mechanism for macOS binary downloads
- Improve download link verification with HEAD request
- Add graceful handling for missing architecture-specific binaries
- Provide more informative error messages during download process
2025-02-25 11:54:45 +08:00
yeongpin
e2e2ebc12e feat: Enhance Download Verification in Installation Script
- Add verbose curl download logging
- Implement file size check for downloaded binaries
- Provide detailed error messages for download failures
- Improve download error handling and diagnostics
2025-02-25 11:53:37 +08:00
yeongpin
d131bccac0 feat: Improve macOS Architecture Detection in Installation Script
- Add detailed macOS architecture detection (ARM64 and Intel)
- Enhance system type logging with informative messages
- Provide more precise OS and architecture identification
2025-02-25 11:50:39 +08:00
4 changed files with 76 additions and 10 deletions

4
.env
View File

@@ -1,2 +1,2 @@
version=1.4.04
VERSION=1.4.04
version=1.4.05
VERSION=1.4.05

View File

@@ -1,5 +1,10 @@
# Change Log
## v1.4.05
1. Fix: macOS Language Detection | 修復macOS語言檢測
## v1.4.04
1. Change Some Language Info to English | 更改一些語言信息為英文

18
main.py
View File

@@ -5,11 +5,15 @@ import sys
import json
from logo import print_logo
from colorama import Fore, Style, init
import ctypes
from ctypes import windll
import locale
import platform
# 只在 Windows 系统上导入 windll
if platform.system() == 'Windows':
import ctypes
# 只在 Windows 上导入 windll
from ctypes import windll
# 初始化colorama
init()
@@ -29,8 +33,8 @@ EMOJI = {
class Translator:
def __init__(self):
self.current_language = self.detect_system_language() # Changed to use system language
self.translations = {}
self.current_language = self.detect_system_language() # 使用正确的方法名
self.fallback_language = 'en' # Fallback language if translation is missing
self.load_translations()
@@ -51,8 +55,12 @@ class Translator:
def _detect_windows_language(self):
"""Detect language on Windows systems"""
try:
# Get the keyboard layout
user32 = ctypes.WinDLL('user32', use_last_error=True)
# 确保我们在 Windows 上
if platform.system() != 'Windows':
return 'en'
# 获取键盘布局
user32 = ctypes.windll.user32
hwnd = user32.GetForegroundWindow()
threadid = user32.GetWindowThreadProcessId(hwnd, 0)
layout_id = user32.GetKeyboardLayout(threadid) & 0xFFFF

View File

@@ -50,12 +50,25 @@ get_latest_version() {
echo -e "${GREEN}✅ 找到最新版本: ${VERSION}${NC}"
}
# 檢測系統類型
# 檢測系統類型和架構
detect_os() {
if [[ "$(uname)" == "Darwin" ]]; then
OS="mac"
else
# 检测 macOS 架构
ARCH=$(uname -m)
if [[ "$ARCH" == "arm64" ]]; then
OS="mac_arm64"
echo -e "${CYAN} 检测到 macOS ARM64 架构${NC}"
else
OS="mac_intel"
echo -e "${CYAN} 检测到 macOS Intel 架构${NC}"
fi
elif [[ "$(uname)" == "Linux" ]]; then
OS="linux"
echo -e "${CYAN} 检测到 Linux 系统${NC}"
else
# 假设是 Windows
OS="windows"
echo -e "${CYAN} 检测到 Windows 系统${NC}"
fi
}
@@ -67,11 +80,51 @@ install_cursor_free_vip() {
local download_url="https://github.com/yeongpin/cursor-free-vip/releases/download/v${VERSION}/${binary_name}"
echo -e "${CYAN} 正在下載到 ${downloads_dir}...${NC}"
echo -e "${CYAN} 下載鏈接: ${download_url}${NC}"
# 先检查文件是否存在
if curl --output /dev/null --silent --head --fail "$download_url"; then
echo -e "${GREEN}✅ 文件存在,开始下载...${NC}"
else
echo -e "${RED}❌ 下载链接不存在: ${download_url}${NC}"
echo -e "${YELLOW}⚠️ 尝试不带架构的版本...${NC}"
# 尝试不带架构的版本
if [[ "$OS" == "mac_arm64" || "$OS" == "mac_intel" ]]; then
OS="mac"
binary_name="CursorFreeVIP_${VERSION}_${OS}"
download_url="https://github.com/yeongpin/cursor-free-vip/releases/download/v${VERSION}/${binary_name}"
echo -e "${CYAN} 新下载链接: ${download_url}${NC}"
if ! curl --output /dev/null --silent --head --fail "$download_url"; then
echo -e "${RED}❌ 新下载链接也不存在${NC}"
exit 1
fi
else
exit 1
fi
fi
# 下载文件
if ! curl -L -o "${binary_path}" "$download_url"; then
echo -e "${RED}❌ 下載失敗${NC}"
exit 1
fi
# 检查下载的文件大小
local file_size=$(stat -f%z "${binary_path}" 2>/dev/null || stat -c%s "${binary_path}" 2>/dev/null)
echo -e "${CYAN} 下載的文件大小: ${file_size} 字節${NC}"
# 如果文件太小,可能是错误信息
if [ "$file_size" -lt 1000 ]; then
echo -e "${YELLOW}⚠️ 警告: 下載的文件太小,可能不是有效的可執行文件${NC}"
echo -e "${YELLOW}⚠️ 文件內容:${NC}"
cat "${binary_path}"
echo ""
echo -e "${RED}❌ 下載失敗,請檢查版本號和操作系統是否正確${NC}"
exit 1
fi
echo -e "${CYAN} 正在設置執行權限...${NC}"
chmod +x "${binary_path}"