main.cpp 2.9 KB

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