main.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "mainwindow.h"
  2. #include "skin.h"
  3. #include <QApplication>
  4. #include <QFile>
  5. #include <QTextCodec>
  6. #include <QLockFile>
  7. #include <QtGlobal>
  8. #include <QtGlobal>
  9. #include <QMessageBox>
  10. #include <QThread>
  11. #include <QtConcurrent/QtConcurrentRun>
  12. #include <QDir>
  13. #include <QString>
  14. #include <QDate>
  15. #include <QtMessageHandler>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
  19. {
  20. QByteArray localMsg = msg.toUtf8();
  21. const char * format = "[" + QDate::currentDate().toString(Qt::ISODate).toUtf8() + " " + QTime::currentTime().toString(Qt::ISODate).toUtf8() + "]";
  22. switch (type) {
  23. case QtDebugMsg:
  24. fprintf(stderr, "%s DEB: %s\n", format, localMsg.constData());
  25. break;
  26. case QtInfoMsg:
  27. fprintf(stderr, "%s INF: %s\n", format, localMsg.constData());
  28. break;
  29. case QtWarningMsg:
  30. fprintf(stderr, "%s WAR: %s\n", format, localMsg.constData());
  31. break;
  32. case QtCriticalMsg:
  33. fprintf(stderr, "%s CRT: %s\n", format, localMsg.constData());
  34. break;
  35. case QtFatalMsg:
  36. fprintf(stderr, "%s FAT: %s\n", format, localMsg.constData());
  37. abort();
  38. }
  39. }
  40. int main(int argc, char *argv[]){
  41. //if (argc <= 1 || (argc > 1 && std::string(argv[1]) != std::string("-S") && std::string(argv[1]) != "-prelaunched"))
  42. // return 0;
  43. freopen("log.txt", "w", stdout);
  44. freopen("log.txt", "a", stderr);
  45. // if it's later than 25.02.2018 - return. That's for temporary version
  46. //long long cur_time = time(0);
  47. //if (cur_time >= 1520629200)
  48. // return 0;
  49. setbuf(stdout, NULL);
  50. setbuf(stderr, NULL);
  51. setvbuf (stdout, NULL, _IONBF, BUFSIZ);
  52. setvbuf (stderr, NULL, _IONBF, BUFSIZ);/**/
  53. qInstallMessageHandler(myMessageOutput);// вывод логов в файл
  54. QApplication a(argc, argv);
  55. QLockFile lockFile(QDir::temp().absoluteFilePath("rulotro.lock"));
  56. if(!lockFile.tryLock(100)){
  57. QMessageBox msgBox;
  58. msgBox.setIcon(QMessageBox::Warning);
  59. msgBox.setText("Приложение уже запущено.\nРазрешено запускать только один экземпляр приложения.");
  60. msgBox.exec();
  61. return 1;
  62. }
  63. MainWindow::getInstance()->show();
  64. MainWindow::getInstance()->setupWindow();
  65. QFile styleF;
  66. QString skin = Skin::getInstance()->getSkinName();
  67. styleF.setFileName(QApplication::applicationDirPath() + "/styles/" + skin + "/style.css");
  68. styleF.open(QFile::ReadOnly);
  69. QString qssStr = styleF.readAll();
  70. qApp->setStyleSheet(qssStr);
  71. MainWindow::getInstance()->show();
  72. auto result = a.exec();
  73. lockFile.unlock();
  74. return result;
  75. }