Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 30, 2025

Adds local persistence for download tasks using libtorrent's native resume data APIs and SQLite for metadata. Tasks automatically resume on restart. Data stored in WinUI3's recommended ApplicationData::Current().LocalFolder().

Changes

New: TorrentStateManager (Core/torrentCore/)

  • SQLite-backed storage for task metadata (magnet URI, save path, progress, status)
  • Session state persistence via session_state() / apply_settings()
  • Resume data via write_resume_data() / read_resume_data()
  • Bencode-based import/export for backup

LibtorrentHandle updates

  • Track task ID ↔ torrent handle mappings
  • Handle save_resume_data_alert, metadata_received_alert
  • Save resume data on torrent events (finish, pause, error)
  • AddTorrentFromResumeData() for restoring saved torrents

P2PManager updates

  • Initialize state manager on startup
  • LoadAndResumeSavedTasksAsync() resumes incomplete downloads
  • Expose GetAllTasks(), ExportTasksAsync(), ImportTasksAsync()

TasksViewModel updates

  • Load saved tasks on init with progress/status display
  • Add ExportCommand / ImportCommand

Storage Schema

CREATE TABLE tasks (
    task_id TEXT PRIMARY KEY,
    magnet_uri TEXT NOT NULL,
    save_path TEXT NOT NULL,
    name TEXT,
    added_timestamp INTEGER,
    total_size INTEGER,
    downloaded_size INTEGER,
    status INTEGER,  -- 0=pending, 1=downloading, 2=paused, 3=completed, 4=failed
    resume_data BLOB
);
Original prompt

根据目前已有的sqlite集成对所有下载任务的本地保存(使用的是libtorrent)你检查可行性,如lt是否已经提供相关方法。本地保存应该具有能够重启然后加载。保存位置应当在winui3cppwinrt的推荐保存目录中并提供导入导出功能


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Nov 30, 2025
Copilot AI and others added 2 commits November 30, 2025 19:40
…ith SQLite

- Create TorrentStateManager class using libtorrent's write_resume_data/read_resume_data APIs
- Store data in WinUI3's recommended LocalFolder (ApplicationData::Current().LocalFolder())
- Implement SQLite-based storage for task metadata and session state
- Add import/export functionality for task data backup
- Update LibtorrentHandle to save resume data on torrent events
- Update P2PManager to initialize state manager and load saved tasks on startup
- Update TasksViewModel with export/import commands and saved task loading

Co-authored-by: hoshiizumiya <63837495+hoshiizumiya@users.noreply.github.com>
- Fix race condition in ExportToFile by loading data while holding lock, then writing without lock
- Fix race condition in ImportFromFile by reading file first, then saving to database
- Add FormatTimestamp helper function for proper date formatting
- Replace placeholder date code with actual timestamp formatting

Co-authored-by: hoshiizumiya <63837495+hoshiizumiya@users.noreply.github.com>
Copilot AI changed the title [WIP] Check feasibility for local storage of download tasks Implement libtorrent task persistence with SQLite and resume data support Nov 30, 2025
Copilot AI requested a review from hoshiizumiya November 30, 2025 19:47
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.

2 participants