11using std::string_view;
22[[nodiscard]]
static string subst(string_view path, string_view before, string_view after)
24 assert(path.starts_with(before));
25 return strCat(after, path.substr(before.size()));
28[[nodiscard]]
static vector<string> getPathsHelper(std::span<const string> input)
30 vector<string> result;
31 for (
const auto& s : input) {
47 for (
const auto& s : result) {
53[[nodiscard]]
static string resolveHelper(std::span<const string> pathList,
63 for (
const auto& p : pathList) {
71 throw FileException(filename,
" not found in this context");
75 : paths(
std::move(paths_)), savePaths(
std::move(savePaths_))
81 string result = resolveHelper(
getPaths(), filename);
88 if (savePaths2.empty()) {
89 savePaths2 = getPathsHelper(savePaths);
94 result = resolveHelper(savePaths2, filename);
96 const string& path = savePaths2.front();
110 if (paths2.empty()) {
111 paths2 = getPathsHelper(paths);
121template<
typename Archive>
124 ar.serialize(
"paths", paths,
125 "savePaths", savePaths);
131static string backSubstSymbols(string_view path)
134 path.starts_with(systemData)) {
138 path.starts_with(userData)) {
142 path.starts_with(userDir)) {
151 return { { backSubstSymbols(path) },
191 static const FileContext result{{
string{}}, {
string{}}};
void serialize(Archive &ar, unsigned version)
std::string resolveCreate(std::string_view filename) const
std::span< const std::string > getPaths() const
bool isUserContext() const
std::string resolve(std::string_view filename) const
bool exists(zstring_view filename)
Does this file (directory) exists?
string expandTilde(string path)
Expand the '~' character to the users home directory.
const std::string & expandCurrentDirFromDrive(const std::string &path)
Get the current directory of the specified drive Linux: return the given string unchanged.
const string & getUserOpenMSXDir()
Get the openMSX dir in the user's home directory.
bool isAbsolutePath(string_view path)
Checks whether it's a absolute path or not.
const string & getSystemDataDir()
Get system directory.
bool needsTildeExpansion(std::string_view path)
Returns true iff expandTilde(s) would have an effect.
void mkdirp(string path)
Acts like the unix command "mkdir -p".
const string & getUserDataDir()
Get the openMSX data dir in the user's home directory.
string join(string_view part1, string_view part2)
Join two paths.
This file implemented 3 utility functions:
const FileContext & systemFileContext()
const string USER_OPENMSX
FileContext configFileContext(string_view path, string_view hwDescr, string_view userName)
const FileContext & currentDirFileContext()
const FileContext & userFileContext()
FileContext userDataFileContext(string_view subDir)
const FileContext & preferSystemFileContext()
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
constexpr bool contains(ITER first, ITER last, const VAL &val)
Check if a range contains a given value, using linear search.