]> git.sesse.net Git - casparcg/blob - common/env.cpp
2.0.0.2: Restructuring. Moved protocol code (legacy) into separate project.
[casparcg] / common / env.cpp
1 #include "stdafx.h"\r
2 \r
3 #include "env.h"\r
4 \r
5 #include "utility/string_convert.h"\r
6 \r
7 #include <boost/property_tree/ptree.hpp>\r
8 #include <boost/property_tree/xml_parser.hpp>\r
9 #include <boost/filesystem.hpp>\r
10 #include <boost/thread/once.hpp>\r
11 \r
12 #include <functional>\r
13 \r
14 namespace caspar\r
15 {\r
16 \r
17 std::wstring media;\r
18 std::wstring log;\r
19 std::wstring ftemplate;\r
20 std::wstring data;\r
21 boost::property_tree::ptree pt;\r
22 \r
23 void do_setup()\r
24 {\r
25         std::string initialPath = boost::filesystem::initial_path().file_string();\r
26         \r
27         boost::property_tree::read_xml(initialPath + "\\caspar.config", pt);\r
28 \r
29         auto paths = pt.get_child("configuration.paths");\r
30         media = widen(paths.get("media-path", initialPath + "\\media\\"));\r
31         log = widen(paths.get("log-path", initialPath + "\\log\\"));\r
32         ftemplate = widen(paths.get("template-path", initialPath + "\\template\\"));\r
33         data = widen(paths.get("data-path", initialPath + "\\data\\"));\r
34 }\r
35 \r
36 void setup()\r
37 {\r
38         static boost::once_flag setup_flag = BOOST_ONCE_INIT;\r
39         boost::call_once(do_setup, setup_flag); \r
40 }\r
41         \r
42 const std::wstring& env::media_folder()\r
43 {\r
44         setup();\r
45         return media;\r
46 }\r
47 \r
48 const std::wstring& env::log_folder()\r
49 {\r
50         setup();\r
51         return log;\r
52 }\r
53 \r
54 const std::wstring& env::template_folder()\r
55 {\r
56         setup();\r
57         return ftemplate;\r
58 }\r
59 \r
60 const std::wstring& env::data_folder()\r
61 {\r
62         setup();\r
63         return data;\r
64 }\r
65 \r
66 const std::wstring& env::version()\r
67 {\r
68         static std::wstring ver = L"2.0.0.2";\r
69         return ver;\r
70 }\r
71 \r
72 const std::wstring& env::version_tag()\r
73 {\r
74         static std::wstring tag = L"Experimental";\r
75         return tag;\r
76 }\r
77 \r
78 const boost::property_tree::ptree& env::properties()\r
79 {\r
80         setup();\r
81         return pt;\r
82 }\r
83 \r
84 }