]> git.sesse.net Git - casparcg/blobdiff - common/filesystem.cpp
[psd] Fixed wrong animation pace when interlaced video formats are used.
[casparcg] / common / filesystem.cpp
index c286b6d57d3ab6981020f9a0c582a63e582df0dd..877ac7ca68f6c8310d2488d1c83ad16bf2549d7f 100644 (file)
 #include "stdafx.h"
 
 #include "filesystem.h"
+#include "except.h"
 
 #include <boost/filesystem/operations.hpp>
 #include <boost/filesystem/path.hpp>
 
 namespace caspar {
 
-boost::filesystem::path get_relative_without_extension(
+boost::filesystem::path get_relative(
                const boost::filesystem::path& file,
                const boost::filesystem::path& relative_to)
 {
-       auto result = file.stem();
+       auto result                     = file.filename();
+       auto current_path       = file;
 
-       boost::filesystem::path current_path = file;
+       if (boost::filesystem::equivalent(current_path, relative_to))
+               return L"";
 
        while (true)
        {
@@ -44,7 +47,7 @@ boost::filesystem::path get_relative_without_extension(
                        break;
 
                if (current_path.empty())
-                       throw std::runtime_error("File not relative to folder");
+                       CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info("File " + file.string() + " not relative to folder " + relative_to.string()));
 
                result = current_path.filename() / result;
        }
@@ -52,4 +55,13 @@ boost::filesystem::path get_relative_without_extension(
        return result;
 }
 
+boost::filesystem::path get_relative_without_extension(
+               const boost::filesystem::path& file,
+               const boost::filesystem::path& relative_to)
+{
+       return get_relative(
+                       file.parent_path() / file.stem(),
+                       relative_to);
+}
+
 }