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>
29 using boost::optional;
32 boost::optional<boost::filesystem::path> State::override_path;
35 /* List of config versions to look for in descending order of preference;
36 * i.e. look at the first one, and if that doesn't exist, try the second, etc.
38 static std::vector<std::string> config_versions = { "2.16" };
42 boost::filesystem::path
43 config_path_or_override (optional<string> version)
45 if (State::override_path) {
46 auto p = *State::override_path;
53 return config_path (version);
57 /** @param file State filename
58 * @return Full path to read @file from.
60 boost::filesystem::path
61 State::read_path (string file)
63 for (auto i: config_versions) {
64 auto full = config_path_or_override(i) / file;
65 if (dcp::filesystem::exists(full)) {
70 return config_path_or_override({}) / file;
74 /** @param file State filename
75 * @return Full path to write @file to.
77 boost::filesystem::path
78 State::write_path (string file)
80 auto p = config_path_or_override(config_versions.front());
81 dcp::filesystem::create_directories(p);