From 8c12cefa8a3726b5d2dba48cb5ae02f29c5a317e Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Sat, 15 Apr 2017 11:13:21 +0100 Subject: [PATCH] SixCycle - Support Compressed Download .. where file name is e.g. tcx_*.gz to indicate a TCX file using gzip compression. --- src/Cloud/CloudService.cpp | 10 +++++++--- src/Cloud/SixCycle.cpp | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Cloud/CloudService.cpp b/src/Cloud/CloudService.cpp index 67055e267..2ddd63388 100644 --- a/src/Cloud/CloudService.cpp +++ b/src/Cloud/CloudService.cpp @@ -234,7 +234,11 @@ CloudService::uncompressRide(QByteArray *data, QString name, QStringList &errors QByteArray jsonData; - if (downloadCompression == zip) { + // some services will offer file as compressed or uncompressed + // data. In which case they must add .zip or .gz to the end of the + // filename to indicate it. The file format must still be included + // in the name e.g. .pwx.gz or .fit.zip + if (name.endsWith(".zip")) { // write out to a zip file first QTemporaryFile zipfile; zipfile.open(); @@ -247,7 +251,7 @@ CloudService::uncompressRide(QByteArray *data, QString name, QStringList &errors jsonData = reader.fileData(info.filePath); // name without the .zip name = name.mid(0, name.length()-4); - } else if (downloadCompression == gzip) { + } else if (name.endsWith(".gz")) { jsonData = gUncompress(*data); // name without the .gz name = name.mid(0, name.length()-3); @@ -255,7 +259,7 @@ CloudService::uncompressRide(QByteArray *data, QString name, QStringList &errors jsonData = *data; } - // uncompress and write to tmp + // uncompress and write to tmp preserviing the file extension QString tmp = context->athlete->home->temp().absolutePath() + "/" + QFileInfo(name).baseName() + "." + QFileInfo(name).suffix(); // uncompress and write a file diff --git a/src/Cloud/SixCycle.cpp b/src/Cloud/SixCycle.cpp index 5d1cb409b..be4c5aa78 100644 --- a/src/Cloud/SixCycle.cpp +++ b/src/Cloud/SixCycle.cpp @@ -279,6 +279,16 @@ SixCycle::readdir(QString path, QStringList &errors, QDateTime from, QDateTime t //add->name = name; QString dateString = each["activityStartDateTime"].toString(); QString suffix = QFileInfo(add->id).suffix(); + + // data might be compressed remotely, need to adapt to their scheme of naming + // the rawfiles with the format at the front and compression at the back of the + // filename; e.g: + // https://s3.amazonaws.com/sixcycle/rawFiles/tcx_ba4319c2-a6dd-4503-9a50-0cb1f0f832ab.gz + // + if (suffix == "gz") { + QString prefix = add->id.split("/").last().split("_").first(); + suffix = prefix + "." + suffix; + } QDateTime startTime= QDateTime::fromString(dateString, Qt::ISODate).toLocalTime(); QChar zero = QLatin1Char ( '0' ); add->name = QString ( "%1_%2_%3_%4_%5_%6.%7" ) @@ -463,8 +473,8 @@ SixCycle::readFileCompleted() printd("reply begins:%s", buffers.value(reply)->toStdString().substr(0,80).c_str()); - // lets not override the date use an unformatted file name - QString name = QString("temp.%1").arg(QFileInfo(replyName(reply)).suffix()); + // lets not override the date use an unformatted file name, keeping any .tcx.gz style suffix + QString name = QString("temp.%1").arg(QFileInfo(replyName(reply)).completeSuffix()); // process it then ........ notifyReadComplete(buffers.value(reply), name, tr("Completed."));