2 Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
25 #include <dcp/filesystem.h>
30 using boost::optional;
33 boost::optional<boost::filesystem::path> State::override_path;
36 /* List of config versions to look for in descending order of preference;
37 * i.e. look at the first one, and if that doesn't exist, try the second, etc.
39 static std::vector<std::string> config_versions = { "2.16" };
43 boost::filesystem::path
44 config_path_or_override (optional<string> version)
46 if (State::override_path) {
47 auto p = *State::override_path;
54 return config_path (version);
58 /** @param file State filename
59 * @return Full path to read @file from.
61 boost::filesystem::path
62 State::read_path (string file)
64 for (auto i: config_versions) {
65 auto full = config_path_or_override(i) / file;
66 if (dcp::filesystem::exists(full)) {
71 return config_path_or_override({}) / file;
75 /** @param file State filename
76 * @return Full path to write @file to.
78 boost::filesystem::path
79 State::write_path (string file)
81 auto p = config_path_or_override(config_versions.front());
82 boost::system::error_code ec;
83 dcp::filesystem::create_directories(p, ec);