27#include "std_filesystem.h"
28#include "model/base_platform.h"
32static fs::path UserPath() {
34 fs::path path(userdir);
36 if (!fs::exists(path)) fs::create_directories(path);
40static fs::path SystemPath() {
41 auto systemdir = g_BasePlatform->GetSharedDataDir().ToStdString();
42 fs::path path(systemdir);
44 assert(fs::exists(path) &&
"System filters not found");
48namespace filters_on_disk {
50std::vector<std::string>
List(
bool include_system) {
51 std::vector<std::string> v;
52 for (
const auto& entry : fs::directory_iterator(UserPath()))
53 v.push_back(entry.path().filename().string());
55 for (
const auto& entry : fs::directory_iterator(SystemPath()))
56 v.push_back(entry.path().stem().string());
58 for (
auto& filter : v) filter = fs::path(filter).stem().string();
50std::vector<std::string>
List(
bool include_system) {
…}
62bool Exists(
const std::string& name) {
63 const std::string filename = name +
".json";
64 if (fs::exists(UserPath() / filename))
return true;
65 return fs::exists(SystemPath() / filename);
68bool Remove(
const std::string& name) {
69 const std::string filename = name +
".json";
70 fs::path path(UserPath() / filename);
72 return !fs::exists(path);
77 const std::string filename = name +
".json";
78 fs::path path(UserPath() / filename);
79 std::ofstream stream(path);
80 if (!stream.is_open())
return false;
86 const std::string filename = name +
".json";
87 fs::path path(UserPath() / filename);
88 if (!fs::exists(path)) path = SystemPath() / filename;
89 std::ifstream stream(path);
std::string to_string() const
Output parsable JSON string representation.
static NavmsgFilter Parse(const std::string &s)
Parse text as created by to_string().
bool IsSystemFilter(std::string &name)
Return true iff name refers to a read-only system filter.
std::vector< std::string > List(bool include_system)
Return list of filters, possibly including also the system ones.
NavmsgFilter Read(const std::string &name)
Read filter with given name from disk.
bool Remove(const std::string &name)
Remove a filter, return ok if no errors.
bool Write(const NavmsgFilter &filter, const std::string &name)
Write contents for given filter to disk.
bool Exists(const std::string &name)
Return true iff filter with given name exists, either system or user defined.