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
41 using namespace boost::filesystem2;
\r
45 std::wstring ftemplate;
\r
47 boost::property_tree::wptree pt;
\r
49 void check_is_configured()
\r
52 BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Enviroment properties has not been configured"));
\r
55 void configure(const std::wstring& filename)
\r
59 auto initialPath = boost::filesystem::initial_path<boost::filesystem2::wpath>().file_string();
\r
61 std::wifstream file(initialPath + L"\\" + filename);
\r
62 boost::property_tree::read_xml(file, pt, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
\r
64 auto paths = pt.get_child(L"configuration.paths");
\r
65 media = widen(paths.get(L"media-path", initialPath + L"\\media\\"));
\r
66 log = widen(paths.get(L"log-path", initialPath + L"\\log\\"));
\r
67 ftemplate = complete(wpath(widen(paths.get(L"template-path", initialPath + L"\\template\\")))).string();
\r
68 data = widen(paths.get(L"data-path", initialPath + L"\\data\\"));
\r
72 std::wcout << L" ### Invalid configuration file. ###";
\r
77 const std::wstring& media_folder()
\r
79 check_is_configured();
\r
83 const std::wstring& log_folder()
\r
85 check_is_configured();
\r
89 const std::wstring& template_folder()
\r
91 check_is_configured();
\r
95 const std::wstring& data_folder()
\r
97 check_is_configured();
\r
101 const std::wstring& version()
\r
103 static std::wstring ver = std::wstring(L"") + CASPAR_GEN + L"." + CASPAR_MAYOR + L"." + CASPAR_MINOR + L"." + CASPAR_REV + L" " + CASPAR_TAG;
\r
107 const boost::property_tree::wptree& properties()
\r
109 check_is_configured();
\r