filecache.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. Copyright (C) 2013 Jonathan Neuschäfer <j.neuschaefer@gmx.net>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU Lesser General Public License as published by
  7. the Free Software Foundation; either version 2.1 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #pragma once
  18. #include <iostream>
  19. #include <string>
  20. #include <string_view>
  21. class FileCache
  22. {
  23. public:
  24. /*
  25. 'dir' is the file cache directory to use.
  26. */
  27. FileCache(const std::string &dir) : m_dir(dir) {}
  28. bool update(const std::string &name, std::string_view data);
  29. bool load(const std::string &name, std::ostream &os);
  30. bool exists(const std::string &name);
  31. // Copy another file on disk into the cache
  32. bool updateCopyFile(const std::string &name, const std::string &src_path);
  33. private:
  34. std::string m_dir;
  35. void createDir();
  36. bool loadByPath(const std::string &path, std::ostream &os);
  37. bool updateByPath(const std::string &path, std::string_view data);
  38. };