config file is now ~/.config/RsyncUI.conf
This commit is contained in:
+21
-9
@@ -19,59 +19,70 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Initialization de la class
|
||||
downloadFile::downloadFile()
|
||||
{
|
||||
}
|
||||
|
||||
//Slot activated when download is cancelled
|
||||
void downloadFile::cancelled(int pid)
|
||||
{
|
||||
if (kill(pid, SIGTERM) == -1)
|
||||
if (pid == 0)
|
||||
{
|
||||
//TODO gestion erreur kill
|
||||
perror("Pid = 0 : I do not kill"); // Error rsync process not launched so it can't be killed
|
||||
}else if (kill(pid, SIGTERM) == -1)
|
||||
{
|
||||
//TODO managing error of kill
|
||||
}
|
||||
}
|
||||
|
||||
// launch a rsync processus downloading a file
|
||||
void downloadFile::download(MainWindow *mw)
|
||||
{
|
||||
string line;
|
||||
string errorRsync;
|
||||
int pos;
|
||||
array<string, 7> argv;
|
||||
array<string,8> argv;
|
||||
stringstream output;
|
||||
vector<string> v;
|
||||
int value;
|
||||
char buffer[4096];
|
||||
|
||||
// Populating array with command and parameters for popen2
|
||||
argv[0] = "/usr/bin/rsync";
|
||||
if (mw->connexion.bandwidthLimit == 0)
|
||||
{
|
||||
argv[1] = "--bwlimit=1000P";
|
||||
}else
|
||||
{
|
||||
output << mw->connexion.bandwidthLimit;
|
||||
argv[1] = "--bwlimit=" + output.str() + mw->connexion.bandwidthLimitUnit;
|
||||
argv[1] = "--bwlimit=" + to_string(mw->connexion.bandwidthLimit) + mw->connexion.bandwidthLimitUnit;
|
||||
}
|
||||
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 + "/";
|
||||
argv[6] = "";
|
||||
argv[6].clear();
|
||||
|
||||
//launching downloading thread
|
||||
FILE * fp = popen2(argv, "r", mw->downloading.pid);
|
||||
if (!fp)
|
||||
if (fp <= (FILE *) 0)
|
||||
{
|
||||
throw runtime_error("popen2() failed!");
|
||||
sprintf(buffer, "popen2() failed!: returning code:%d", fileno(fp));
|
||||
throw runtime_error(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
// waiting rsync output
|
||||
while (fgets(buffer, 4096, fp) != nullptr)
|
||||
{
|
||||
// Downloading is cancelled, we return
|
||||
if (this->canceled == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
line = buffer;
|
||||
|
||||
// extracting percentage of completion
|
||||
pos = line.find('%');
|
||||
if (pos != -1)
|
||||
{
|
||||
@@ -81,9 +92,11 @@ void downloadFile::download(MainWindow *mw)
|
||||
{
|
||||
line.erase(0, pos);
|
||||
value = stoi(line);
|
||||
// sending progress to Main window
|
||||
emit progressSignal(value);
|
||||
}
|
||||
}
|
||||
// download ended
|
||||
}
|
||||
pclose2(fp, mw->downloading.pid);
|
||||
|
||||
@@ -91,4 +104,3 @@ void downloadFile::download(MainWindow *mw)
|
||||
emit progressSignal(100);
|
||||
emit finishedSignal(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user