#pragma once #include #include #include struct sqlite3; enum class TaskState : int { kQueued = 0, kDownloading = 1, kCompleted = 2, kFailed = 3, kPaused = 4, kDeleted = 5, kScheduled = 6, }; struct TaskInfo { int64_t id = 0; std::wstring url; std::wstring save_path; std::wstring file_name; TaskState state = TaskState::kQueued; int64_t total_bytes = 0; int64_t downloaded_bytes = 0; std::wstring error; std::wstring request_id,referrer,user_agent; }; class TaskStore { public: ~TaskStore(); bool Open(const std::wstring& db_path); void Close(); std::vector LoadTasks(); bool Insert(TaskInfo& task); bool DeleteTask(int64_t id); bool UpdateProgress(int64_t id, int64_t downloaded_bytes, int64_t total_bytes); bool UpdateState(int64_t id, TaskState state, int64_t downloaded_bytes, int64_t total_bytes, const std::wstring& error); bool UpdateTarget(int64_t id, const std::wstring& save_path, const std::wstring& file_name); private: sqlite3* db_ = nullptr; };