]> git.sesse.net Git - casparcg/commitdiff
* Fixed problem where the base path of CLS, CINF, TLS, DATA LIST and THUMBNAIL LIST...
authorHelge Norberg <helge.norberg@svt.se>
Tue, 3 Nov 2015 13:41:13 +0000 (14:41 +0100)
committerHelge Norberg <helge.norberg@svt.se>
Tue, 3 Nov 2015 13:41:13 +0000 (14:41 +0100)
common/CMakeLists.txt
common/filesystem.cpp [new file with mode: 0644]
common/filesystem.h [new file with mode: 0644]
core/thumbnail_generator.cpp
protocol/amcp/AMCPCommandsImpl.cpp

index de5c7c571332f0774b83baf4813d399b709e2d36..0c91e057f424ed458c767ad9b8aac68cfdc542d4 100644 (file)
@@ -9,6 +9,7 @@ set(SOURCES
 
                base64.cpp
                env.cpp
+               filesystem.cpp
                log.cpp
                polling_filesystem_monitor.cpp
                stdafx.cpp
@@ -67,6 +68,7 @@ set(HEADERS
                env.h
                except.h
                executor.h
+               filesystem.h
                filesystem_monitor.h
                forward.h
                future.h
diff --git a/common/filesystem.cpp b/common/filesystem.cpp
new file mode 100644 (file)
index 0000000..c286b6d
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Helge Norberg, helge.norberg@svt.se
+*/
+
+#include "stdafx.h"
+
+#include "filesystem.h"
+
+#include <boost/filesystem/operations.hpp>
+#include <boost/filesystem/path.hpp>
+
+namespace caspar {
+
+boost::filesystem::path get_relative_without_extension(
+               const boost::filesystem::path& file,
+               const boost::filesystem::path& relative_to)
+{
+       auto result = file.stem();
+
+       boost::filesystem::path current_path = file;
+
+       while (true)
+       {
+               current_path = current_path.parent_path();
+
+               if (boost::filesystem::equivalent(current_path, relative_to))
+                       break;
+
+               if (current_path.empty())
+                       throw std::runtime_error("File not relative to folder");
+
+               result = current_path.filename() / result;
+       }
+
+       return result;
+}
+
+}
diff --git a/common/filesystem.h b/common/filesystem.h
new file mode 100644 (file)
index 0000000..df5bf2b
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+* Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
+*
+* This file is part of CasparCG (www.casparcg.com).
+*
+* CasparCG is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* CasparCG is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
+*
+* Author: Helge Norberg, helge.norberg@svt.se
+*/
+
+#pragma once
+
+#include <boost/filesystem/path.hpp>
+
+#include <string>
+
+namespace caspar {
+
+boost::filesystem::path get_relative_without_extension(
+               const boost::filesystem::path& file,
+               const boost::filesystem::path& relative_to);
+
+}
index fd3ccb1886cda53eb0d7d60995b88ba0fbfea789..f08e2f97384902840e6382c3f27c3290fa5a6d6d 100644 (file)
@@ -35,6 +35,7 @@
 #include <tbb/atomic.h>
 
 #include <common/diagnostics/graph.h>
+#include <common/filesystem.h>
 
 #include "producer/frame_producer.h"
 #include "consumer/frame_consumer.h"
 
 namespace caspar { namespace core {
 
-std::wstring get_relative_without_extension(
-               const boost::filesystem::path& file,
-               const boost::filesystem::path& relative_to)
-{
-       auto result = file.stem();
-
-       boost::filesystem::path current_path = file;
-
-       while (true)
-       {
-               current_path = current_path.parent_path();
-
-               if (boost::filesystem::equivalent(current_path, relative_to))
-                       break;
-
-               if (current_path.empty())
-                       throw std::runtime_error("File not relative to folder");
-
-               result = current_path.filename() / result;
-       }
-
-       return result.wstring();
-}
-
 struct thumbnail_output
 {
        tbb::atomic<int> sleep_millis;
@@ -168,7 +145,7 @@ public:
                                std::insert_iterator<std::set<std::wstring>>(
                                                relative_without_extensions,
                                                relative_without_extensions.end()),
-                               boost::bind(&get_relative_without_extension, _1, media_path_));
+                               [&](const path& p) { return get_relative_without_extension(p, media_path_).wstring(); });
 
                for (boost::filesystem::wrecursive_directory_iterator iter(thumbnails_path_); iter != boost::filesystem::wrecursive_directory_iterator(); ++iter)
                {
@@ -178,11 +155,11 @@ public:
                                continue;
 
                        auto relative_without_extension = get_relative_without_extension(path, thumbnails_path_);
-                       bool no_corresponding_media_file = relative_without_extensions.find(relative_without_extension) 
+                       bool no_corresponding_media_file = relative_without_extensions.find(relative_without_extension.wstring()
                                        == relative_without_extensions.end();
 
                        if (no_corresponding_media_file)
-                               remove(thumbnails_path_ / (relative_without_extension + L".png"));
+                               remove(thumbnails_path_ / (relative_without_extension.wstring() + L".png"));
                }
        }
 
@@ -221,7 +198,7 @@ public:
                        break;
                case filesystem_event::REMOVED:
                        auto relative_without_extension = get_relative_without_extension(file, media_path_);
-                       boost::filesystem::remove(thumbnails_path_ / (relative_without_extension + L".png"));
+                       boost::filesystem::remove(thumbnails_path_ / (relative_without_extension.wstring() + L".png"));
                        media_info_repo_->remove(file.wstring());
 
                        break;
@@ -232,7 +209,7 @@ public:
        {
                using namespace boost::filesystem;
 
-               auto png_file = thumbnails_path_ / (get_relative_without_extension(file, media_path_) + L".png");
+               auto png_file = thumbnails_path_ / (get_relative_without_extension(file, media_path_).wstring() + L".png");
 
                if (!exists(png_file))
                        return true;
@@ -263,7 +240,7 @@ public:
        void generate_thumbnail(const boost::filesystem::path& file)
        {
                auto media_file = get_relative_without_extension(file, media_path_);
-               auto png_file = thumbnails_path_ / (media_file + L".png");
+               auto png_file = thumbnails_path_ / (media_file.wstring() + L".png");
                std::promise<void> thumbnail_ready;
 
                {
@@ -273,7 +250,7 @@ public:
                        {
                                producer = producer_registry_->create_thumbnail_producer(
                                                frame_producer_dependencies(image_mixer_, { }, format_desc_, producer_registry_),
-                                               media_file);
+                                               media_file.wstring());
                        }
                        catch (const boost::thread_interrupted&)
                        {
index 57ad98ad2fa57287abc99f0ab554b4d60653a1e4..181e8ac20248cd9607d2213ace3eb3f343596d3c 100644 (file)
@@ -38,6 +38,7 @@
 #include <common/os/filesystem.h>
 #include <common/base64.h>
 #include <common/thread_info.h>
+#include <common/filesystem.h>
 
 #include <core/producer/cg_proxy.h>
 #include <core/producer/frame_producer.h>
@@ -208,7 +209,7 @@ std::wstring MediaInfo(const boost::filesystem::path& path, const spl::shared_pt
 
        auto is_not_digit = [](char c){ return std::isdigit(c) == 0; };
 
-       auto relativePath = boost::filesystem::path(path.wstring().substr(env::media_folder().size() - 1, path.wstring().size()));
+       auto relativePath = get_relative_without_extension(path, env::media_folder());
 
        auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(path)));
        writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), is_not_digit), writeTimeStr.end());
@@ -249,7 +250,7 @@ std::wstring ListTemplates(const spl::shared_ptr<core::cg_producer_registry>& cg
        {               
                if(boost::filesystem::is_regular_file(itr->path()) && cg_registry->is_cg_extension(itr->path().extension().wstring()))
                {
-                       auto relativePath = boost::filesystem::path(itr->path().wstring().substr(env::template_folder().size()-1, itr->path().wstring().size()));
+                       auto relativePath = get_relative_without_extension(itr->path(), env::template_folder());
 
                        auto writeTimeStr = boost::posix_time::to_iso_string(boost::posix_time::from_time_t(boost::filesystem::last_write_time(itr->path())));
                        writeTimeStr.erase(std::remove_if(writeTimeStr.begin(), writeTimeStr.end(), [](char c){ return std::isdigit(c) == 0;}), writeTimeStr.end());
@@ -856,7 +857,7 @@ std::wstring data_list_command(command_context& ctx)
                        if (!boost::iequals(itr->path().extension().wstring(), L".ftd"))
                                continue;
 
-                       auto relativePath = boost::filesystem::path(itr->path().wstring().substr(env::data_folder().size() - 1, itr->path().wstring().size()));
+                       auto relativePath = get_relative_without_extension(itr->path(), env::data_folder());
 
                        auto str = relativePath.replace_extension(L"").generic_wstring();
                        if (str[0] == L'\\' || str[0] == L'/')
@@ -2086,7 +2087,7 @@ std::wstring thumbnail_list_command(command_context& ctx)
                        if (!boost::iequals(itr->path().extension().wstring(), L".png"))
                                continue;
 
-                       auto relativePath = boost::filesystem::path(itr->path().wstring().substr(env::thumbnails_folder().size() - 1, itr->path().wstring().size()));
+                       auto relativePath = get_relative_without_extension(itr->path(), env::thumbnails_folder());
 
                        auto str = relativePath.replace_extension(L"").generic_wstring();
                        if (str[0] == '\\' || str[0] == '/')