2 Copyright (C) 2015 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/>.
22 #include "dcpomatic_assert.h"
23 #include "compose.hpp"
28 using boost::shared_ptr;
29 using boost::function;
31 Uploader::Uploader (function<void (string)> set_status, function<void (float)> set_progress)
32 : _set_progress (set_progress)
33 , _set_status (set_status)
35 _set_status (_("connecting"));
39 Uploader::count_file_sizes (boost::filesystem::path directory) const
41 using namespace boost::filesystem;
43 boost::uintmax_t size = 0;
45 for (directory_iterator i = directory_iterator (directory); i != directory_iterator (); ++i) {
46 if (is_directory (i->path ())) {
47 size += count_file_sizes (i->path ());
49 size += file_size (*i);
57 Uploader::upload (boost::filesystem::path directory)
59 boost::uintmax_t transferred = 0;
60 upload_directory (directory.parent_path (), directory, transferred, count_file_sizes (directory));
64 Uploader::upload_directory (boost::filesystem::path base, boost::filesystem::path directory, boost::uintmax_t& transferred, boost::uintmax_t total_size)
66 using namespace boost::filesystem;
68 create_directory (remove_prefix (base, directory));
69 for (directory_iterator i = directory_iterator (directory); i != directory_iterator (); ++i) {
70 if (is_directory (i->path ())) {
71 upload_directory (base, i->path (), transferred, total_size);
73 _set_status (String::compose (_("copying %1"), i->path().leaf ()));
74 upload_file (i->path (), remove_prefix (base, i->path ()), transferred, total_size);
79 boost::filesystem::path
80 Uploader::remove_prefix (boost::filesystem::path prefix, boost::filesystem::path target) const
82 using namespace boost::filesystem;
86 path::iterator i = target.begin ();
87 for (path::iterator j = prefix.begin (); j != prefix.end(); ++j) {
88 DCPOMATIC_ASSERT (*i == *j);
92 for (; i != target.end(); ++i) {