2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
\r
4 * This file is part of CasparCG (www.casparcg.com).
\r
6 * CasparCG is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * CasparCG is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
\r
19 * Author: Robert Nagy, ronag89@gmail.com
\r
26 #include "../version.h"
\r
28 #include "exception\exceptions.h"
\r
29 #include "utility/string.h"
\r
31 #include <boost/property_tree/ptree.hpp>
\r
32 #include <boost/property_tree/xml_parser.hpp>
\r
33 #include <boost/filesystem.hpp>
\r
34 #include <boost/thread/once.hpp>
\r
36 #include <functional>
\r
39 namespace caspar { namespace env {
\r
43 std::string ftemplate;
\r
45 boost::property_tree::ptree pt;
\r
47 void check_is_configured()
\r
50 BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Enviroment properties has not been configured"));
\r
53 void configure(const std::string& filename)
\r
57 auto initialPath = boost::filesystem::initial_path().file_string();
\r
59 std::ifstream file(initialPath + "\\" + filename);
\r
60 boost::property_tree::read_xml(file, pt, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
\r
62 auto paths = pt.get_child("configuration.paths");
\r
63 media = paths.get("media-path", initialPath + "\\media\\");
\r
64 log = paths.get("log-path", initialPath + "\\log\\");
\r
65 ftemplate = boost::filesystem2::complete(paths.get("template-path", initialPath + "\\template\\")).string();
\r
66 data = paths.get("data-path", initialPath + "\\data\\");
\r
70 std::wcout << " ### Invalid configuration file. ###";
\r
75 const std::string& media_folder()
\r
77 check_is_configured();
\r
81 const std::string& log_folder()
\r
83 check_is_configured();
\r
87 const std::string& template_folder()
\r
89 check_is_configured();
\r
93 const std::string& data_folder()
\r
95 check_is_configured();
\r
99 const std::string& version()
\r
101 static std::string ver = std::string("") + CASPAR_GEN + "." + CASPAR_MAYOR + "." + CASPAR_MINOR + "." + CASPAR_REV + " " + CASPAR_TAG;
\r
105 const boost::property_tree::ptree& properties()
\r
107 check_is_configured();
\r