Skip to content

Commit

Permalink
Merge #1165 from saifulbkhan/ftr_notify_zlib
Browse files Browse the repository at this point in the history
[Ftr] Notify users about ability to load zlib compressed data
  • Loading branch information
shubhra-agrawal authored Oct 22, 2019
2 parents ca41eb6 + 9e39d68 commit 2e36150
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
65 changes: 64 additions & 1 deletion src/gui/mzroll/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "isotopeswidget.h"
#include "librarymanager.h"
#include "ligandwidget.h"
#include "common/logger.h"
#include "logwidget.h"
#include "mainwindow.h"
#include "masscalcgui.h"
Expand Down Expand Up @@ -182,7 +183,6 @@ using namespace mzUtils;
QString dataDir = ".";
unloadableFiles.reserve(50);


QList<QString> dirs;
dirs << dataDir << QApplication::applicationDirPath()
<< QApplication::applicationDirPath() + "/../Resources/";
Expand Down Expand Up @@ -1587,6 +1587,17 @@ void MainWindow::analyticsAverageSpectra(){

void MainWindow::open()
{
// TODO: temporarily added for informing user, remove after a few releases
if (!_versionRecordExists()) {
QMessageBox msgBox;
msgBox.setText("El-MAVEN is now capable of reading files containing "
"zlib compressed data. Please feel free to load such "
"files, if you have any.");
msgBox.setIcon(QMessageBox::Information);
QPushButton* b = msgBox.addButton("Continue", QMessageBox::AcceptRole);
msgBox.exec();
}

QString dir = ".";

if (settings->contains("lastDir")) {
Expand Down Expand Up @@ -1956,6 +1967,58 @@ void MainWindow::setLastLoadedDatabase(QString filename)
settings->setValue("lastDatabaseFile", filename);
}

bool MainWindow::_versionRecordExists()
{
QString currentVersion = STR(EL_MAVEN_VERSION);
QString versionLogPath = QString(QStandardPaths::writableLocation(
QStandardPaths::GenericConfigLocation)
+ QDir::separator()
+ "ElMaven"
+ QDir::separator()
+ "version.log");

// lambda that can be used to log an entry for the current app version
auto logCurrentVersion = [&]() {
Logger versionLogger(versionLogPath.toStdString(), false, false);
versionLogger.info() << currentVersion.toStdString() << endl;
};

// lambda that checks whether two regex matches represent the same hits
auto sameVersionMatch = [](QRegularExpressionMatch& first,
QRegularExpressionMatch& second) {
// for two successful matches of version strings, one of which might be
// "v0.8.0-beta.2-142-g1d3468ae", checks whether the groups (0.8.0),
// (beta) and (2) match or not; build numbers and tags are disregarded
return (first.captured(2) == second.captured(2)
&& first.captured(4) == second.captured(4)
&& first.captured(6) == second.captured(6));
};

QFile data(versionLogPath);
if (!data.open(QFile::ReadOnly) ) {
qDebug() << "Cannot open file: " << versionLogPath;
logCurrentVersion();
return false;
}

QRegularExpression
ver("v((\\d+\\.\\d+\\.\\d+)(-(beta|alpha))?(\\.(\\d)*)?(-(\\d+))?)");
auto currentVersionMatch = ver.match(currentVersion);

QTextStream stream(&data);
while (!stream.atEnd()) {
QString line = stream.readLine();
auto match = ver.match(line);
if (match.hasMatch()
&& sameVersionMatch(currentVersionMatch, match)) {
return true;
}
}

logCurrentVersion();
return false;
}

void MainWindow::checkCorruptedSampleInjectionOrder()
{

Expand Down
12 changes: 12 additions & 0 deletions src/gui/mzroll/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,18 @@ private Q_SLOTS:
* failed completely, i.e., no compounds were loaded.
*/
void _notifyIfBadCompoundsDB(QString filename, bool failedToLoadCompletely);

/**
* @brief This method allows checking whether a version of the application
* has been run before on a user's system.
* @details If the current running version does not exist in the record, a
* `Logger` is used to add the version to the record, which is a file
* reserved for this purpose. The record will be used in future checks to
* deduce which versions have already been run before.
* @return `true` if the current version has been run on the system before,
* false otherwise.
*/
bool _versionRecordExists();
};

struct FileLoader {
Expand Down

0 comments on commit 2e36150

Please sign in to comment.