2024-10-28 15:57:39 +01:00
|
|
|
// Luanti
|
|
|
|
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
|
|
// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
// Copyright (C) 2013 Jonathan Neuschäfer <j.neuschaefer@gmx.net>
|
2012-02-08 11:49:24 +01:00
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2012-02-08 11:49:24 +01:00
|
|
|
|
|
|
|
#include <iostream>
|
2017-04-01 14:48:16 +02:00
|
|
|
#include <string>
|
2024-02-17 15:35:33 +01:00
|
|
|
#include <string_view>
|
2012-02-08 11:49:24 +01:00
|
|
|
|
|
|
|
class FileCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*
|
|
|
|
'dir' is the file cache directory to use.
|
|
|
|
*/
|
2017-04-19 00:36:30 +02:00
|
|
|
FileCache(const std::string &dir) : m_dir(dir) {}
|
2017-04-01 14:48:16 +02:00
|
|
|
|
2024-02-17 15:35:33 +01:00
|
|
|
bool update(const std::string &name, std::string_view data);
|
2012-03-25 14:47:51 +03:00
|
|
|
bool load(const std::string &name, std::ostream &os);
|
2020-06-13 19:03:26 +02:00
|
|
|
bool exists(const std::string &name);
|
2017-04-01 14:48:16 +02:00
|
|
|
|
2024-01-20 16:26:05 +01:00
|
|
|
// Copy another file on disk into the cache
|
|
|
|
bool updateCopyFile(const std::string &name, const std::string &src_path);
|
|
|
|
|
2012-02-08 11:49:24 +01:00
|
|
|
private:
|
|
|
|
std::string m_dir;
|
|
|
|
|
2024-01-20 16:26:05 +01:00
|
|
|
void createDir();
|
2012-03-25 11:50:29 +03:00
|
|
|
bool loadByPath(const std::string &path, std::ostream &os);
|
2024-02-17 15:35:33 +01:00
|
|
|
bool updateByPath(const std::string &path, std::string_view data);
|
2012-02-08 11:49:24 +01:00
|
|
|
};
|