-— For logging std::cout << "VP1AvailEvtsHttps stage -- " << m_d->m_stage << " -- finished with error=" << (int)m_d->m_netreply->error() << ", sc=" << sc << ", LM=" << lastModified.toStdString() << std::endl;
-— For logging std::cout << " Active Ret Dir: " << activeRetrievalDir.toStdString() << std::endl; std::cout << " Target : " << target.toStdString() << std::endl;
-— For logging std::cout << "\t\t" << target.toStdString() << " written and closed" << std::endl;
234{
237 QVariant
val =
m_d->m_netreply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
238 if(
val.type()==QVariant::Int)
239 sc =
val.value<
int>();
240 else if(
val.type()==QVariant::Invalid)
241 message(
"No status code obtained while processing " +
m_d->m_netreply->url().toString());
242 else if(!
val.canConvert<
int>())
243 message(
"Cannot convert status code to int while processing " +
m_d->m_netreply->url().toString());
244 else
245 sc =
val.value<
int>();
246
248
249 QString lastModified;
250 QVariant lastModHeader =
m_d->m_netreply->header(QNetworkRequest::LastModifiedHeader);
251 if(lastModHeader.type()!=QVariant::Invalid &&
252 lastModHeader.canConvert<QDateTime>()) {
253 QDateTime lastModTime = lastModHeader.value<QDateTime>();
254 lastModified = lastModTime.toString();
255 }
256
263
264 if(
m_d->m_netreply->error()==QNetworkReply::NoError) {
265 if(
m_d->m_stage==0) {
266 if(!lastModified.isEmpty() && lastModified!=
m_d->m_urlLastMod) {
267
268 m_d->m_urlLastMod = std::move(lastModified);
270 } else {
271
273 }
274 }
else if(
m_d->m_stage==1) {
275
277 QString
target = activeRetrievalDir +
"downloadedfileinfo.txt";
282
283
284 if(QFileInfo(target).
exists() && !QFile(target).
remove()) {
285 message(
"ERROR: Could not remove the old fileinfo " + target);
287 m_d->startTimer(
m_d->m_updateInterval);
288 return;
289 }
290
291
292 QFile localfileinfo(target);
293 if(!localfileinfo.open(QIODevice::WriteOnly)) {
294 message(
"ERROR: Unable to open " + target +
" for writing");
296 m_d->startTimer(
m_d->m_updateInterval);
297 return;
298 }
299
300
301 QByteArray ba =
m_d->m_netreply->readAll();
302 localfileinfo.write(ba);
303 localfileinfo.close();
305 }
else if(
m_d->m_stage==2) {
306
308 QFile targetFile(target);
309 if(!targetFile.open(QIODevice::WriteOnly)) {
310 message(
"ERROR: Unable to open " + target +
" for writing");
312 m_d->startTimer(
m_d->m_updateInterval);
313 return;
314 }
315
316
317 QByteArray ba =
m_d->m_netreply->readAll();
318 targetFile.write(ba);
319 targetFile.close();
323
324
327 message(
"Checksum did not match");
328 QFile::remove(target);
330 m_d->startTimer(
m_d->m_updateInterval);
331 return;
332 }
333
335 if(!QFile::rename(target,finalTarget)) {
336 message(
"ERROR: Could not move " + target +
" to " + finalTarget);
337 QFile::remove(target);
338 QFile::remove(finalTarget);
339 } else {
341 }
342
344 }
345 }
346 else
348
349 m_d->m_netreply->blockSignals(
true);
350 m_d->m_netreply->deleteLater();
352
354 m_d->startTimer(interval);
355}
void cleanupAndCheckForEventListChanges()
QString tmpActiveRetrievalDir()
static bool sumMatches(const QString &filename, const QByteArray &md5sum)
static void messageDebug(const QString &)
bool exists(const std::string &filename)
does a file exist
bool match(std::string s1, std::string s2)
match the individual directories of two strings