#pragma once #include #include #include #include #include "Export.h" #include #include "WebFileInfo.h" #include using std::chrono::operator""s; using std::chrono::operator""min; class UNSWSC_DLL_EXPORT TempFileManager { private: struct FileControlBlock { WebFileInfo info; std::chrono::steady_clock::time_point expire_time; std::chrono::steady_clock::time_point active_start_time; std::chrono::seconds remaining_timeout; std::chrono::seconds max_processing_timeout; bool is_active = false; bool is_permanent = false; // 是否永久保留 bool is_invalid = false; }; std::string base_dir; std::unordered_map file_map; mutable std::shared_mutex rw_mutex; // C++20 jthread std::jthread cleanup_thread; void CleanupLoop(std::stop_token st) noexcept; public: TempFileManager() noexcept; ~TempFileManager() noexcept; // 禁止拷贝与移动 TempFileManager(const TempFileManager&) = delete; TempFileManager& operator=(const TempFileManager&) = delete; TempFileManager(TempFileManager&&) = delete; TempFileManager& operator=(TempFileManager&&) = delete; // 基础业务接口(保持不变) bool SetBaseDirectory(std::string dir) noexcept; bool RegisterFile(const WebFileInfo& info, std::chrono::seconds timeout, std::chrono::seconds max_proc_timeout = std::chrono::seconds(0)) noexcept; bool InvalidateFile(const WebFileInfo& info); //For SFR_FileMap bool InvalidateFile(const std::map& info); bool CopyFileTo(const std::string& storage_name, const std::string& dest_absolute_path) noexcept; bool CutFileTo(const std::string& storage_name, const std::string& dest_absolute_path) noexcept; bool RenameFile(const std::string& old_storage_name, const std::string& new_storage_name) noexcept; bool DeleteFile(const std::string& storage_name) noexcept; bool ActiveFile(const std::string& storage_name) noexcept; bool DeactiveFile(const std::string& storage_name) noexcept; bool SetPermanent(const std::string& storage_name, bool permanent) noexcept; bool FileExists(const std::string& storage_name) const noexcept; bool GetFileInfo(const std::string& storage_name, WebFileInfo& out_info) const noexcept; size_t GetFileCount() const noexcept; // 获取当前所有管理中的文件信息快照(线程安全,绝不抛出异常) std::vector GetAllFileInfos() const noexcept; };