12 using std::string_view;
23 [[nodiscard]]
static string subst(string_view path, string_view before, string_view after)
26 return strCat(after, path.substr(before.size()));
29 [[nodiscard]]
static vector<string> getPathsHelper(
const vector<string>& input)
31 vector<string> result;
32 for (
const auto& s : input) {
48 for (
const auto& s : result) {
54 [[nodiscard]]
static string resolveHelper(
const vector<string>& pathList,
64 for (
const auto& p : pathList) {
72 throw FileException(
filename,
" not found in this context");
76 : paths(std::move(paths_)), savePaths(std::move(savePaths_))
89 if (savePaths2.empty()) {
90 savePaths2 = getPathsHelper(savePaths);
95 result = resolveHelper(savePaths2,
filename);
97 const string& path = savePaths2.front();
111 if (paths2.empty()) {
112 paths2 = getPathsHelper(paths);
122 template<
typename Archive>
125 ar.serialize(
"paths", paths,
126 "savePaths", savePaths);
132 static string backSubstSymbols(string_view path)
152 return { { backSubstSymbols(path) },
192 static const FileContext result{{
string{}}, {
string{}}};
void serialize(Archive &ar, unsigned version)
std::string resolveCreate(std::string_view filename) const
bool isUserContext() const
const std::vector< std::string > & getPaths() const
std::string resolve(std::string_view filename) const
bool startsWith(string_view total, string_view part)
bool exists(zstring_view filename)
Does this file (directory) exists?
string expandTilde(string path)
Expand the '~' character to the users home directory.
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.
const std::string & expandCurrentDirFromDrive(const std::string &path)
Get the current directory of the specified drive Linux: return the given string unchanged.
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()
constexpr const char *const filename
FileContext userFileContext(string_view savePath)
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.
std::string strCat(Ts &&...ts)