feat: Implement 30-minute timeout protection and unify path configurations
- Introduced a 30-minute timeout mechanism to prevent the script from getting stuck in invalid states, with configurable timeout settings. - Unified path configurations across the project to enhance maintainability and avoid hardcoded paths. - Updated documentation and flowcharts to reflect the new timeout feature and improved path management. - Fixed issues with template and screenshot path configurations to ensure consistency across the project.
This commit is contained in:
1 parent
686dde5cc0
commit
26df350755
64 files changed
+7568
-414
No files matched your search
@@ -0,0 +1,201 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""修复 Cursor IDE 无法打开 Markdown 文件的问题"""
|
||||
|
||||
import os
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
def check_file_permissions(file_path):
|
||||
"""检查文件权限"""
|
||||
issues = []
|
||||
try:
|
||||
if not os.path.exists(file_path):
|
||||
issues.append("文件不存在")
|
||||
return issues
|
||||
|
||||
if not os.access(file_path, os.R_OK):
|
||||
issues.append("文件无读取权限")
|
||||
|
||||
# 检查文件是否被锁定
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
f.read(1)
|
||||
except PermissionError:
|
||||
issues.append("文件被锁定或无权限")
|
||||
except Exception as e:
|
||||
issues.append(f"无法读取文件: {e}")
|
||||
|
||||
except Exception as e:
|
||||
issues.append(f"检查权限时出错: {e}")
|
||||
|
||||
return issues
|
||||
|
||||
def create_test_md_file():
|
||||
"""创建一个测试 Markdown 文件"""
|
||||
test_file = Path("TEST_MARKDOWN.md")
|
||||
content = """# Test Markdown File
|
||||
|
||||
This is a test file to verify Cursor can open Markdown files.
|
||||
|
||||
## Test Section
|
||||
|
||||
- Item 1
|
||||
- Item 2
|
||||
- Item 3
|
||||
|
||||
**Bold text** and *italic text*
|
||||
|
||||
```python
|
||||
print("Hello, World!")
|
||||
```
|
||||
|
||||
"""
|
||||
try:
|
||||
with open(test_file, 'w', encoding='utf-8', newline='\n') as f:
|
||||
f.write(content)
|
||||
print(f"[OK] 已创建测试文件: {test_file}")
|
||||
return test_file
|
||||
except Exception as e:
|
||||
print(f"[ERROR] 创建测试文件失败: {e}")
|
||||
return None
|
||||
|
||||
def fix_md_file_encoding(file_path):
|
||||
"""修复单个 MD 文件的编码"""
|
||||
try:
|
||||
# 读取文件
|
||||
encodings = ['utf-8', 'utf-8-sig', 'gbk', 'gb2312']
|
||||
content = None
|
||||
|
||||
for encoding in encodings:
|
||||
try:
|
||||
with open(file_path, 'r', encoding=encoding) as f:
|
||||
content = f.read()
|
||||
break
|
||||
except (UnicodeDecodeError, UnicodeError):
|
||||
continue
|
||||
|
||||
if content is None:
|
||||
return False, "无法读取文件"
|
||||
|
||||
# 移除BOM
|
||||
if content.startswith('\ufeff'):
|
||||
content = content[1:]
|
||||
|
||||
# 确保以UTF-8保存(无BOM,使用LF换行)
|
||||
with open(file_path, 'w', encoding='utf-8', newline='\n') as f:
|
||||
f.write(content)
|
||||
|
||||
return True, "已修复"
|
||||
|
||||
except Exception as e:
|
||||
return False, str(e)
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
print("=" * 60)
|
||||
print("Cursor IDE Markdown 文件修复工具")
|
||||
print("=" * 60)
|
||||
print()
|
||||
|
||||
# 检查主要MD文件
|
||||
main_files = [
|
||||
"MODULARIZATION_SUMMARY.md",
|
||||
"README.md",
|
||||
"douyin/README.md",
|
||||
"douyin/fudai/core/MODULARIZATION_PLAN.md",
|
||||
]
|
||||
|
||||
print("检查主要 Markdown 文件...")
|
||||
print()
|
||||
|
||||
all_ok = True
|
||||
for file_path_str in main_files:
|
||||
file_path = Path(file_path_str)
|
||||
if not file_path.exists():
|
||||
print(f"[WARN] {file_path_str} - 文件不存在")
|
||||
continue
|
||||
|
||||
# 检查权限
|
||||
perm_issues = check_file_permissions(file_path)
|
||||
if perm_issues:
|
||||
print(f"[ERROR] {file_path_str}")
|
||||
for issue in perm_issues:
|
||||
print(f" - {issue}")
|
||||
all_ok = False
|
||||
continue
|
||||
|
||||
# 修复编码
|
||||
success, message = fix_md_file_encoding(file_path)
|
||||
if success:
|
||||
file_size = os.path.getsize(file_path)
|
||||
print(f"[OK] {file_path_str} ({file_size} bytes) - {message}")
|
||||
else:
|
||||
print(f"[ERROR] {file_path_str} - {message}")
|
||||
all_ok = False
|
||||
|
||||
print()
|
||||
print("=" * 60)
|
||||
|
||||
# 创建测试文件
|
||||
print("创建测试文件...")
|
||||
test_file = create_test_md_file()
|
||||
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("修复建议:")
|
||||
print("=" * 60)
|
||||
print()
|
||||
print("1. 重启 Cursor IDE")
|
||||
print(" - 完全关闭 Cursor")
|
||||
print(" - 重新打开 Cursor 和项目")
|
||||
print()
|
||||
print("2. 清除 Cursor 缓存")
|
||||
print(" - 关闭 Cursor")
|
||||
print(" - 删除以下目录(如果存在):")
|
||||
print(" - %APPDATA%\\Cursor\\Cache")
|
||||
print(" - %APPDATA%\\Cursor\\CachedData")
|
||||
print(" - 重新打开 Cursor")
|
||||
print()
|
||||
print("3. 检查 Cursor 设置")
|
||||
print(" - 打开设置 (Ctrl+,)")
|
||||
print(" - 搜索 'markdown'")
|
||||
print(" - 确保 Markdown 预览功能已启用")
|
||||
print()
|
||||
print("4. 重新安装 Markdown 扩展")
|
||||
print(" - 打开扩展面板 (Ctrl+Shift+X)")
|
||||
print(" - 搜索 'Markdown'")
|
||||
print(" - 禁用并重新启用相关扩展")
|
||||
print()
|
||||
print("5. 使用命令面板")
|
||||
print(" - 按 Ctrl+Shift+P")
|
||||
print(" - 输入 'Reload Window'")
|
||||
print(" - 选择 'Developer: Reload Window'")
|
||||
print()
|
||||
print("6. 手动打开文件")
|
||||
print(" - 在文件资源管理器中找到文件")
|
||||
print(" - 右键点击 .md 文件")
|
||||
print(" - 选择 '打开方式' -> 'Cursor'")
|
||||
print()
|
||||
|
||||
if test_file:
|
||||
print(f"7. 测试文件")
|
||||
print(f" - 尝试打开: {test_file}")
|
||||
print(f" - 如果这个文件能打开,说明是特定文件的问题")
|
||||
print(f" - 如果这个文件也不能打开,说明是 Cursor 的配置问题")
|
||||
print()
|
||||
|
||||
print("=" * 60)
|
||||
|
||||
if all_ok:
|
||||
print("[SUCCESS] 所有文件检查通过")
|
||||
print("如果仍然无法打开,请按照上述建议操作")
|
||||
else:
|
||||
print("[WARNING] 发现一些问题,请查看上面的详细信息")
|
||||
|
||||
return 0 if all_ok else 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
Reference in new issue
Block a user