2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG 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 3 of the License, or
9 * (at your option) any later version.
11 * CasparCG 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 CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Robert Nagy, ronag89@gmail.com
26 #include "../version.h"
32 #include <boost/property_tree/ptree.hpp>
33 #include <boost/property_tree/xml_parser.hpp>
34 #include <boost/filesystem.hpp>
35 #include <boost/thread/once.hpp>
40 namespace caspar { namespace env {
44 std::wstring ftemplate;
47 std::wstring thumbnails;
48 boost::property_tree::wptree pt;
50 void check_is_configured()
53 CASPAR_THROW_EXCEPTION(invalid_operation() << msg_info(L"Enviroment properties has not been configured"));
56 void configure(const std::wstring& filename)
60 auto initialPath = boost::filesystem3::initial_path().wstring();
62 std::wifstream file(initialPath + L"\\" + filename);
63 boost::property_tree::read_xml(file, pt, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);
65 auto paths = pt.get_child(L"configuration.paths");
66 media = paths.get(L"media-path", initialPath + L"\\media\\");
67 log = paths.get(L"log-path", initialPath + L"\\log\\");
68 ftemplate = boost::filesystem3::complete(paths.get(L"template-path", initialPath + L"\\template\\")).wstring();
69 data = paths.get(L"data-path", initialPath + L"\\data\\");
70 font = paths.get(L"font-path", initialPath + L"\\fonts\\");
71 thumbnails = paths.get(L"thumbnails-path", initialPath + L"\\data\\");
75 for(auto it = boost::filesystem::directory_iterator(initialPath); it != boost::filesystem::directory_iterator(); ++it)
77 if(it->path().wstring().find(L".fth") != std::wstring::npos)
80 auto to_path = boost::filesystem::path(ftemplate + L"/" + it->path().wstring());
82 if(boost::filesystem::exists(to_path))
83 boost::filesystem::remove(to_path);
85 boost::filesystem::copy_file(from_path, to_path);
91 CASPAR_LOG_CURRENT_EXCEPTION();
92 CASPAR_LOG(error) << L"Failed to copy template-hosts from initial-path to template-path.";
97 CASPAR_LOG(error) << L" ### Invalid configuration file. ###";
105 auto log_path = boost::filesystem::path(log);
106 if(!boost::filesystem::exists(log_path))
107 boost::filesystem::create_directories(log_path);
114 auto media_path = boost::filesystem::path(media);
115 if(!boost::filesystem::exists(media_path))
116 boost::filesystem::create_directories(media_path);
118 auto template_path = boost::filesystem::path(ftemplate);
119 if(!boost::filesystem::exists(template_path))
120 boost::filesystem::create_directories(template_path);
122 auto data_path = boost::filesystem::path(data);
123 if(!boost::filesystem::exists(data_path))
124 boost::filesystem::create_directories(data_path);
126 auto thumbnails_path = boost::filesystem::path(thumbnails);
127 if(!boost::filesystem::exists(thumbnails_path))
128 boost::filesystem::create_directories(thumbnails_path);
132 CASPAR_LOG_CURRENT_EXCEPTION();
133 CASPAR_LOG(error) << L"Failed to create configured directories.";
137 const std::wstring& media_folder()
139 check_is_configured();
143 const std::wstring& log_folder()
145 check_is_configured();
149 const std::wstring& template_folder()
151 check_is_configured();
155 const std::wstring& data_folder()
157 check_is_configured();
161 const std::wstring& font_folder()
163 check_is_configured();
167 const std::wstring& thumbnails_folder()
169 check_is_configured();
173 #define QUOTE(str) #str
174 #define EXPAND_AND_QUOTE(str) QUOTE(str)
176 const std::wstring& version()
178 static std::wstring ver = u16(
179 EXPAND_AND_QUOTE(CASPAR_GEN) "."
180 EXPAND_AND_QUOTE(CASPAR_MAYOR) "."
181 EXPAND_AND_QUOTE(CASPAR_MINOR) "."
187 const boost::property_tree::wptree& properties()
189 check_is_configured();
193 std::wstring system_font_folder()
195 return L"C:\\windows\\Fonts\\";