From 725ea566a2b6a12e0a02e4f570b6e99102e2d21b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 8 Apr 2019 21:04:12 +0200 Subject: Refactor, remove a lot of code and use dchat core instead --- include/Cache.hpp | 91 ------------------------------------------------------- 1 file changed, 91 deletions(-) delete mode 100644 include/Cache.hpp (limited to 'include/Cache.hpp') diff --git a/include/Cache.hpp b/include/Cache.hpp deleted file mode 100644 index fc702a7..0000000 --- a/include/Cache.hpp +++ /dev/null @@ -1,91 +0,0 @@ -#pragma once - -#include "types.hpp" -#include -#include -#include -#include -#include -#include -#include -#include - -namespace TinyProcessLib -{ - class Process; -} - -namespace dchat -{ - class Gif; - class WebPagePreview; - - struct ContentByUrlResult - { - enum class Type - { - CACHED, - DOWNLOADING, - FAILED_DOWNLOAD - }; - - enum class CachedType - { - NONE, - TEXTURE, - GIF, - WEB_PAGE_PREVIEW - }; - - ContentByUrlResult() : texture(nullptr), type(Type::DOWNLOADING), cachedType(CachedType::NONE) {} - ContentByUrlResult(sf::Texture *_texture, Type _type) : texture(_texture), type(_type), cachedType(CachedType::TEXTURE) {} - ContentByUrlResult(Gif *_gif, Type _type) : gif(_gif), type(_type), cachedType(CachedType::GIF) {} - ContentByUrlResult(WebPagePreview *_webPagePreview, Type _type) : webPagePreview(_webPagePreview), type(_type), cachedType(CachedType::WEB_PAGE_PREVIEW) {} - - // @texture is null if @type is DOWNLOADING or FAILED_DOWNLOAD - union - { - sf::Texture *texture; - Gif *gif; - WebPagePreview *webPagePreview; - }; - - Type type; - CachedType cachedType; - i64 lastAccessed; - }; - - class Cache - { - public: - Cache(); - ~Cache(); - - // Creates directory if it doesn't exist (recursively). Throws boost exception on failure - static boost::filesystem::path getDchatDir(); - - // Creates directory if it doesn't exist (recursively). Throws boost exception on failure - static boost::filesystem::path getImagesDir(); - - static void loadBindsFromFile(); - static void replaceBindsInFile(const std::unordered_map &binds); - - // Get cached content or download it. - // Default download file limit is 12MB - // Returns ContentByUrlResult describing texture status. - const ContentByUrlResult getContentByUrl(const std::string &url, int downloadLimitBytes = 12582912); - private: - struct ImageDownloadInfo - { - TinyProcessLib::Process *process; - std::string url; - }; - - std::thread downloadWaitThread; - std::thread checkContentAccessTimeThread; - std::vector imageDownloadProcesses; - std::vector imageDownloadProcessesQueue; - std::mutex imageDownloadMutex; - bool alive; - }; -} -- cgit v1.2.3