|
@@ -1,5 +1,8 @@
|
|
#include "../include/FileManager.h"
|
|
#include "../include/FileManager.h"
|
|
|
|
|
|
|
|
+#include <boost/filesystem.hpp>
|
|
|
|
+#include <boost/range/iterator_range.hpp>
|
|
|
|
+
|
|
FileManager::FileManager() {}
|
|
FileManager::FileManager() {}
|
|
|
|
|
|
FileManager::~FileManager() {
|
|
FileManager::~FileManager() {
|
|
@@ -7,7 +10,7 @@ FileManager::~FileManager() {
|
|
closeGetFile();
|
|
closeGetFile();
|
|
}
|
|
}
|
|
|
|
|
|
-bool FileManager::isUploading() { return this->putFile.is_open(); }
|
|
+bool FileManager::isUploading() { return this->putFile.is_open() || !list.empty(); }
|
|
|
|
|
|
bool FileManager::isDownloading() { return this->getFile.is_open(); }
|
|
bool FileManager::isDownloading() { return this->getFile.is_open(); }
|
|
|
|
|
|
@@ -83,22 +86,51 @@ std::vector<char> FileManager::readGet() {
|
|
std::vector<std::string> FileManager::listFiles() {
|
|
std::vector<std::string> FileManager::listFiles() {
|
|
std::vector<std::string> res;
|
|
std::vector<std::string> res;
|
|
|
|
|
|
- boost::filesystem::path p{"."};
|
|
+ for (const auto &entry :
|
|
- for(auto& entry : boost::make_iterator_range(boost::filesystem::directory_iterator(p), {})) {
|
|
+ boost::filesystem::directory_iterator(this->fileDirectory)) {
|
|
- if(boost::filesystem::is_directory(entry.path()))
|
|
+ if (boost::filesystem::is_directory(entry.path()))
|
|
continue;
|
|
continue;
|
|
res.push_back(entry.path().string());
|
|
res.push_back(entry.path().string());
|
|
}
|
|
}
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
-int FileManager::getChunksFromFile(const std::string &filename) {
|
|
+int FileManager::openList() {
|
|
- boost::filesystem::path p{filename};
|
|
+ list = listFiles();
|
|
- boost::filesystem::file_status s = status(p);
|
|
+ int chunks = 0;
|
|
- if(is_directory(s)) {
|
|
+ int cursize = 0;
|
|
- return -1;
|
|
+ for(int i=0; i<list.size(); i++) {
|
|
|
|
+ if(list.at(i).length() > max_data_length)
|
|
|
|
+ return -1;
|
|
|
|
+ cursize += list.at(i).length();
|
|
|
|
+ if(cursize > max_data_length) {
|
|
|
|
+ chunks++;
|
|
|
|
+ i--;
|
|
|
|
+ cursize = 0;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- uintmax_t size = boost::filesystem::file_size(filename);
|
|
+ if(list.size() > 0)
|
|
- int chunks = size / max_data_length + (size % max_data_length == 0 ? 0 : 1);
|
|
+ chunks++;
|
|
return chunks;
|
|
return chunks;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+int FileManager::getListSize() {
|
|
|
|
+ return list.size();
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+std::vector<std::string> FileManager::getNextChunkFromList() {
|
|
|
|
+ std::vector<std::string> ret;
|
|
|
|
+ int cursize = 0;
|
|
|
|
+ std::string tmp;
|
|
|
|
+ while(!list.empty()) {
|
|
|
|
+ tmp = list.back();
|
|
|
|
+ cursize += tmp.length();
|
|
|
|
+ if(cursize>max_data_length) {
|
|
|
|
+ break;
|
|
|
|
+ } else {
|
|
|
|
+ ret.push_back(tmp);
|
|
|
|
+ list.pop_back();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return ret;
|
|
|
|
+}
|