]> git.sesse.net Git - casparcg/blob - common/env.cpp
Added automatic versioning. Needs tortoise to run.
[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 "utility/string_convert.h"\r
8 \r
9 #include <boost/property_tree/ptree.hpp>\r
10 #include <boost/property_tree/xml_parser.hpp>\r
11 #include <boost/filesystem.hpp>\r
12 #include <boost/thread/once.hpp>\r
13 \r
14 #include <functional>\r
15 \r
16 namespace caspar\r
17 {\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 do_setup()\r
27 {\r
28         std::string initialPath = boost::filesystem::initial_path().file_string();\r
29         \r
30         boost::property_tree::read_xml(initialPath + "\\caspar.config", pt);\r
31 \r
32         auto paths = pt.get_child("configuration.paths");\r
33         media = widen(paths.get("media-path", initialPath + "\\media\\"));\r
34         log = widen(paths.get("log-path", initialPath + "\\log\\"));\r
35         ftemplate = widen(paths.get("template-path", initialPath + "\\template\\"));\r
36         ftemplate_host = widen(paths.get("template-host-path", initialPath + "\\template\\cg.fth"));\r
37         data = widen(paths.get("data-path", initialPath + "\\data\\"));\r
38 }\r
39 \r
40 void setup()\r
41 {\r
42         static boost::once_flag setup_flag = BOOST_ONCE_INIT;\r
43         boost::call_once(do_setup, setup_flag); \r
44 }\r
45         \r
46 const std::wstring& env::media_folder()\r
47 {\r
48         setup();\r
49         return media;\r
50 }\r
51 \r
52 const std::wstring& env::log_folder()\r
53 {\r
54         setup();\r
55         return log;\r
56 }\r
57 \r
58 const std::wstring& env::template_folder()\r
59 {\r
60         setup();\r
61         return ftemplate;\r
62 }\r
63 \r
64 const std::wstring& env::template_host()\r
65 {\r
66         setup();\r
67         return ftemplate_host;\r
68 }\r
69 \r
70 \r
71 const std::wstring& env::data_folder()\r
72 {\r
73         setup();\r
74         return data;\r
75 }\r
76 \r
77 const std::wstring& env::version()\r
78 {\r
79         static std::wstring ver = std::wstring(L"") + CASPAR_GEN + L"." + CASPAR_MAYOR + L"." + CASPAR_MINOR + L"." + CASPAR_REV;\r
80         return ver;\r
81 }\r
82 \r
83 const std::wstring& env::version_tag()\r
84 {\r
85         static std::wstring tag = L"Experimental";\r
86         return tag;\r
87 }\r
88 \r
89 const boost::property_tree::ptree& env::properties()\r
90 {\r
91         setup();\r
92         return pt;\r
93 }\r
94 \r
95 }