X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fuploader.cc;h=c5448e469b8c3175ab750496ae4672964cceeb08;hb=07b21bb92a8d54c6c03de9aadc63ab93b65d9bc5;hp=b6b23ed8e5794445594714cf5e055e418ad3d8d1;hpb=b00389305af83dfd1e3b41ab3b108cb591f18c5d;p=dcpomatic.git diff --git a/src/lib/uploader.cc b/src/lib/uploader.cc index b6b23ed8e..c5448e469 100644 --- a/src/lib/uploader.cc +++ b/src/lib/uploader.cc @@ -1,36 +1,44 @@ /* - Copyright (C) 2015 Carl Hetherington + Copyright (C) 2015-2021 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ + #include "uploader.h" #include "dcpomatic_assert.h" +#include "compose.hpp" + +#include "i18n.h" + using std::string; -using boost::shared_ptr; -using boost::function; +using std::shared_ptr; +using std::function; + Uploader::Uploader (function set_status, function set_progress) - : _set_status (set_status) - , _set_progress (set_progress) + : _set_progress (set_progress) + , _set_status (set_status) { - + _set_status (_("connecting")); } + boost::uintmax_t Uploader::count_file_sizes (boost::filesystem::path directory) const { @@ -38,39 +46,43 @@ Uploader::count_file_sizes (boost::filesystem::path directory) const boost::uintmax_t size = 0; - for (directory_iterator i = directory_iterator (directory); i != directory_iterator (); ++i) { - if (is_directory (i->path ())) { - size += count_file_sizes (i->path ()); + for (auto i: directory_iterator(directory)) { + if (is_directory (i.path())) { + size += count_file_sizes (i.path()); } else { - size += file_size (*i); + size += file_size (i); } } return size; } + void Uploader::upload (boost::filesystem::path directory) { boost::uintmax_t transferred = 0; - upload_directory (directory.parent_path (), directory, transferred, count_file_sizes (directory)); + upload_directory (directory.parent_path(), directory, transferred, count_file_sizes(directory)); } + void Uploader::upload_directory (boost::filesystem::path base, boost::filesystem::path directory, boost::uintmax_t& transferred, boost::uintmax_t total_size) { using namespace boost::filesystem; - create_directory (remove_prefix (base, directory)); - for (directory_iterator i = directory_iterator (directory); i != directory_iterator (); ++i) { - if (is_directory (i->path ())) { - upload_directory (base, i->path (), transferred, total_size); + create_directory (remove_prefix(base, directory)); + for (auto i: directory_iterator(directory)) { + if (is_directory(i.path())) { + upload_directory (base, i.path(), transferred, total_size); } else { - upload_file (i->path (), remove_prefix (base, i->path ()), transferred, total_size); + _set_status (String::compose(_("copying %1"), i.path().leaf())); + upload_file (i.path(), remove_prefix (base, i.path()), transferred, total_size); } } } + boost::filesystem::path Uploader::remove_prefix (boost::filesystem::path prefix, boost::filesystem::path target) const { @@ -78,8 +90,8 @@ Uploader::remove_prefix (boost::filesystem::path prefix, boost::filesystem::path path result; - path::iterator i = target.begin (); - for (path::iterator j = prefix.begin (); j != prefix.end(); ++j) { + auto i = target.begin (); + for (auto j = prefix.begin (); j != prefix.end(); ++j) { DCPOMATIC_ASSERT (*i == *j); ++i; }