#pragma once #include "platform.h" #include #include namespace ks { struct Pixels; Settings loadSettings(const std::filesystem::path &, const std::vector &); Settings decodeSettings(const Bytes &, const std::vector &); Bytes encodeSettings(const Settings &); void saveSettings(const std::filesystem::path &, const Settings &); void validateSettings(const Settings &); struct Entry { std::wstring id, preview, app; uint64_t bytes{}, at{}; bool pinned{}, image{}, files{}; int ocrState{}; // 0: legacy/not applicable, 1: pending, 2: saved, 3: failed std::wstring ocrProfile = L"windows"; std::string contentHash, imageHash, pixelHash; }; class History { std::filesystem::path folder_; std::vector entries_; mutable std::mutex mutex_; void saveIndex(); void loadIndex(); void prune(const Settings &); public: explicit History(const std::filesystem::path &); void reload(); std::vector entries() const; Clip load(const std::wstring &id) const; void add(const Clip &, const std::wstring &app, const Settings &); bool captureImage(DWORD sequence, const std::wstring &app, const Settings &); std::wstring recognizeImage(const std::wstring &id, const Settings &, const std::function &cancelled = {}) const; Pixels thumbnail(const std::wstring &id, const std::function &cancelled = {}) const; bool saveOcr(const std::wstring &id, const std::optional &, const Settings &); std::optional ocrText(const std::wstring &id, const std::wstring &profile = L"") const; void remove(const std::wstring &); void pin(const std::wstring &); void clear(); std::vector search(const std::wstring &, bool pinnedOnly = false) const; }; Bytes encodeClip(const Clip &); Clip decodeClip(const Bytes &); bool sameClipboardImage(const Clip &, const Clip &); int runImageHistoryCapture(const std::filesystem::path &request); int runHistoryOcr(const std::filesystem::path &request); // Image backups stay encrypted on disk and are read/written only by a short-lived helper. class ClipboardSnapshot { Clip clip_; std::filesystem::path request_; void cleanup() noexcept; DWORD run(bool restore, DWORD sequence); public: ClipboardSnapshot() = default; ClipboardSnapshot(const ClipboardSnapshot &) = delete; ClipboardSnapshot &operator=(const ClipboardSnapshot &) = delete; ~ClipboardSnapshot(); void capture(HWND, DWORD sequence); DWORD restore(HWND, DWORD sequence); }; int runClipboardSnapshot(const std::filesystem::path &request); } // namespace ks