diff options
Diffstat (limited to 'oop2eindopdr/CacheManager.cpp')
| -rw-r--r-- | oop2eindopdr/CacheManager.cpp | 45 | 
1 files changed, 45 insertions, 0 deletions
| diff --git a/oop2eindopdr/CacheManager.cpp b/oop2eindopdr/CacheManager.cpp new file mode 100644 index 0000000..7de435e --- /dev/null +++ b/oop2eindopdr/CacheManager.cpp @@ -0,0 +1,45 @@ +#include "CacheManager.h" + +#include <filesystem> +#include <fstream> +#include <iostream> +#include <ctime> + +CacheManager::CacheManager(const char* cache_path) : CacheManager(std::string(cache_path)) { } +CacheManager::CacheManager(std::string cache_path) { +  this->cache_path = cache_path; +  this->verify_cache(); +} + +CacheManager::~CacheManager() { +	for (std::fstream* file : this->files) { +		if (file != nullptr) { +			file->close(); +			delete file; +			file = nullptr; +		} +	} +} + +void CacheManager::verify_cache() { +  if (!std::filesystem::is_directory(this->cache_path)) this->init_cache(); +	this->update_cache(); +} + +void CacheManager::init_cache() { +  std::filesystem::create_directory(this->cache_path); +	this->update_cache(); +} + +void CacheManager::update_cache() { +	std::fstream& date = *cache_get("date"); +	this->age = std::time(nullptr); +	date << this->age; +} + +std::fstream* CacheManager::cache_get(const char* filename) { +	std::fstream* file = new std::fstream(filename, std::ios::out | std::ios::in); +	this->files.push_back(file); +	return file; +} + |