Skip to content

Commit

Permalink
refactored code, much cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
arthursw committed Oct 2, 2019
1 parent 9fbbedb commit 137647d
Show file tree
Hide file tree
Showing 7 changed files with 419 additions and 602 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
data/
cpp/src/CMakeLists.txt.user
cpp/src/CMakeCache.txt
cpp/src/CMakeLists.txt.user*
cpp/src/*.autosave
cpp/build*
cpp/medInriaPlugin
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ add_executable(${PROJECT_NAME}
main.cpp
)

target_link_libraries(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME}
Qt5::Core
Qt5::Gui
Qt5::Widgets
Expand Down
306 changes: 25 additions & 281 deletions cpp/src/CMakeLists.txt.user

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions cpp/src/executionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ void ExecutionWidget::executionProcessFinished()

void ExecutionWidget::dataReady()
{
QString output = QString::fromUtf8(this->executionProcess->readAll());
string output = this->executionProcess->readAll().toStdString();

regex e("\x1b\[[0-9;]*[mGKF]");

string outputClean = regex_replace(output.toStdString(), e, "");
string outputClean = regex_replace(output, e, "");
this->print(QString::fromStdString(outputClean));
}

Expand Down
71 changes: 35 additions & 36 deletions cpp/src/installer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ bool Installer::isPythonWorking(QWidget *parent, const QString &version)
QProcess pythonProcess(parent);
pythonProcess.start(BoutiquesPaths::Python(), {"--version"});
pythonProcess.waitForFinished();
QString output = QString::fromUtf8(pythonProcess.readAllStandardOutput());
QString error = QString::fromUtf8(pythonProcess.readAllStandardError());
QString pythonVersion = "Python " + version;
return output.contains(pythonVersion) || error.contains(pythonVersion);
std::string output = pythonProcess.readAllStandardOutput().toStdString();
std::string error = pythonProcess.readAllStandardError().toStdString();
std::string pythonVersion = "Python " + version.toStdString();
return output.find(pythonVersion) != std::string::npos || error.find(pythonVersion) != std::string::npos;
}

bool Installer::isDockerWorking(QWidget *parent)
Expand All @@ -64,52 +64,51 @@ bool Installer::isDockerWorking(QWidget *parent)
QProcess dockerProcess(parent);
dockerProcess.start(BoutiquesPaths::Docker(), {"--version"});
dockerProcess.waitForFinished();
QString output = QString::fromUtf8(dockerProcess.readAllStandardOutput());
QString error = QString::fromUtf8(dockerProcess.readAllStandardError());
QString dockerVersion = "Docker version";
return output.contains(dockerVersion) || error.contains(dockerVersion);
std::string output = dockerProcess.readAllStandardOutput().toStdString();
std::string error = dockerProcess.readAllStandardError().toStdString();
std::string dockerVersion = "Docker version";
return output.find(dockerVersion) != std::string::npos || error.find(dockerVersion) != std::string::npos;
}

void Installer::installBoutiques(QWidget *parent, QJsonObject *settings)
{
bool pythonAndDockerAreWorking = true;

if (QSysInfo::productType() == "winrt" || QSysInfo::productType() == "windows") {
#ifdef Q_OS_WIN
// On Windows:

// On Windows:

if(!Installer::isPythonWorking(parent, "3"))
{
// If "BoutiquesGUI-Data/python/python.exe" does not work:
// Install visual studio redistributable (required for python3)
if(!Installer::isPythonWorking(parent, "3"))
{
// If "BoutiquesGUI-Data/python/python.exe" does not work:
// Install visual studio redistributable (required for python3)

QProcess installVisualStudioRedistributableProcess(parent);
installVisualStudioRedistributableProcess.start(BoutiquesPaths::VCRedis(), {"\\q"});
QProcess installVisualStudioRedistributableProcess(parent);
installVisualStudioRedistributableProcess.start(BoutiquesPaths::VCRedis(), {"\\q"});

if (!installVisualStudioRedistributableProcess.waitForFinished())
{
// If the install fails: ask the user to install it manullay
pythonAndDockerAreWorking = false;
QMessageBox::critical(parent, "Could not install Microsoft Visual C++ Redistributable for Visual Studio", "Error while installing Microsoft Visual C++ Redistributable for Visual Studio.\nThis software is required to run python3 and boutiques under windows.\n\nTry to install it manually.");
}
else if(!Installer::isPythonWorking(parent, "3"))
{
// If the install succeeds but python still does not work: ask the user to install python
pythonAndDockerAreWorking = false;
QMessageBox::critical(parent, "Python is not working", "Python.exe (" + BoutiquesPaths::Python() + ") is not working.\n\nYou need a working python3 version at this location to run boutiques tools.");
}
if (!installVisualStudioRedistributableProcess.waitForFinished())
{
// If the install fails: ask the user to install it manullay
pythonAndDockerAreWorking = false;
QMessageBox::critical(parent, "Could not install Microsoft Visual C++ Redistributable for Visual Studio", "Error while installing Microsoft Visual C++ Redistributable for Visual Studio.\nThis software is required to run python3 and boutiques under windows.\n\nTry to install it manually.");
}

} else {
// On Linux:

if(!Installer::isPythonWorking(parent))
else if(!Installer::isPythonWorking(parent, "3"))
{
// If python does not work: ask the user to install it
// If the install succeeds but python still does not work: ask the user to install python
pythonAndDockerAreWorking = false;
QMessageBox::critical(parent, "Could not run Python", "Error while testing Python.\nInstall python 2.7 or 3 to run boutiques tools.");
QMessageBox::critical(parent, "Python is not working", "Python.exe (" + BoutiquesPaths::Python() + ") is not working.\n\nYou need a working python3 version at this location to run boutiques tools.");
}
}
#else
// On Linux:

if(!Installer::isPythonWorking(parent))
{
// If python does not work: ask the user to install it
pythonAndDockerAreWorking = false;
QMessageBox::critical(parent, "Could not run Python", "Error while testing Python.\nInstall python 2.7 or 3 to run boutiques tools.");
}

#endif

if (!Installer::isDockerWorking(parent))
{
Expand Down
Loading

0 comments on commit 137647d

Please sign in to comment.