2 Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
23 #include "dcpomatic_assert.h"
24 #include "compose.hpp"
30 using std::shared_ptr;
34 Uploader::Uploader (function<void (string)> set_status, function<void (float)> set_progress)
35 : _set_progress (set_progress)
36 , _set_status (set_status)
38 _set_status (_("connecting"));
43 Uploader::count_file_sizes (boost::filesystem::path directory) const
45 using namespace boost::filesystem;
47 boost::uintmax_t size = 0;
49 for (auto i: directory_iterator(directory)) {
50 if (is_directory (i.path())) {
51 size += count_file_sizes (i.path());
53 size += file_size (i);
62 Uploader::upload (boost::filesystem::path directory)
64 boost::uintmax_t transferred = 0;
65 upload_directory (directory.parent_path(), directory, transferred, count_file_sizes(directory));
70 Uploader::upload_directory (boost::filesystem::path base, boost::filesystem::path directory, boost::uintmax_t& transferred, boost::uintmax_t total_size)
72 using namespace boost::filesystem;
74 create_directory (remove_prefix(base, directory));
75 for (auto i: directory_iterator(directory)) {
76 if (is_directory(i.path())) {
77 upload_directory (base, i.path(), transferred, total_size);
79 _set_status (String::compose(_("copying %1"), i.path().leaf()));
80 upload_file (i.path(), remove_prefix (base, i.path()), transferred, total_size);
86 boost::filesystem::path
87 Uploader::remove_prefix (boost::filesystem::path prefix, boost::filesystem::path target) const
89 using namespace boost::filesystem;
93 auto i = target.begin ();
94 for (auto j = prefix.begin (); j != prefix.end(); ++j) {
95 DCPOMATIC_ASSERT (*i == *j);
99 for (; i != target.end(); ++i) {