Merge 1.70.0-hotfix branch into master.
[dcpomatic.git] / src / lib / file_group.cc
index cdd78c6a30e0427c28887465a93274480934b73f..9d042554c5b8c0649385456895d0358d813a7b0c 100644 (file)
 #include <sndfile.h>
 #include "file_group.h"
 #include "exceptions.h"
+#include "cross.h"
 
 using std::vector;
 using std::cout;
 
+FileGroup::FileGroup ()
+       : _current_path (0)
+       , _current_file (0)
+{
+
+}
+
 FileGroup::FileGroup (boost::filesystem::path p)
        : _current_path (0)
        , _current_file (0)
@@ -49,6 +57,13 @@ FileGroup::~FileGroup ()
        }
 }
 
+void
+FileGroup::set_paths (vector<boost::filesystem::path> const & p)
+{
+       _paths = p;
+       ensure_open_path (0);
+       seek (0, SEEK_SET);
+}
 
 /** Ensure that the given path index in the content is the _current_file */
 void
@@ -64,7 +79,7 @@ FileGroup::ensure_open_path (size_t p) const
        }
 
        _current_path = p;
-       _current_file = fopen (_paths[_current_path].string().c_str(), "rb");
+       _current_file = fopen_boost (_paths[_current_path], "rb");
        if (_current_file == 0) {
                throw OpenFileError (_paths[_current_path]);
        }
@@ -85,7 +100,11 @@ FileGroup::seek (int64_t pos, int whence) const
                for (size_t i = 0; i < _current_path; ++i) {
                        full_pos += boost::filesystem::file_size (_paths[i]);
                }
+#ifdef DCPOMATIC_WINDOWS
+               full_pos += _ftelli64 (_current_file);
+#else          
                full_pos += ftell (_current_file);
+#endif         
                full_pos += pos;
                break;
        case SEEK_END:
@@ -110,7 +129,7 @@ FileGroup::seek (int64_t pos, int whence) const
        }
 
        ensure_open_path (i);
-       fseek (_current_file, sub_pos, SEEK_SET);
+       dcpomatic_fseek (_current_file, sub_pos, SEEK_SET);
        return full_pos;
 }