PageRenderTime 51ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/updater.cpp

https://gitlab.com/gustawho/aircrackgui-m4
C++ | 123 lines | 82 code | 27 blank | 14 comment | 14 complexity | fdf6043fa82f8968d92ea52efc32e5f9 MD5 | raw file
  1. #include "updater.h"
  2. #include "ui_updater.h"
  3. updater::updater(QWidget *parent) :
  4. QWidget(parent),
  5. ui(new Ui::updater)
  6. {
  7. logThread::addLog("Constructor of updater attack GUI", logInfo::MAIN);
  8. ui->setupUi(this);
  9. //connect button check updates
  10. connect(this->ui->pushButtonCheckUpdates, SIGNAL(clicked()), this, SLOT(checkUpdates()));
  11. //connect to download
  12. connect(this->ui->pushButtonDownload, SIGNAL(clicked()), this, SLOT(downloadUpdate()));
  13. //connect to show the window when update is available
  14. connect(this, SIGNAL(updateAvailable()), this, SLOT(show()));
  15. }
  16. updater::~updater()
  17. {
  18. logThread::addLog("Destructor of updater attack GUI", logInfo::MAIN);
  19. delete ui;
  20. }
  21. void updater::downloadUpdate()
  22. {
  23. QDesktopServices::openUrl(QUrl("http://code.google.com/p/aircrackgui-m4/downloads/list"));
  24. }
  25. void updater::checkUpdates(){
  26. logThread::addLog("Updater: checking for updates", logInfo::MAIN);
  27. QFile::remove("index.html");
  28. this->ui->textEditLog->clear();
  29. //move cursor to end
  30. this->ui->textEditLog->moveCursor(QTextCursor::End);
  31. //getting current version
  32. this->ui->lineEditCurrentVersion->setText(VERSION);
  33. //getting latest version
  34. QProcess p;
  35. p.start("wget http://code.google.com/p/aircrackgui-m4/");
  36. if (!p.waitForFinished(5000)) {
  37. this->ui->textEditLog->append(utils::htmlRojo("Imposible to execute correctly wget to update"));
  38. return;
  39. }
  40. QFile f("index.html");
  41. if (!f.open(QIODevice::ReadOnly)) {
  42. this->ui->textEditLog->append(utils::htmlRojo("Imposible to open information obtained to update"));
  43. return;
  44. }
  45. QString pageText = f.readAll();
  46. f.close();
  47. int preIndex = pageText.indexOf("[{-]");
  48. if (preIndex == -1) {
  49. this->ui->textEditLog->append(utils::htmlRojo("Imposible to open information obtained to update"));
  50. return;
  51. }
  52. pageText.remove(preIndex, 4);
  53. int postIndex = pageText.indexOf("[-}]");
  54. if (postIndex == -1) {
  55. this->ui->textEditLog->append(utils::htmlRojo("Imposible to open information obtained to update"));
  56. return;
  57. }
  58. //set latest version
  59. this->ui->lineEditLatestVersion->setText(pageText.mid(preIndex, postIndex-preIndex).replace('_', ' '));
  60. //getting changelog
  61. preIndex = pageText.indexOf("[*CHANGELOG*]");
  62. if (preIndex == -1) {
  63. this->ui->textEditLog->append(utils::htmlRojo("Imposible to open information obtained to update"));
  64. return;
  65. }
  66. pageText.remove(preIndex, 13);
  67. postIndex = pageText.indexOf("[/*CHANGELOG*]");
  68. if (postIndex == -1) {
  69. this->ui->textEditLog->append(utils::htmlRojo("Imposible to open information obtained to update"));
  70. return;
  71. }
  72. const QString changelog = pageText.mid(preIndex, postIndex-preIndex);
  73. //UPDATED?
  74. //yes
  75. if (this->ui->lineEditCurrentVersion->text().remove(' ')
  76. == this->ui->lineEditLatestVersion->text().remove(' ')) {
  77. if (this->isVisible())
  78. this->ui->textEditLog->append(utils::htmlVerde("Program is Up-To-Date"));
  79. }
  80. //no
  81. else {
  82. emit updateAvailable();
  83. this->ui->textEditLog->append(utils::htmlVerde("*****************************"));
  84. this->ui->textEditLog->append(utils::htmlVerde("UPDATE AVAILABLE"));
  85. this->ui->textEditLog->append(utils::htmlVerde("*****************************"));
  86. //enabling download button
  87. this->ui->pushButtonDownload->setEnabled(true);
  88. }
  89. //anyway showing changelog
  90. this->ui->textEditLog->append(utils::htmlVerde("\n-----------------------------"));
  91. this->ui->textEditLog->append(utils::htmlVerde("Changelog"));
  92. this->ui->textEditLog->append(utils::htmlVerde("-----------------------------"));
  93. this->ui->textEditLog->append(changelog);
  94. //move cursor to start
  95. this->ui->textEditLog->moveCursor(QTextCursor::Start);
  96. }