X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fstate.cc;h=e22f9e0b98bd71d37f4e6947d1563b1b6afd01c2;hb=dd3ddb4359a9f8b7ce08ce92e0315dccc65bf40b;hp=5f7e9a701bebcb0ee9272ab79ef99457912c9952;hpb=33e13c4053138930f4b2f59349e441c76111059d;p=dcpomatic.git diff --git a/src/lib/state.cc b/src/lib/state.cc index 5f7e9a701..e22f9e0b9 100644 --- a/src/lib/state.cc +++ b/src/lib/state.cc @@ -19,33 +19,70 @@ */ -#include "state.h" #include "cross.h" +#include "state.h" +#include "util.h" #include using std::string; +using boost::optional; boost::optional State::override_path; +/* List of config versions to look for in descending order of preference; + * i.e. look at the first one, and if that doesn't exist, try the second, etc. + */ +static std::vector config_versions = { "2.16" }; + + +static +boost::filesystem::path +config_path_or_override (optional version) +{ + if (State::override_path) { + auto p = *State::override_path; + if (version) { + p /= *version; + } + return p; + } + + return config_path (version); +} + + /** @param file State filename - * @return Full path to write @file to. + * @return Full path to read @file from. */ boost::filesystem::path -State::path (string file, bool create_directories) +State::read_path (string file) { - boost::filesystem::path p; - if (override_path) { - p = *override_path; - } else { - p = config_path (); + using namespace boost::filesystem; + + for (auto i: config_versions) { + auto full = config_path_or_override(i) / file; + if (exists(full)) { + return full; + } } + + return config_path_or_override({}) / file; +} + + +/** @param file State filename + * @return Full path to write @file to. + */ +boost::filesystem::path +State::write_path (string file) +{ + boost::filesystem::path p = config_path_or_override(config_versions.front()); boost::system::error_code ec; - if (create_directories) { - boost::filesystem::create_directories (p, ec); - } + boost::filesystem::create_directories (p, ec); p /= file; return p; } +