]> git.sesse.net Git - casparcg/blobdiff - common/env.cpp
Fixed potential race condition
[casparcg] / common / env.cpp
index 3616397e46e0c04d97973dbf702479dbe059a862..91d0969d3334abe69ec0360e9df39b83267d970a 100644 (file)
@@ -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
@@ -66,12 +67,58 @@ 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
+\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
+       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 +145,17 @@ const std::wstring& data_folder()
        return data;\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
+                       EXPAND_AND_QUOTE(CASPAR_REV)    " " \r
+                       CASPAR_TAG);\r
        return ver;\r
 }\r
 \r