]> git.sesse.net Git - casparcg/blobdiff - common/env.cpp
2.0.0.2: Added UNSTABLE warning.
[casparcg] / common / env.cpp
index ff4cd92a2cbe431f5a7e89c905dac24e1caa1004..ce392f0826487dd4fd039176344aa0bcd78f9fe6 100644 (file)
@@ -1,8 +1,30 @@
+/*\r
+* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+*\r
+*  This file is part of CasparCG.\r
+*\r
+*    CasparCG is free software: you can redistribute it and/or modify\r
+*    it under the terms of the GNU General Public License as published by\r
+*    the Free Software Foundation, either version 3 of the License, or\r
+*    (at your option) any later version.\r
+*\r
+*    CasparCG is distributed in the hope that it will be useful,\r
+*    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+*    GNU General Public License for more details.\r
+\r
+*    You should have received a copy of the GNU General Public License\r
+*    along with CasparCG.  If not, see <http://www.gnu.org/licenses/>.\r
+*\r
+*/\r
 #include "stdafx.h"\r
 \r
 #include "env.h"\r
 \r
-#include "utility/string_convert.h"\r
+#include "../version.h"\r
+\r
+#include "exception\exceptions.h"\r
+#include "utility/string.h"\r
 \r
 #include <boost/property_tree/ptree.hpp>\r
 #include <boost/property_tree/xml_parser.hpp>\r
 \r
 #include <functional>\r
 \r
-namespace caspar\r
-{\r
+namespace caspar { namespace env {\r
 \r
 std::wstring media;\r
 std::wstring log;\r
 std::wstring ftemplate;\r
+std::wstring ftemplate_host;\r
 std::wstring data;\r
 boost::property_tree::ptree pt;\r
 \r
-void do_setup()\r
+void check_is_configured()\r
+{\r
+       if(pt.empty())\r
+               BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Enviroment properties has not been configured"));\r
+}\r
+\r
+void configure(const std::string& filename)\r
 {\r
        std::string initialPath = boost::filesystem::initial_path().file_string();\r
        \r
-       boost::property_tree::read_xml(initialPath + "\\caspar.config", pt);\r
+       boost::property_tree::read_xml(initialPath + "\\" + filename, pt);\r
 \r
        auto paths = pt.get_child("configuration.paths");\r
        media = widen(paths.get("media-path", initialPath + "\\media\\"));\r
        log = widen(paths.get("log-path", initialPath + "\\log\\"));\r
        ftemplate = widen(paths.get("template-path", initialPath + "\\template\\"));\r
+       ftemplate_host = widen(paths.get("template-host", "cg.fth"));\r
        data = widen(paths.get("data-path", initialPath + "\\data\\"));\r
 }\r
-\r
-void setup()\r
-{\r
-       static boost::once_flag setup_flag = BOOST_ONCE_INIT;\r
-       boost::call_once(do_setup, setup_flag); \r
-}\r
        \r
-const std::wstring& env::media_folder()\r
+const std::wstring& media_folder()\r
 {\r
-       setup();\r
+       check_is_configured();\r
        return media;\r
 }\r
 \r
-const std::wstring& env::log_folder()\r
+const std::wstring& log_folder()\r
 {\r
-       setup();\r
+       check_is_configured();\r
        return log;\r
 }\r
 \r
-const std::wstring& env::template_folder()\r
+const std::wstring& template_folder()\r
 {\r
-       setup();\r
+       check_is_configured();\r
        return ftemplate;\r
 }\r
 \r
-const std::wstring& env::data_folder()\r
+const std::wstring& template_host()\r
 {\r
-       setup();\r
-       return data;\r
+       check_is_configured();\r
+       return ftemplate_host;\r
 }\r
 \r
-const std::wstring& env::version()\r
+const std::wstring& data_folder()\r
 {\r
-       static std::wstring ver = L"2.0.0.2";\r
-       return ver;\r
+       check_is_configured();\r
+       return data;\r
 }\r
 \r
-const std::wstring& env::version_tag()\r
+const std::wstring& version()\r
 {\r
-       static std::wstring tag = L"Experimental";\r
-       return tag;\r
+       static std::wstring ver = std::wstring(L"") + CASPAR_GEN + L"." + CASPAR_MAYOR + L"." + CASPAR_MINOR + L"." + CASPAR_REV + L" UNSTABLE";\r
+       return ver;\r
 }\r
 \r
-const boost::property_tree::ptree& env::properties()\r
+const boost::property_tree::ptree& properties()\r
 {\r
-       setup();\r
+       check_is_configured();\r
        return pt;\r
 }\r
 \r
-}
\ No newline at end of file
+}}
\ No newline at end of file