]> git.sesse.net Git - casparcg/blob - common/env.cpp
git-svn-id: https://casparcg.svn.sourceforge.net/svnroot/casparcg/server/branches...
[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 ftemplate_host;\r
21 std::wstring data;\r
22 boost::property_tree::ptree pt;\r
23 \r
24 void do_setup()\r
25 {\r
26         std::string initialPath = boost::filesystem::initial_path().file_string();\r
27         \r
28         boost::property_tree::read_xml(initialPath + "\\caspar.config", pt);\r
29 \r
30         auto paths = pt.get_child("configuration.paths");\r
31         media = widen(paths.get("media-path", initialPath + "\\media\\"));\r
32         log = widen(paths.get("log-path", initialPath + "\\log\\"));\r
33         ftemplate = widen(paths.get("template-path", initialPath + "\\template\\"));\r
34         ftemplate_host = widen(paths.get("template-host-path", initialPath + "\\template\\cg.fth"));\r
35         data = widen(paths.get("data-path", initialPath + "\\data\\"));\r
36 }\r
37 \r
38 void setup()\r
39 {\r
40         static boost::once_flag setup_flag = BOOST_ONCE_INIT;\r
41         boost::call_once(do_setup, setup_flag); \r
42 }\r
43         \r
44 const std::wstring& env::media_folder()\r
45 {\r
46         setup();\r
47         return media;\r
48 }\r
49 \r
50 const std::wstring& env::log_folder()\r
51 {\r
52         setup();\r
53         return log;\r
54 }\r
55 \r
56 const std::wstring& env::template_folder()\r
57 {\r
58         setup();\r
59         return ftemplate;\r
60 }\r
61 \r
62 const std::wstring& env::template_host()\r
63 {\r
64         setup();\r
65         return ftemplate_host;\r
66 }\r
67 \r
68 \r
69 const std::wstring& env::data_folder()\r
70 {\r
71         setup();\r
72         return data;\r
73 }\r
74 \r
75 const std::wstring& env::version()\r
76 {\r
77         static std::wstring ver = L"2.0.0.2";\r
78         return ver;\r
79 }\r
80 \r
81 const std::wstring& env::version_tag()\r
82 {\r
83         static std::wstring tag = L"Experimental";\r
84         return tag;\r
85 }\r
86 \r
87 const boost::property_tree::ptree& env::properties()\r
88 {\r
89         setup();\r
90         return pt;\r
91 }\r
92 \r
93 }