]> git.sesse.net Git - casparcg/blobdiff - common/env.cpp
Made MIXER CROP work more as one might expect
[casparcg] / common / env.cpp
index 99cf775bb9571fd6a65baeb117a6136ee8dd8ac4..d2e941bbcfafd39f39f6ea4e80b3d26000039be3 100644 (file)
@@ -1,29 +1,32 @@
 /*\r
-* copyright (c) 2010 Sveriges Television AB <info@casparcg.com>\r
+* Copyright 2013 Sveriges Television AB http://casparcg.com/\r
 *\r
-*  This file is part of CasparCG.\r
+* This file is part of CasparCG (www.casparcg.com).\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
+* 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
+* 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
+* Author: Robert Nagy, ronag89@gmail.com\r
 */\r
+\r
 #include "stdafx.h"\r
 \r
 #include "env.h"\r
 \r
 #include "../version.h"\r
 \r
-#include "exception\exceptions.h"\r
+#include "exception/exceptions.h"\r
+#include "log/log.h"\r
 #include "utility/string.h"\r
 \r
 #include <boost/property_tree/ptree.hpp>\r
@@ -42,7 +45,8 @@ std::wstring media;
 std::wstring log;\r
 std::wstring ftemplate;\r
 std::wstring data;\r
-boost::property_tree::ptree pt;\r
+std::wstring thumbnails;\r
+boost::property_tree::wptree pt;\r
 \r
 void check_is_configured()\r
 {\r
@@ -50,25 +54,89 @@ void check_is_configured()
                BOOST_THROW_EXCEPTION(invalid_operation() << msg_info("Enviroment properties has not been configured"));\r
 }\r
 \r
-void configure(const std::string& filename)\r
+void configure(const std::wstring& filename)\r
 {\r
        try\r
        {\r
-               std::string initialPath = boost::filesystem::initial_path().file_string();\r
+               auto initialPath = boost::filesystem::initial_path<boost::filesystem2::wpath>().file_string();\r
        \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 = complete(wpath(widen(paths.get("template-path", initialPath + "\\template\\")))).string();          \r
-               data = widen(paths.get("data-path", initialPath + "\\data\\"));\r
+               std::wifstream file(initialPath + L"\\" + filename);\r
+               boost::property_tree::read_xml(file, pt, boost::property_tree::xml_parser::trim_whitespace | boost::property_tree::xml_parser::no_comments);\r
+\r
+               auto paths = pt.get_child(L"configuration.paths");\r
+               media = widen(paths.get(L"media-path", initialPath + L"\\media\\"));\r
+               log = widen(paths.get(L"log-path", initialPath + L"\\log\\"));\r
+               ftemplate = complete(wpath(widen(paths.get(L"template-path", initialPath + L"\\template\\")))).string();                \r
+               data = widen(paths.get(L"data-path", initialPath + L"\\data\\"));\r
+               thumbnails = widen(paths.get(L"thumbnails-path", initialPath + L"\\thumbnails\\"));\r
+\r
+               //Make sure that all paths have a trailing backslash\r
+               if(media.at(media.length()-1) != L'\\')\r
+                       media.append(L"\\");\r
+               if(log.at(log.length()-1) != L'\\')\r
+                       log.append(L"\\");\r
+               if(ftemplate.at(ftemplate.length()-1) != L'\\')\r
+                       ftemplate.append(L"\\");\r
+               if(data.at(data.length()-1) != L'\\')\r
+                       data.append(L"\\");\r
+               if(thumbnails.at(thumbnails.length()-1) != L'\\')\r
+                       thumbnails.append(L"\\");\r
+\r
+               try\r
+               {\r
+                       for(auto it = boost::filesystem2::wdirectory_iterator(initialPath); it != boost::filesystem2::wdirectory_iterator(); ++it)\r
+                       {\r
+                               if(it->filename().find(L".fth") != std::wstring::npos)                  \r
+                               {\r
+                                       auto from_path = *it;\r
+                                       auto to_path = boost::filesystem2::wpath(ftemplate + L"/" + it->filename());\r
+                               \r
+                                       if(boost::filesystem2::exists(to_path))\r
+                                               boost::filesystem2::remove(to_path);\r
+\r
+                                       boost::filesystem2::copy_file(from_path, to_path);\r
+                               }       \r
+                       }\r
+               }\r
+               catch(...)\r
+               {\r
+                       CASPAR_LOG_CURRENT_EXCEPTION();\r
+                       CASPAR_LOG(error) << L"Failed to copy template-hosts from initial-path to template-path.";\r
+               }\r
        }\r
        catch(...)\r
        {\r
                std::wcout << L" ### Invalid configuration file. ###";\r
                throw;\r
        }\r
+\r
+       try\r
+       {\r
+               auto media_path = boost::filesystem::wpath(media);\r
+               if(!boost::filesystem::exists(media_path))\r
+                       boost::filesystem::create_directory(media_path);\r
+               \r
+               auto log_path = boost::filesystem::wpath(log);\r
+               if(!boost::filesystem::exists(log_path))\r
+                       boost::filesystem::create_directory(log_path);\r
+               \r
+               auto template_path = boost::filesystem::wpath(ftemplate);\r
+               if(!boost::filesystem::exists(template_path))\r
+                       boost::filesystem::create_directory(template_path);\r
+               \r
+               auto data_path = boost::filesystem::wpath(data);\r
+               if(!boost::filesystem::exists(data_path))\r
+                       boost::filesystem::create_directory(data_path);\r
+               \r
+               auto thumbnails_path = boost::filesystem::wpath(thumbnails);\r
+               if(!boost::filesystem::exists(thumbnails_path))\r
+                       boost::filesystem::create_directory(thumbnails_path);\r
+       }\r
+       catch(...)\r
+       {\r
+               CASPAR_LOG_CURRENT_EXCEPTION();\r
+               CASPAR_LOG(error) << L"Failed to create configured directories.";\r
+       }\r
 }\r
        \r
 const std::wstring& media_folder()\r
@@ -95,13 +163,27 @@ const std::wstring& data_folder()
        return data;\r
 }\r
 \r
+const std::wstring& thumbnails_folder()\r
+{\r
+       check_is_configured();\r
+       return thumbnails;\r
+}\r
+\r
+#define QUOTE(str) #str\r
+#define EXPAND_AND_QUOTE(str) QUOTE(str)\r
+\r
 const std::wstring& version()\r
 {\r
-       static std::wstring ver = std::wstring(L"") + CASPAR_GEN + L"." + CASPAR_MAYOR + L"." + CASPAR_MINOR + L"." + CASPAR_REV + L" ALPHA";\r
+       static std::wstring ver = widen(\r
+                       EXPAND_AND_QUOTE(CASPAR_GEN)    "." \r
+                       EXPAND_AND_QUOTE(CASPAR_MAYOR)  "." \r
+                       EXPAND_AND_QUOTE(CASPAR_MINOR)  "." \r
+                       CASPAR_REV      " " \r
+                       CASPAR_TAG);\r
        return ver;\r
 }\r
 \r
-const boost::property_tree::ptree& properties()\r
+const boost::property_tree::wptree& properties()\r
 {\r
        check_is_configured();\r
        return pt;\r