2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "dcpomatic_assert.h"
22 #include "compose.hpp"
27 using boost::shared_ptr;
28 using boost::function;
30 Uploader::Uploader (function<void (string)> set_status, function<void (float)> set_progress)
31 : _set_progress (set_progress)
32 , _set_status (set_status)
34 _set_status (_("connecting"));
38 Uploader::count_file_sizes (boost::filesystem::path directory) const
40 using namespace boost::filesystem;
42 boost::uintmax_t size = 0;
44 for (directory_iterator i = directory_iterator (directory); i != directory_iterator (); ++i) {
45 if (is_directory (i->path ())) {
46 size += count_file_sizes (i->path ());
48 size += file_size (*i);
56 Uploader::upload (boost::filesystem::path directory)
58 boost::uintmax_t transferred = 0;
59 upload_directory (directory.parent_path (), directory, transferred, count_file_sizes (directory));
63 Uploader::upload_directory (boost::filesystem::path base, boost::filesystem::path directory, boost::uintmax_t& transferred, boost::uintmax_t total_size)
65 using namespace boost::filesystem;
67 create_directory (remove_prefix (base, directory));
68 for (directory_iterator i = directory_iterator (directory); i != directory_iterator (); ++i) {
69 if (is_directory (i->path ())) {
70 upload_directory (base, i->path (), transferred, total_size);
72 _set_status (String::compose (_("copying %1"), i->path().leaf ()));
73 upload_file (i->path (), remove_prefix (base, i->path ()), transferred, total_size);
78 boost::filesystem::path
79 Uploader::remove_prefix (boost::filesystem::path prefix, boost::filesystem::path target) const
81 using namespace boost::filesystem;
85 path::iterator i = target.begin ();
86 for (path::iterator j = prefix.begin (); j != prefix.end(); ++j) {
87 DCPOMATIC_ASSERT (*i == *j);
91 for (; i != target.end(); ++i) {