#include "downloadfile.h" #include "mainwindow.h" #include "ui_mainwindow.h" #include "tools.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; downloadFile::downloadFile() { } void downloadFile::cancelled(int pid) { if (kill(pid, SIGTERM) == -1) { //TODO gestion erreur kill } } void downloadFile::download(MainWindow *mw) { string line; string errorRsync; int pos; array argv; stringstream output; vector v; int value; char buffer[4096]; argv[0] = "/usr/bin/rsync"; argv[1] = "--bwlimit=" + mw->connexion.bandwidthLimit; argv[2] = "--port=" + to_string(mw->connexion.port); argv[3] = "-P"; argv[4] = mw->connexion.server + "::" + mw->downloading.service + "/" + mw->downloading.path; argv[5] = mw->downloading.savePath + "/"; //unique_ptr pipe(popen(cmd "r"), pclose); FILE * fp = popen2(argv, "r", mw->downloading.pid); if (!fp) { throw runtime_error("popen2() failed!"); return; } while (fgets(buffer, 4096, fp) != nullptr) { if (this->canceled == true) { return; } line = buffer; //cout << line << endl; pos = line.find('%'); if (pos != -1) { line.erase(pos); pos = line.find_last_of(' '); if (pos != -1) { line.erase(0, pos); value = stoi(line); cout << value << endl; emit progressSignal(value); } } } pclose2(fp, mw->downloading.pid); emit progressSignal(100); emit finishedSignal(true); //cout << path << endl; }