Commit 0953865a authored by crashmatt's avatar crashmatt

mavlink-ftp : Fixed filepaths for upload

parent 00e14ded
...@@ -475,16 +475,16 @@ void QGCUASFileManager::uploadPath(const QString& toPath, const QFileInfo& uploa ...@@ -475,16 +475,16 @@ void QGCUASFileManager::uploadPath(const QString& toPath, const QFileInfo& uploa
} }
QFile file(uploadFile.absoluteFilePath()); QFile file(uploadFile.absoluteFilePath());
if (!file.open(QIODevice::ReadOnly | QIODevice::Truncate)) { if (!file.open(QIODevice::ReadOnly)) {
_emitErrorMessage(tr("Unable to open local file for upload (%1)").arg(uploadFile.absoluteFilePath())); _emitErrorMessage(tr("Unable to open local file for upload (%1)").arg(uploadFile.absoluteFilePath()));
return; return;
} }
_writeFileAccumulator = file.readAll(); _writeFileAccumulator = file.readAll();
qint64 bytesRead = file.write((const char *)_readFileAccumulator, _readFileAccumulator.length());
if (bytesRead <= 0) {
file.close(); file.close();
if (_writeFileAccumulator.size() == 0) {
_emitErrorMessage(tr("Unable to read data from local file (%1)").arg(uploadFile.absoluteFilePath())); _emitErrorMessage(tr("Unable to read data from local file (%1)").arg(uploadFile.absoluteFilePath()));
return; return;
} }
...@@ -495,7 +495,7 @@ void QGCUASFileManager::uploadPath(const QString& toPath, const QFileInfo& uploa ...@@ -495,7 +495,7 @@ void QGCUASFileManager::uploadPath(const QString& toPath, const QFileInfo& uploa
request.hdr.session = 0; request.hdr.session = 0;
request.hdr.opcode = kCmdCreateFile; request.hdr.opcode = kCmdCreateFile;
request.hdr.offset = 0; request.hdr.offset = 0;
request.hdr.size = bytesRead; request.hdr.size = 0;
_fillRequestWithString(&request, toPath); _fillRequestWithString(&request, toPath);
_sendRequest(&request); _sendRequest(&request);
} }
......
...@@ -100,19 +100,25 @@ void QGCUASFileView::_uploadFile(void) ...@@ -100,19 +100,25 @@ void QGCUASFileView::_uploadFile(void)
_ui.statusText->clear(); _ui.statusText->clear();
// And now download to this location // get and check directory from list view
QString path;
QTreeWidgetItem* item = _ui.treeWidget->currentItem(); QTreeWidgetItem* item = _ui.treeWidget->currentItem();
if (item && item->type() != _typeDir) { if (item && item->type() != _typeDir) {
return; return;
} }
QString targetDir = item->text(0); // Find complete path for upload directory
QString path;
do {
QString name = item->text(0).split("\t")[0]; // Strip off file sizes
path.prepend("/" + name);
item = item->parent();
} while (item);
qDebug() << "Upload: " << path;
QString uploadFromHere = QGCFileDialog::getOpenFileName(this, tr("Upload File"), QString uploadFromHere = QGCFileDialog::getOpenFileName(this, tr("Upload File"),
QDir::homePath()); QDir::homePath());
_manager->uploadPath(targetDir, uploadFromHere); _manager->uploadPath(path, uploadFromHere);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment