]> git.sesse.net Git - casparcg/blob - common/env.cpp
2.0.0.2: - Cleanup and improvements in main.cpp.
[casparcg] / common / env.cpp
1 #include "stdafx.h"\r
2 \r
3 #include "env.h"\r
4 \r
5 #include "../version.h"\r
6 \r
7 #include "exception\exceptions.h"\r
8 #include "utility/string.h"\r
9 \r
10 #include <boost/property_tree/ptree.hpp>\r
11 #include <boost/property_tree/xml_parser.hpp>\r
12 #include <boost/filesystem.hpp>\r
13 #include <boost/thread/once.hpp>\r
14 \r
15 #include <functional>\r
16 \r
17 namespace caspar { namespace env {\r
18 \r
19 std::wstring media;\r
20 std::wstring log;\r
21 std::wstring ftemplate;\r
22 std::wstring ftemplate_host;\r
23 std::wstring data;\r
24 boost::property_tree::ptree pt;\r
25 \r
26 void check_is_configured()\r
27 {\r
28         if(pt.empty())\r
29                 BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Enviroment properties has not been configured"));\r
30 }\r
31 \r
32 void configure(const std::string& filename)\r
33 {\r
34         std::string initialPath = boost::filesystem::initial_path().file_string();\r
35         \r
36         boost::property_tree::read_xml(initialPath + "\\" + filename, pt);\r
37 \r
38         auto paths = pt.get_child("configuration.paths");\r
39         media = widen(paths.get("media-path", initialPath + "\\media\\"));\r
40         log = widen(paths.get("log-path", initialPath + "\\log\\"));\r
41         ftemplate = widen(paths.get("template-path", initialPath + "\\template\\"));\r
42         ftemplate_host = widen(paths.get("template-host", "cg.fth"));\r
43         data = widen(paths.get("data-path", initialPath + "\\data\\"));\r
44 }\r
45         \r
46 const std::wstring& media_folder()\r
47 {\r
48         check_is_configured();\r
49         return media;\r
50 }\r
51 \r
52 const std::wstring& log_folder()\r
53 {\r
54         check_is_configured();\r
55         return log;\r
56 }\r
57 \r
58 const std::wstring& template_folder()\r
59 {\r
60         check_is_configured();\r
61         return ftemplate;\r
62 }\r
63 \r
64 const std::wstring& template_host()\r
65 {\r
66         check_is_configured();\r
67         return ftemplate_host;\r
68 }\r
69 \r
70 const std::wstring& data_folder()\r
71 {\r
72         check_is_configured();\r
73         return data;\r
74 }\r
75 \r
76 const std::wstring& version()\r
77 {\r
78         static std::wstring ver = std::wstring(L"") + CASPAR_GEN + L"." + CASPAR_MAYOR + L"." + CASPAR_MINOR + L"." + CASPAR_REV;\r
79         return ver;\r
80 }\r
81 \r
82 const boost::property_tree::ptree& properties()\r
83 {\r
84         check_is_configured();\r
85         return pt;\r
86 }\r
87 \r
88 }}