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"
24 using boost::shared_ptr;
25 using boost::function;
27 Uploader::Uploader (function<void (string)> set_status, function<void (float)> set_progress)
28 : _set_status (set_status)
29 , _set_progress (set_progress)
35 Uploader::count_file_sizes (boost::filesystem::path directory) const
37 using namespace boost::filesystem;
39 boost::uintmax_t size = 0;
41 for (directory_iterator i = directory_iterator (directory); i != directory_iterator (); ++i) {
42 if (is_directory (i->path ())) {
43 size += count_file_sizes (i->path ());
45 size += file_size (*i);
53 Uploader::upload (boost::filesystem::path directory)
55 boost::uintmax_t transferred = 0;
56 upload_directory (directory.parent_path (), directory, transferred, count_file_sizes (directory));
60 Uploader::upload_directory (boost::filesystem::path base, boost::filesystem::path directory, boost::uintmax_t& transferred, boost::uintmax_t total_size)
62 using namespace boost::filesystem;
64 create_directory (remove_prefix (base, directory));
65 for (directory_iterator i = directory_iterator (directory); i != directory_iterator (); ++i) {
66 if (is_directory (i->path ())) {
67 upload_directory (base, i->path (), transferred, total_size);
69 upload_file (i->path (), remove_prefix (base, i->path ()), transferred, total_size);
74 boost::filesystem::path
75 Uploader::remove_prefix (boost::filesystem::path prefix, boost::filesystem::path target) const
77 using namespace boost::filesystem;
81 path::iterator i = target.begin ();
82 for (path::iterator j = prefix.begin (); j != prefix.end(); ++j) {
83 DCPOMATIC_ASSERT (*i == *j);
87 for (; i != target.end(); ++i) {