]> git.sesse.net Git - casparcg/blobdiff - common/env.cpp
Merge pull request #239 from CasparCG/ffmpeg_producer_nb_frames
[casparcg] / common / env.cpp
index 3616397e46e0c04d97973dbf702479dbe059a862..d2e941bbcfafd39f39f6ea4e80b3d26000039be3 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>\r
+* Copyright 2013 Sveriges Television AB http://casparcg.com/\r
 *\r
 * This file is part of CasparCG (www.casparcg.com).\r
 *\r
@@ -25,7 +25,8 @@
 \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
@@ -44,6 +45,7 @@ std::wstring media;
 std::wstring log;\r
 std::wstring ftemplate;\r
 std::wstring data;\r
+std::wstring thumbnails;\r
 boost::property_tree::wptree pt;\r
 \r
 void check_is_configured()\r
@@ -66,12 +68,75 @@ void configure(const std::wstring& filename)
                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
@@ -98,9 +163,23 @@ 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" " + CASPAR_TAG;\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