From 7c26526d788ac87a822950d90c7b21c1148449c5 Mon Sep 17 00:00:00 2001 From: Julian POIDEVIN Date: Thu, 9 Mar 2017 23:08:25 +0100 Subject: [PATCH] Fixes #5 --- main.cpp | 1 - mainwindow.cpp | 57 ++++++++++++++++++++++++++++++++++++++++---------- mainwindow.h | 6 ++++++ 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/main.cpp b/main.cpp index cd75e58..1a34348 100644 --- a/main.cpp +++ b/main.cpp @@ -9,6 +9,5 @@ int main(int argc, char *argv[]) ui.show(); - return app.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 91df2e6..b24bb8d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -15,6 +15,12 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::exit() +{ + close(); + qApp->quit(); +} + void MainWindow::on_patchButton_clicked() { //Display Warning Message @@ -47,24 +53,40 @@ void MainWindow::on_restoreButton_clicked() void MainWindow::init() { + ui->patchButton->setEnabled(false); ui->restoreButton->setEnabled(false); //Search for compatibility - isCompatibleVersion(getMBPModelVersion()); - - ui->patchButton->setEnabled(true); - ui->restoreButton->setEnabled(true); + if(isCompatibleVersion(getMBPModelVersion())) + { + ui->patchButton->setEnabled(true); + ui->restoreButton->setEnabled(true); + } + else + { + QMessageBox *QuitWindow = new QMessageBox; + QuitWindow->information(this,"Mac not compatible","Sorry, your Mac is not compatible.\nThe application will close"); + // TODO: Find a way to force close the app + } } QString MainWindow::getMBPModelVersion() { - /* Execute Following Command Line and return result */ - //sysctl -n hw.model - //or - //ioreg -l | awk '/product-name/ { split($0, line, "\""); printf("%s\n", line[4]); }' - QString MBPModelVersion; + QProcess process; + + //Execute commande line + process.start("sysctl -n hw.model"); + + //Wait forever until finished + process.waitForFinished(-1); + + //Get command line output + MBPModelVersion = process.readAllStandardOutput(); + + //Remove carriage return ("\n") from string + MBPModelVersion = MBPModelVersion.simplified(); return MBPModelVersion; } @@ -83,15 +105,28 @@ bool MainWindow::isCompatibleVersion(QString modelVersion) { //Compare version with compatible versions of MBPs bool isCompatibleVersion; + QString MBPModelVersion; - return isCompatibleVersion; + MBPModelVersion = getMBPModelVersion(); + + //TODO : Search in a list + if(MBPModelVersion == "MacBookPro6,2") + { + std::cout<<"Succes"< #include #include +#include +#include +#include // Inclut la bibliothèque iostream (affichage de texte) + +using namespace std; // Indique quel espace de noms on va utiliser //GoogleC++ Style Guide : https://google.github.io/styleguide/cppguide.html @@ -28,6 +33,7 @@ private slots: void on_restoreButton_clicked(); + void exit(); private: Ui::MainWindow *ui;