main.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "app.h"
  2. #include <QApplication>
  3. #include <QFile>
  4. #include <QTextCodec>
  5. #include <QLockFile>
  6. #include <QtGlobal>
  7. #include <QtGlobal>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <QThread>
  11. #include <QtConcurrent/QtConcurrentRun>
  12. void myMessageOutput(QtMsgType type, const QMessageLogContext &, const QString &msg)
  13. {
  14. QByteArray localMsg = msg.toUtf8();
  15. const char * format = "[" + QDate::currentDate().toString(Qt::ISODate).toUtf8() + " " + QTime::currentTime().toString(Qt::ISODate).toUtf8() + "]";
  16. switch (type) {
  17. case QtDebugMsg:
  18. fprintf(stderr, "%s DEB: %s\n", format, localMsg.constData());
  19. break;
  20. case QtInfoMsg:
  21. fprintf(stderr, "%s INF: %s\n", format, localMsg.constData());
  22. break;
  23. case QtWarningMsg:
  24. fprintf(stderr, "%s WAR: %s\n", format, localMsg.constData());
  25. break;
  26. case QtCriticalMsg:
  27. fprintf(stderr, "%s CRT: %s\n", format, localMsg.constData());
  28. break;
  29. case QtFatalMsg:
  30. fprintf(stderr, "%s FAT: %s\n", format, localMsg.constData());
  31. abort();
  32. }
  33. }
  34. int main(int argc, char *argv[]){
  35. //if (argc <= 1 || (argc > 1 && std::string(argv[1]) != std::string("-S") && std::string(argv[1]) != "-prelaunched"))
  36. // return 0;
  37. // if (app->config->getValue("General", "dpiscale") == "-1") {
  38. // QApplication a(argc, argv);
  39. // qDebug() << "No value. Detected " << ((QGuiApplication*)QCoreApplication::instance())->primaryScreen()->physicalDotsPerInch();
  40. // app->config->setValue("General", "dpiscale", QString::number(((QGuiApplication*)QCoreApplication::instance())->primaryScreen()->physicalDotsPerInch()));
  41. // a.exit(0);
  42. // return 0;
  43. // } else {
  44. // qDebug() << app->config->getValue("general", "dpiscale").toLatin1();
  45. // qputenv("QT_SCALE_FACTOR", app->config->getValue("general", "dpiscale").toLatin1());
  46. // }
  47. freopen("log.txt", "w", stdout);
  48. freopen("log.txt", "a", stderr);
  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 w;
  64. App *app = &App::getInstance();
  65. app->logSectionStart("Начинаем работать");
  66. QFile styleF;
  67. QString skin = app->helper->getSkinName();
  68. styleF.setFileName(app->app_folder + "styles/" + skin + "/style.css");
  69. styleF.open(QFile::ReadOnly);
  70. QString qssStr = styleF.readAll();
  71. qApp->setStyleSheet(qssStr);
  72. w.show();
  73. //QFuture<void> future = QtConcurrent::run(w, &MainWindow::doStartPreparations);
  74. auto result = a.exec();
  75. lockFile.unlock();
  76. return result;
  77. }