Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 4, 2025

Implements "另存为" (Save As) context menu for files and folders, supporting both web browser downloads and desktop native save dialogs.

Changes

  • UI: Added "另存为..." menu items to file and folder context menus
  • File Save: Exports individual files with current content, preserving extensions
  • Folder Save: Exports complete directory structures as JSON with all files, subfolders, content, project types, and NuGet configs
  • Desktop Integration: Uses native OS save dialogs via desktopBridge.requestFileDownload() with save-file-as/save-folder-as actions
  • Web Fallback: Triggers browser downloads when desktop bridge unavailable

Implementation

Created shared utilities to eliminate duplication (~130 lines):

  • sanitizeFileName(): Strips path separators, control chars, limits length
  • requestDesktopSave(): Centralized desktop bridge requests
  • downloadBlob(): Unified browser download logic
  • createFolderStructureData(): Recursively builds folder structure from latest localStorage content

Refactored existing exportFolder() to use shared methods for consistency.

Security

Filename sanitization prevents:

  • Directory traversal (/, \, :)
  • Control characters (\x00-\x1f)
  • Hidden files (leading/trailing dots)
  • Filesystem limits (200 char max)

Usage

// Right-click file → "另存为..."
saveFileAs()  downloads file.cs with latest content

// Right-click folder → "另存为..."  
saveFolderAs()  downloads folder.json with complete structure

Desktop mode shows saved path in notifications. Folders can be re-imported via existing "导入" functionality.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • av-build-tel-api-v1.avaloniaui.net
    • Triggering command: /usr/share/dotnet/dotnet dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.2/tools/netstandard2.0/runtimeconfig.json /home/REDACTED/.nuget/packages/avalonia.buildservices/11.3.2/tools/netstandard2.0/Avalonia.BuildServices.Collector.dll (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>feat # 另存为文件或目录到磁盘</issue_title>
<issue_description>另存为文件或目录到磁盘</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 4, 2025
Copilot AI changed the title [WIP] Add feature to save file or directory to disk feat: Add Save As functionality for files and directories Dec 4, 2025
Copilot AI requested a review from gaoconggit December 4, 2025 03:11
@gaoconggit gaoconggit merged commit 467c9be into main Dec 29, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat # 另存为文件或目录到磁盘

2 participants