Fission FSN
Loading...
Searching...
No Matches
fsCShareCache.h
Go to the documentation of this file.
1/********************************************************************
2*
3* File: fsCShareCache.h
4*
5* Purpose: Folder of rendered share cards. The OS may still be reading
6* a file after the share returns, so old files are pruned
7* rather than deleted straight away.
8*
9*********************************************************************/
10
11#ifndef fsCShareCachehdr
12#define fsCShareCachehdr
13
14#include <cstddef>
15#include <cstdint>
16#include <filesystem>
17#include <string>
18
19// A path as UTF-8 text in C++17 and C++20 (where u8string() became std::u8string).
20inline std::string fsSharePathUtf8(const std::filesystem::path& path)
21{
22#if defined(__cpp_char8_t)
23 const auto text = path.u8string();
24 return std::string(text.begin(), text.end());
25#else
26 return path.u8string();
27#endif
28}
29
31{
32public:
33 fsCShareCache(std::filesystem::path root, std::size_t keep = 10);
34
35 // <root>/<utcMs>/<name>.<ext>, creating the folders. The name is what share sheets and recipients
36 // see (e.g. "Canvas Trails - Texas"), so the time lives in the folder. extension includes the dot.
37 std::filesystem::path pathMake(const std::string& name, const std::string& extension, std::int64_t utcMs) const;
38
39 // Writes bytes (e.g. a packed asset) to a new cache file; empty path on failure.
40 std::filesystem::path write(const std::string& name, const std::string& extension, std::int64_t utcMs,
41 const std::string& bytes) const;
42
43 // Keeps the newest shares, by the time in their folder (or legacy "<moment>-<utcMs>" file) name.
44 void prune() const;
45
46 const std::filesystem::path& rootGet() const;
47
48private:
49 std::filesystem::path mRoot;
50 std::size_t mKeep;
51};
52
53#endif
const std::filesystem::path & rootGet() const
Definition fsCShareCache.cpp:86
std::filesystem::path write(const std::string &name, const std::string &extension, std::int64_t utcMs, const std::string &bytes) const
Definition fsCShareCache.cpp:42
void prune() const
Definition fsCShareCache.cpp:49
std::filesystem::path pathMake(const std::string &name, const std::string &extension, std::int64_t utcMs) const
Definition fsCShareCache.cpp:33
fsCShareCache(std::filesystem::path root, std::size_t keep=10)
Definition fsCShareCache.cpp:27
std::string fsSharePathUtf8(const std::filesystem::path &path)
Definition fsCShareCache.h:20
decltype(sizeof(void *)) size_t
Definition doctest.h:524